*
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 867a1f176..bac4031f0 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -44,7 +44,6 @@ import com.jogamp.newt.util.EDTUtil;
import java.util.ArrayList;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.NativeWindowFactory;
public abstract class DisplayImpl extends Display {
private static int serialno = 1;
@@ -52,26 +51,9 @@ public abstract class DisplayImpl extends Display {
private static Class> getDisplayClass(String type)
throws ClassNotFoundException
{
- Class> displayClass = NewtFactory.getCustomClass(type, "Display");
+ final Class> displayClass = NewtFactory.getCustomClass(type, "DisplayDriver");
if(null==displayClass) {
- if (NativeWindowFactory.TYPE_ANDROID == type) {
- displayClass = Class.forName("jogamp.newt.driver.android.AndroidDisplay");
- } else if (NativeWindowFactory.TYPE_EGL == type) {
- displayClass = Class.forName("jogamp.newt.driver.kd.Display");
- } else if (NativeWindowFactory.TYPE_WINDOWS == type) {
- displayClass = Class.forName("jogamp.newt.driver.windows.WindowsDisplay");
- } else if (NativeWindowFactory.TYPE_MACOSX == type) {
- displayClass = Class.forName("jogamp.newt.driver.macosx.MacDisplay");
- } else if (NativeWindowFactory.TYPE_X11 == type) {
- displayClass = Class.forName("jogamp.newt.driver.x11.X11Display");
- } else if (NativeWindowFactory.TYPE_AWT == type) {
- displayClass = Class.forName("jogamp.newt.driver.awt.AWTDisplay");
- } else {
- throw new RuntimeException("Unknown display type \"" + type + "\"");
- }
- }
- if(null==displayClass) {
- throw new ClassNotFoundException("Failed to find NEWT Display Class <"+type+".Display>");
+ throw new ClassNotFoundException("Failed to find NEWT Display Class <"+type+".DisplayDriver>");
}
return displayClass;
}
diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java
index 9f75a0d25..e2c0f746f 100644
--- a/src/newt/classes/jogamp/newt/ScreenImpl.java
+++ b/src/newt/classes/jogamp/newt/ScreenImpl.java
@@ -90,31 +90,13 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
});
}
- @SuppressWarnings("unchecked")
- private static Class extends Screen> getScreenClass(String type) throws ClassNotFoundException
+ private static Class> getScreenClass(String type) throws ClassNotFoundException
{
- Class> screenClass = NewtFactory.getCustomClass(type, "Screen");
+ final Class> screenClass = NewtFactory.getCustomClass(type, "ScreenDriver");
if(null==screenClass) {
- if (NativeWindowFactory.TYPE_ANDROID == type) {
- screenClass = Class.forName("jogamp.newt.driver.android.AndroidScreen");
- } else if (NativeWindowFactory.TYPE_EGL == type) {
- screenClass = Class.forName("jogamp.newt.driver.kd.Screen");
- } else if (NativeWindowFactory.TYPE_WINDOWS == type) {
- screenClass = Class.forName("jogamp.newt.driver.windows.WindowsScreen");
- } else if (NativeWindowFactory.TYPE_MACOSX == type) {
- screenClass = Class.forName("jogamp.newt.driver.macosx.MacScreen");
- } else if (NativeWindowFactory.TYPE_X11 == type) {
- screenClass = Class.forName("jogamp.newt.driver.x11.X11Screen");
- } else if (NativeWindowFactory.TYPE_AWT == type) {
- screenClass = Class.forName("jogamp.newt.driver.awt.AWTScreen");
- } else {
- throw new RuntimeException("Unknown window type \"" + type + "\"");
- }
- }
- if(null==screenClass) {
- throw new ClassNotFoundException("Failed to find NEWT Screen Class <"+type+".Screen>");
+ throw new ClassNotFoundException("Failed to find NEWT Screen Class <"+type+".ScreenDriver>");
}
- return (Class extends Screen>)screenClass;
+ return screenClass;
}
public static Screen create(Display display, int idx) {
@@ -133,7 +115,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
}
}
synchronized(screenList) {
- Class extends Screen> screenClass = getScreenClass(display.getType());
+ Class> screenClass = getScreenClass(display.getType());
ScreenImpl screen = (ScreenImpl) screenClass.newInstance();
screen.display = (DisplayImpl) display;
idx = screen.validateScreenIndex(idx);
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 2971fa07e..ad7195944 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -152,26 +152,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
private static Class> getWindowClass(String type)
throws ClassNotFoundException
{
- Class> windowClass = NewtFactory.getCustomClass(type, "Window");
+ final Class> windowClass = NewtFactory.getCustomClass(type, "WindowDriver");
if(null==windowClass) {
- if (NativeWindowFactory.TYPE_ANDROID == type) {
- windowClass = Class.forName("jogamp.newt.driver.android.AndroidWindow");
- } else if (NativeWindowFactory.TYPE_EGL == type) {
- windowClass = Class.forName("jogamp.newt.driver.kd.Window");
- } else if (NativeWindowFactory.TYPE_WINDOWS == type) {
- windowClass = Class.forName("jogamp.newt.driver.windows.WindowsWindow");
- } else if (NativeWindowFactory.TYPE_MACOSX == type) {
- windowClass = Class.forName("jogamp.newt.driver.macosx.MacWindow");
- } else if (NativeWindowFactory.TYPE_X11 == type) {
- windowClass = Class.forName("jogamp.newt.driver.x11.X11Window");
- } else if (NativeWindowFactory.TYPE_AWT == type) {
- windowClass = Class.forName("jogamp.newt.driver.awt.AWTWindow");
- } else {
- throw new NativeWindowException("Unknown window type \"" + type + "\"");
- }
- }
- if(null==windowClass) {
- throw new ClassNotFoundException("Failed to find NEWT Window Class <"+type+".Window>");
+ throw new ClassNotFoundException("Failed to find NEWT Window Class <"+type+".WindowDriver>");
}
return windowClass;
}
diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidDisplay.java b/src/newt/classes/jogamp/newt/driver/android/AndroidDisplay.java
deleted file mode 100644
index 0a43c9b8f..000000000
--- a/src/newt/classes/jogamp/newt/driver/android/AndroidDisplay.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright 2011 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 jogamp.newt.driver.android;
-
-import jogamp.newt.*;
-import jogamp.opengl.egl.*;
-
-import javax.media.nativewindow.*;
-
-public class AndroidDisplay extends jogamp.newt.DisplayImpl {
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if (!AndroidWindow.initIDs0()) {
- throw new NativeWindowException("Failed to initialize Android NEWT Windowing library");
- }
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
-
- public AndroidDisplay() {
- }
-
- protected void createNativeImpl() {
- // EGL Device
- aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
- }
-
- protected void closeNativeImpl() {
- aDevice.close();
- }
-
- protected void dispatchMessagesNative() {
- // n/a .. DispatchMessages();
- }
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java b/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java
deleted file mode 100644
index e108ed0bb..000000000
--- a/src/newt/classes/jogamp/newt/driver/android/AndroidScreen.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * Copyright 2011 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 jogamp.newt.driver.android;
-
-import javax.media.nativewindow.*;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-import com.jogamp.newt.ScreenMode;
-import com.jogamp.newt.util.ScreenModeUtil;
-
-import android.content.Context;
-import android.graphics.PixelFormat;
-import android.util.DisplayMetrics;
-import android.view.Surface;
-import android.view.WindowManager;
-
-public class AndroidScreen extends jogamp.newt.ScreenImpl {
-
- static {
- AndroidDisplay.initSingleton();
- }
-
- public AndroidScreen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- }
-
- protected void closeNativeImpl() { }
-
- protected ScreenMode getCurrentScreenModeImpl() {
- final Context ctx = jogamp.common.os.android.StaticContext.getContext();
- final WindowManager wmgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
- final DisplayMetrics outMetrics = new DisplayMetrics();
- final android.view.Display aDisplay = wmgr.getDefaultDisplay();
- aDisplay.getMetrics(outMetrics);
-
- final int arot = aDisplay.getRotation();
- final int nrot = androidRotation2NewtRotation(arot);
- int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL];
- int offset = 1; // set later for verification of iterator
- offset = getScreenSize(outMetrics, nrot, props, offset);
- offset = getBpp(aDisplay, props, offset);
- offset = getScreenSizeMM(outMetrics, props, offset);
- props[offset++] = (int) aDisplay.getRefreshRate();
- props[offset++] = nrot;
- props[offset - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = offset; // count
- return ScreenModeUtil.streamIn(props, 0);
- }
-
- protected int validateScreenIndex(int idx) {
- return 0; // FIXME: only one screen available ?
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- final ScreenMode sm = getCurrentScreenMode();
- virtualSize.setWidth(sm.getRotatedWidth());
- virtualSize.setHeight(sm.getRotatedHeight());
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
- static int androidRotation2NewtRotation(int arot) {
- switch(arot) {
- case Surface.ROTATION_270: return ScreenMode.ROTATE_270;
- case Surface.ROTATION_180: return ScreenMode.ROTATE_180;
- case Surface.ROTATION_90: return ScreenMode.ROTATE_90;
- case Surface.ROTATION_0:
- }
- return ScreenMode.ROTATE_0;
- }
- static int getScreenSize(DisplayMetrics outMetrics, int nrot, int[] props, int offset) {
- // swap width and height, since Android reflects rotated dimension, we don't
- if (ScreenMode.ROTATE_90 == nrot || ScreenMode.ROTATE_270 == nrot) {
- props[offset++] = outMetrics.heightPixels;
- props[offset++] = outMetrics.widthPixels;
- } else {
- props[offset++] = outMetrics.widthPixels;
- props[offset++] = outMetrics.heightPixels;
- }
- return offset;
- }
- static int getBpp(android.view.Display aDisplay, int[] props, int offset) {
- int bpp;
- switch(aDisplay.getPixelFormat()) {
- case PixelFormat.RGBA_8888: bpp=32; break;
- case PixelFormat.RGBX_8888: bpp=32; break;
- case PixelFormat.RGB_888: bpp=24; break;
- case PixelFormat.RGB_565: bpp=16; break;
- case PixelFormat.RGBA_5551: bpp=16; break;
- case PixelFormat.RGBA_4444: bpp=16; break;
- case PixelFormat.RGB_332: bpp= 8; break;
- default: bpp=32;
- }
- props[offset++] = bpp;
- return offset;
- }
- static int getScreenSizeMM(DisplayMetrics outMetrics, int[] props, int offset) {
- final float iw = (float) outMetrics.widthPixels / outMetrics.xdpi;
- final float ih = (float) outMetrics.heightPixels / outMetrics.xdpi;
- final float mmpi = 25.4f;
- props[offset++] = (int) ((iw * mmpi)+0.5);
- props[offset++] = (int) ((ih * mmpi)+0.5);
- return offset;
- }
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
deleted file mode 100644
index 73192a07f..000000000
--- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java
+++ /dev/null
@@ -1,458 +0,0 @@
-/**
- * Copyright 2011 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 jogamp.newt.driver.android;
-
-import jogamp.common.os.android.StaticContext;
-import jogamp.newt.driver.android.event.AndroidNewtEventFactory;
-
-import javax.media.nativewindow.Capabilities;
-import javax.media.nativewindow.CapabilitiesImmutable;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.VisualIDHolder;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.Point;
-import javax.media.opengl.GLCapabilitiesChooser;
-import javax.media.opengl.GLCapabilitiesImmutable;
-
-import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
-
-import jogamp.opengl.egl.EGL;
-import jogamp.opengl.egl.EGLGraphicsConfiguration;
-import jogamp.opengl.egl.EGLGraphicsConfigurationFactory;
-
-import android.content.Context;
-import android.graphics.PixelFormat;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.ResultReceiver;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceHolder.Callback2;
-import android.view.inputmethod.InputMethodManager;
-import android.view.SurfaceView;
-import android.view.View;
-
-public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 {
- static {
- AndroidDisplay.initSingleton();
- }
-
- public static CapabilitiesImmutable fixCaps(boolean matchFormatPrecise, int format, CapabilitiesImmutable rCaps) {
- PixelFormat pf = new PixelFormat();
- PixelFormat.getPixelFormatInfo(format, pf);
- final CapabilitiesImmutable res;
- int r, g, b, a;
-
- switch(format) {
- case PixelFormat.RGBA_8888: r=8; g=8; b=8; a=8; break;
- case PixelFormat.RGBX_8888: r=8; g=8; b=8; a=0; break;
- case PixelFormat.RGB_888: r=8; g=8; b=8; a=0; break;
- case PixelFormat.RGB_565: r=5; g=6; b=5; a=0; break;
- case PixelFormat.RGBA_5551: r=5; g=5; b=5; a=1; break;
- case PixelFormat.RGBA_4444: r=4; g=4; b=4; a=4; break;
- case PixelFormat.RGB_332: r=3; g=3; b=2; a=0; break;
- default: throw new InternalError("Unhandled pixelformat: "+format);
- }
- final boolean change = matchFormatPrecise ||
- rCaps.getRedBits() > r &&
- rCaps.getGreenBits() > g &&
- rCaps.getBlueBits() > b &&
- rCaps.getAlphaBits() > a ;
-
- if(change) {
- Capabilities nCaps = (Capabilities) rCaps.cloneMutable();
- nCaps.setRedBits(r);
- nCaps.setGreenBits(g);
- nCaps.setBlueBits(b);
- nCaps.setAlphaBits(a);
- res = nCaps;
- } else {
- res = rCaps;
- }
- Log.d(MD.TAG, "fixCaps: format: "+format);
- Log.d(MD.TAG, "fixCaps: requested: "+rCaps);
- Log.d(MD.TAG, "fixCaps: chosen: "+res);
-
- return res;
- }
-
- public static int getFormat(CapabilitiesImmutable rCaps) {
- int fmt = PixelFormat.UNKNOWN;
-
- if(!rCaps.isBackgroundOpaque()) {
- fmt = PixelFormat.TRANSLUCENT;
- } else if(rCaps.getRedBits()<=5 &&
- rCaps.getGreenBits()<=6 &&
- rCaps.getBlueBits()<=5 &&
- rCaps.getAlphaBits()==0) {
- fmt = PixelFormat.RGB_565;
- }
- /* else if(rCaps.getRedBits()<=5 &&
- rCaps.getGreenBits()<=5 &&
- rCaps.getBlueBits()<=5 &&
- rCaps.getAlphaBits()==1) {
- fmt = PixelFormat.RGBA_5551; // FIXME: Supported ?
- } */
- else {
- fmt = PixelFormat.RGBA_8888;
- }
- Log.d(MD.TAG, "getFormat: requested: "+rCaps);
- Log.d(MD.TAG, "getFormat: returned: "+fmt);
-
- return fmt;
- }
-
- public static boolean isAndroidFormatTransparent(int aFormat) {
- switch (aFormat) {
- case PixelFormat.TRANSLUCENT:
- case PixelFormat.TRANSPARENT:
- return true;
- }
- return false;
- }
-
- class AndroidEvents implements View.OnKeyListener, View.OnTouchListener, View.OnFocusChangeListener {
-
- @Override
- public boolean onTouch(View v, android.view.MotionEvent event) {
- final com.jogamp.newt.event.MouseEvent[] newtEvents = AndroidNewtEventFactory.createMouseEvents(event, AndroidWindow.this);
- if(null != newtEvents) {
- focusChanged(false, true);
- for(int i=0; i[] getCustomConstructorArgumentTypes() {
- return new Class>[] { Context.class } ;
- }
-
- public AndroidWindow() {
- reset();
- }
-
- private void reset() {
- ownAndroidWindow = false;
- androidView = null;
- nativeFormat = VisualIDHolder.VID_UNDEFINED;
- androidFormat = VisualIDHolder.VID_UNDEFINED;
- capsByFormat = null;
- surface = null;
- surfaceHandle = 0;
- eglSurface = 0;
- definePosition(0, 0); // default to 0/0
- setBrokenFocusChange(true);
- }
-
- @Override
- protected void instantiationFinished() {
- final Context ctx = StaticContext.getContext();
- if(null == ctx) {
- throw new NativeWindowException("No static [Application] Context has been set. Call StaticContext.setContext(Context) first.");
- }
- androidView = new MSurfaceView(ctx);
-
- final AndroidEvents ae = new AndroidEvents();
- androidView.setOnTouchListener(ae);
- androidView.setClickable(false);
- androidView.setOnKeyListener(ae);
- androidView.setOnFocusChangeListener(ae);
- androidView.setFocusable(true);
- androidView.setFocusableInTouchMode(true);
-
- final SurfaceHolder sh = androidView.getHolder();
- sh.addCallback(AndroidWindow.this);
- sh.setFormat(getFormat(getRequestedCapabilities()));
-
- // default size -> TBD !
- defineSize(0, 0);
- }
-
- public SurfaceView getAndroidView() { return androidView; }
-
- @Override
- protected boolean canCreateNativeImpl() {
- final boolean b = 0 != surfaceHandle;
- Log.d(MD.TAG, "canCreateNativeImpl: "+b);
- return b;
- }
-
- @Override
- protected void createNativeImpl() {
- Log.d(MD.TAG, "createNativeImpl 0 - surfaceHandle 0x"+Long.toHexString(surfaceHandle)+
- ", format [a "+androidFormat+", n "+nativeFormat+"], "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight()+" - "+Thread.currentThread().getName());
-
- if(0!=getParentWindowHandle()) {
- throw new NativeWindowException("Window parenting not supported (yet)");
- }
- if(0==surfaceHandle) {
- throw new InternalError("XXX");
- }
-
- final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) getScreen().getDisplay().getGraphicsDevice();
- final EGLGraphicsConfiguration eglConfig = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
- capsByFormat, (GLCapabilitiesImmutable) getRequestedCapabilities(),
- (GLCapabilitiesChooser)capabilitiesChooser, getScreen().getGraphicsScreen(), nativeFormat,
- isAndroidFormatTransparent(androidFormat));
- if (eglConfig == null) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- final int nativeVisualID = eglConfig.getVisualID(VisualIDHolder.VIDType.NATIVE);
- Log.d(MD.TAG, "nativeVisualID 0x"+Integer.toHexString(nativeVisualID));
- if(VisualIDHolder.VID_UNDEFINED != nativeVisualID) {
- setSurfaceVisualID0(surfaceHandle, nativeVisualID);
- }
-
- eglSurface = EGL.eglCreateWindowSurface(eglDevice.getHandle(), eglConfig.getNativeConfig(), surfaceHandle, null);
- if (EGL.EGL_NO_SURFACE==eglSurface) {
- throw new NativeWindowException("Creation of window surface failed: "+eglConfig+", surfaceHandle 0x"+Long.toHexString(surfaceHandle)+", error "+toHexString(EGL.eglGetError()));
- }
-
- // propagate data ..
- setGraphicsConfiguration(eglConfig);
- setWindowHandle(surfaceHandle);
- focusChanged(false, true);
- Log.d(MD.TAG, "createNativeImpl X");
- }
-
- @Override
- protected void closeNativeImpl() {
- release0(surfaceHandle);
- surface = null;
- surfaceHandle = 0;
- eglSurface = 0;
- }
-
- @Override
- public final long getSurfaceHandle() {
- return eglSurface;
- }
-
- protected void requestFocusImpl(boolean reparented) {
- if(null != androidView) {
- Log.d(MD.TAG, "requestFocusImpl: reparented "+reparented);
- androidView.post(new Runnable() {
- public void run() {
- androidView.requestFocus();
- androidView.bringToFront();
- }
- });
- }
- }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- if( 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) {
- Log.d(MD.TAG, "reconfigureWindowImpl.setFullscreen post creation (setContentView()) n/a");
- return false;
- }
- if(width>0 || height>0) {
- if(0!=getWindowHandle()) {
- Log.d(MD.TAG, "reconfigureWindowImpl.setSize n/a");
- return false;
- }
- }
- if(x>=0 || y>=0) {
- Log.d(MD.TAG, "reconfigureWindowImpl.setPos n/a");
- return false;
- }
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
- return true;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- return new Point(x,y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop ..
- }
-
- //----------------------------------------------------------------------
- // Virtual On-Screen Keyboard / SoftInput
- //
-
- private class KeyboardVisibleReceiver extends ResultReceiver {
- public KeyboardVisibleReceiver() {
- super(null);
- }
-
- @Override
- public void onReceiveResult(int r, Bundle data) {
- boolean v = false;
-
- switch(r) {
- case InputMethodManager.RESULT_UNCHANGED_SHOWN:
- case InputMethodManager.RESULT_SHOWN:
- v = true;
- break;
- case InputMethodManager.RESULT_HIDDEN:
- case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
- v = false;
- break;
- }
- Log.d(MD.TAG, "keyboardVisible: "+v);
- keyboardVisibilityChanged(v);
- }
- }
- private KeyboardVisibleReceiver keyboardVisibleReceiver = new KeyboardVisibleReceiver();
-
- protected final boolean setKeyboardVisibleImpl(boolean visible) {
- if(null != androidView) {
- final InputMethodManager imm = (InputMethodManager) getAndroidView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- final IBinder winid = getAndroidView().getWindowToken();
- if(visible) {
- // Show soft-keyboard:
- imm.showSoftInput(androidView, 0, keyboardVisibleReceiver);
- } else {
- // hide keyboard :
- imm.hideSoftInputFromWindow(winid, 0, keyboardVisibleReceiver);
- }
- return visible;
- } else {
- return false; // nop
- }
- }
-
- //----------------------------------------------------------------------
- // Surface Callbacks
- //
-
- public void surfaceCreated(SurfaceHolder holder) {
- Log.d(MD.TAG, "surfaceCreated: "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight());
- }
-
- public void surfaceChanged(SurfaceHolder aHolder, int aFormat, int aWidth, int aHeight) {
- Log.d(MD.TAG, "surfaceChanged: f "+nativeFormat+" -> "+aFormat+", "+aWidth+"x"+aHeight+", current surfaceHandle: 0x"+Long.toHexString(surfaceHandle));
- if(0!=surfaceHandle && androidFormat != aFormat ) {
- // re-create
- Log.d(MD.TAG, "surfaceChanged (destroy old)");
- if(!windowDestroyNotify(true)) {
- destroy();
- }
- surfaceHandle = 0;
- surface=null;
- }
- if(getScreen().isNativeValid()) {
- getScreen().getCurrentScreenMode(); // if ScreenMode changed .. trigger ScreenMode event
- }
-
- if(0>getX() || 0>getY()) {
- positionChanged(false, 0, 0);
- }
-
- if(0 == surfaceHandle) {
- androidFormat = aFormat;
- surface = aHolder.getSurface();
- surfaceHandle = getSurfaceHandle0(surface);
- acquire0(surfaceHandle);
- nativeFormat = getSurfaceVisualID0(surfaceHandle);
- final int nWidth = getWidth0(surfaceHandle);
- final int nHeight = getHeight0(surfaceHandle);
- capsByFormat = (GLCapabilitiesImmutable) fixCaps(true /* matchFormatPrecise */, nativeFormat, getRequestedCapabilities());
- sizeChanged(false, nWidth, nHeight, false);
-
- Log.d(MD.TAG, "surfaceRealized: isValid: "+surface.isValid()+
- ", new surfaceHandle 0x"+Long.toHexString(surfaceHandle)+
- ", format [a "+androidFormat+"/n "+nativeFormat+"], "+
- getX()+"/"+getY()+" "+nWidth+"x"+nHeight+", visible: "+isVisible());
-
- if(isVisible()) {
- setVisible(true);
- }
- }
- sizeChanged(false, aWidth, aHeight, false);
- windowRepaint(0, 0, aWidth, aHeight);
- Log.d(MD.TAG, "surfaceChanged: X");
- }
-
- public void surfaceDestroyed(SurfaceHolder holder) {
- Log.d(MD.TAG, "surfaceDestroyed");
- windowDestroyNotify(true); // actually too late .. however ..
- }
-
- public void surfaceRedrawNeeded(SurfaceHolder holder) {
- Log.d(MD.TAG, "surfaceRedrawNeeded");
- windowRepaint(0, 0, getWidth(), getHeight());
- }
-
- private boolean ownAndroidWindow;
- private MSurfaceView androidView;
- private int nativeFormat; // chosen current native PixelFormat (suitable for EGL)
- private int androidFormat; // chosen current android PixelFormat (-1, -2 ..)
- private GLCapabilitiesImmutable capsByFormat; // fixed requestedCaps by PixelFormat
- private Surface surface;
- private volatile long surfaceHandle;
- private long eglSurface;
-
- class MSurfaceView extends SurfaceView {
- public MSurfaceView (Context ctx) {
- super(ctx);
- setBackgroundDrawable(null);
- // setBackgroundColor(Color.TRANSPARENT);
- }
- }
- //----------------------------------------------------------------------
- // Internals only
- //
- protected static native boolean initIDs0();
- protected static native long getSurfaceHandle0(Surface surface);
- protected static native int getSurfaceVisualID0(long surfaceHandle);
- protected static native void setSurfaceVisualID0(long surfaceHandle, int nativeVisualID);
- protected static native int getWidth0(long surfaceHandle);
- protected static native int getHeight0(long surfaceHandle);
- protected static native void acquire0(long surfaceHandle);
- protected static native void release0(long surfaceHandle);
-}
diff --git a/src/newt/classes/jogamp/newt/driver/android/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/android/DisplayDriver.java
new file mode 100644
index 000000000..a367462c4
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/android/DisplayDriver.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2011 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 jogamp.newt.driver.android;
+
+import jogamp.newt.*;
+import jogamp.opengl.egl.*;
+
+import javax.media.nativewindow.*;
+
+public class DisplayDriver extends jogamp.newt.DisplayImpl {
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if (!WindowDriver.initIDs0()) {
+ throw new NativeWindowException("Failed to initialize Android NEWT Windowing library");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ // EGL Device
+ aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+
+ protected void closeNativeImpl() {
+ aDevice.close();
+ }
+
+ protected void dispatchMessagesNative() {
+ // n/a .. DispatchMessages();
+ }
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java b/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java
index 4537fa963..91c589beb 100644
--- a/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java
+++ b/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java
@@ -36,7 +36,7 @@ import javax.media.opengl.FPSCounter;
import com.jogamp.newt.Window;
import com.jogamp.opengl.util.Animator;
-import jogamp.newt.driver.android.AndroidWindow;
+import jogamp.newt.driver.android.WindowDriver;
import android.app.Activity;
import android.content.Context;
@@ -83,10 +83,10 @@ public class NewtBaseActivity extends Activity {
*/
public void setContentView(android.view.Window androidWindow, Window newtWindow) {
newtWindow = newtWindow.getDelegatedWindow();
- if(newtWindow instanceof AndroidWindow) {
+ if(newtWindow instanceof WindowDriver) {
adaptTheme4Transparency(newtWindow.getRequestedCapabilities());
layoutForNEWTWindow(androidWindow, newtWindow);
- AndroidWindow newtAWindow = (AndroidWindow)newtWindow;
+ WindowDriver newtAWindow = (WindowDriver)newtWindow;
androidWindow.setContentView(newtAWindow.getAndroidView());
registerNEWTWindow(newtAWindow);
} else {
@@ -107,8 +107,8 @@ public class NewtBaseActivity extends Activity {
*/
public void addContentView(android.view.Window androidWindow, Window newtWindow, android.view.ViewGroup.LayoutParams params) {
newtWindow = newtWindow.getDelegatedWindow();
- if(newtWindow instanceof AndroidWindow) {
- AndroidWindow newtAWindow = (AndroidWindow)newtWindow;
+ if(newtWindow instanceof WindowDriver) {
+ WindowDriver newtAWindow = (WindowDriver)newtWindow;
androidWindow.addContentView(newtAWindow.getAndroidView(), params);
registerNEWTWindow(newtAWindow);
} else {
diff --git a/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java b/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java
index 36b83337a..a49f1648c 100644
--- a/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java
+++ b/src/newt/classes/jogamp/newt/driver/android/NewtVersionActivity.java
@@ -69,7 +69,7 @@ public class NewtVersionActivity extends NewtBaseActivity {
glWindow.setUndecorated(true);
glWindow.setSize(32, 32);
glWindow.setPosition(0, 0);
- final android.view.View androidGLView = ((AndroidWindow)glWindow.getDelegatedWindow()).getAndroidView();
+ final android.view.View androidGLView = ((WindowDriver)glWindow.getDelegatedWindow()).getAndroidView();
viewGroup.addView(androidGLView, new android.widget.FrameLayout.LayoutParams(glWindow.getWidth(), glWindow.getHeight(), Gravity.BOTTOM|Gravity.RIGHT));
registerNEWTWindow(glWindow);
diff --git a/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java
new file mode 100644
index 000000000..795aac5fb
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/android/ScreenDriver.java
@@ -0,0 +1,138 @@
+/**
+ * Copyright 2011 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 jogamp.newt.driver.android;
+
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.util.ScreenModeUtil;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.util.DisplayMetrics;
+import android.view.Surface;
+import android.view.WindowManager;
+
+public class ScreenDriver extends jogamp.newt.ScreenImpl {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() { }
+
+ protected ScreenMode getCurrentScreenModeImpl() {
+ final Context ctx = jogamp.common.os.android.StaticContext.getContext();
+ final WindowManager wmgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
+ final DisplayMetrics outMetrics = new DisplayMetrics();
+ final android.view.Display aDisplay = wmgr.getDefaultDisplay();
+ aDisplay.getMetrics(outMetrics);
+
+ final int arot = aDisplay.getRotation();
+ final int nrot = androidRotation2NewtRotation(arot);
+ int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL];
+ int offset = 1; // set later for verification of iterator
+ offset = getScreenSize(outMetrics, nrot, props, offset);
+ offset = getBpp(aDisplay, props, offset);
+ offset = getScreenSizeMM(outMetrics, props, offset);
+ props[offset++] = (int) aDisplay.getRefreshRate();
+ props[offset++] = nrot;
+ props[offset - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = offset; // count
+ return ScreenModeUtil.streamIn(props, 0);
+ }
+
+ protected int validateScreenIndex(int idx) {
+ return 0; // FIXME: only one screen available ?
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ final ScreenMode sm = getCurrentScreenMode();
+ virtualSize.setWidth(sm.getRotatedWidth());
+ virtualSize.setHeight(sm.getRotatedHeight());
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ static int androidRotation2NewtRotation(int arot) {
+ switch(arot) {
+ case Surface.ROTATION_270: return ScreenMode.ROTATE_270;
+ case Surface.ROTATION_180: return ScreenMode.ROTATE_180;
+ case Surface.ROTATION_90: return ScreenMode.ROTATE_90;
+ case Surface.ROTATION_0:
+ }
+ return ScreenMode.ROTATE_0;
+ }
+ static int getScreenSize(DisplayMetrics outMetrics, int nrot, int[] props, int offset) {
+ // swap width and height, since Android reflects rotated dimension, we don't
+ if (ScreenMode.ROTATE_90 == nrot || ScreenMode.ROTATE_270 == nrot) {
+ props[offset++] = outMetrics.heightPixels;
+ props[offset++] = outMetrics.widthPixels;
+ } else {
+ props[offset++] = outMetrics.widthPixels;
+ props[offset++] = outMetrics.heightPixels;
+ }
+ return offset;
+ }
+ static int getBpp(android.view.Display aDisplay, int[] props, int offset) {
+ int bpp;
+ switch(aDisplay.getPixelFormat()) {
+ case PixelFormat.RGBA_8888: bpp=32; break;
+ case PixelFormat.RGBX_8888: bpp=32; break;
+ case PixelFormat.RGB_888: bpp=24; break;
+ case PixelFormat.RGB_565: bpp=16; break;
+ case PixelFormat.RGBA_5551: bpp=16; break;
+ case PixelFormat.RGBA_4444: bpp=16; break;
+ case PixelFormat.RGB_332: bpp= 8; break;
+ default: bpp=32;
+ }
+ props[offset++] = bpp;
+ return offset;
+ }
+ static int getScreenSizeMM(DisplayMetrics outMetrics, int[] props, int offset) {
+ final float iw = (float) outMetrics.widthPixels / outMetrics.xdpi;
+ final float ih = (float) outMetrics.heightPixels / outMetrics.xdpi;
+ final float mmpi = 25.4f;
+ props[offset++] = (int) ((iw * mmpi)+0.5);
+ props[offset++] = (int) ((ih * mmpi)+0.5);
+ return offset;
+ }
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
new file mode 100644
index 000000000..8ad11b35f
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java
@@ -0,0 +1,458 @@
+/**
+ * Copyright 2011 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 jogamp.newt.driver.android;
+
+import jogamp.common.os.android.StaticContext;
+import jogamp.newt.driver.android.event.AndroidNewtEventFactory;
+
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.CapabilitiesImmutable;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.VisualIDHolder;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
+import javax.media.opengl.GLCapabilitiesChooser;
+import javax.media.opengl.GLCapabilitiesImmutable;
+
+import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
+
+import jogamp.opengl.egl.EGL;
+import jogamp.opengl.egl.EGLGraphicsConfiguration;
+import jogamp.opengl.egl.EGLGraphicsConfigurationFactory;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.ResultReceiver;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+import android.view.SurfaceHolder.Callback2;
+import android.view.inputmethod.InputMethodManager;
+import android.view.SurfaceView;
+import android.view.View;
+
+public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 {
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public static CapabilitiesImmutable fixCaps(boolean matchFormatPrecise, int format, CapabilitiesImmutable rCaps) {
+ PixelFormat pf = new PixelFormat();
+ PixelFormat.getPixelFormatInfo(format, pf);
+ final CapabilitiesImmutable res;
+ int r, g, b, a;
+
+ switch(format) {
+ case PixelFormat.RGBA_8888: r=8; g=8; b=8; a=8; break;
+ case PixelFormat.RGBX_8888: r=8; g=8; b=8; a=0; break;
+ case PixelFormat.RGB_888: r=8; g=8; b=8; a=0; break;
+ case PixelFormat.RGB_565: r=5; g=6; b=5; a=0; break;
+ case PixelFormat.RGBA_5551: r=5; g=5; b=5; a=1; break;
+ case PixelFormat.RGBA_4444: r=4; g=4; b=4; a=4; break;
+ case PixelFormat.RGB_332: r=3; g=3; b=2; a=0; break;
+ default: throw new InternalError("Unhandled pixelformat: "+format);
+ }
+ final boolean change = matchFormatPrecise ||
+ rCaps.getRedBits() > r &&
+ rCaps.getGreenBits() > g &&
+ rCaps.getBlueBits() > b &&
+ rCaps.getAlphaBits() > a ;
+
+ if(change) {
+ Capabilities nCaps = (Capabilities) rCaps.cloneMutable();
+ nCaps.setRedBits(r);
+ nCaps.setGreenBits(g);
+ nCaps.setBlueBits(b);
+ nCaps.setAlphaBits(a);
+ res = nCaps;
+ } else {
+ res = rCaps;
+ }
+ Log.d(MD.TAG, "fixCaps: format: "+format);
+ Log.d(MD.TAG, "fixCaps: requested: "+rCaps);
+ Log.d(MD.TAG, "fixCaps: chosen: "+res);
+
+ return res;
+ }
+
+ public static int getFormat(CapabilitiesImmutable rCaps) {
+ int fmt = PixelFormat.UNKNOWN;
+
+ if(!rCaps.isBackgroundOpaque()) {
+ fmt = PixelFormat.TRANSLUCENT;
+ } else if(rCaps.getRedBits()<=5 &&
+ rCaps.getGreenBits()<=6 &&
+ rCaps.getBlueBits()<=5 &&
+ rCaps.getAlphaBits()==0) {
+ fmt = PixelFormat.RGB_565;
+ }
+ /* else if(rCaps.getRedBits()<=5 &&
+ rCaps.getGreenBits()<=5 &&
+ rCaps.getBlueBits()<=5 &&
+ rCaps.getAlphaBits()==1) {
+ fmt = PixelFormat.RGBA_5551; // FIXME: Supported ?
+ } */
+ else {
+ fmt = PixelFormat.RGBA_8888;
+ }
+ Log.d(MD.TAG, "getFormat: requested: "+rCaps);
+ Log.d(MD.TAG, "getFormat: returned: "+fmt);
+
+ return fmt;
+ }
+
+ public static boolean isAndroidFormatTransparent(int aFormat) {
+ switch (aFormat) {
+ case PixelFormat.TRANSLUCENT:
+ case PixelFormat.TRANSPARENT:
+ return true;
+ }
+ return false;
+ }
+
+ class AndroidEvents implements View.OnKeyListener, View.OnTouchListener, View.OnFocusChangeListener {
+
+ @Override
+ public boolean onTouch(View v, android.view.MotionEvent event) {
+ final com.jogamp.newt.event.MouseEvent[] newtEvents = AndroidNewtEventFactory.createMouseEvents(event, WindowDriver.this);
+ if(null != newtEvents) {
+ focusChanged(false, true);
+ for(int i=0; i[] getCustomConstructorArgumentTypes() {
+ return new Class>[] { Context.class } ;
+ }
+
+ public WindowDriver() {
+ reset();
+ }
+
+ private void reset() {
+ ownAndroidWindow = false;
+ androidView = null;
+ nativeFormat = VisualIDHolder.VID_UNDEFINED;
+ androidFormat = VisualIDHolder.VID_UNDEFINED;
+ capsByFormat = null;
+ surface = null;
+ surfaceHandle = 0;
+ eglSurface = 0;
+ definePosition(0, 0); // default to 0/0
+ setBrokenFocusChange(true);
+ }
+
+ @Override
+ protected void instantiationFinished() {
+ final Context ctx = StaticContext.getContext();
+ if(null == ctx) {
+ throw new NativeWindowException("No static [Application] Context has been set. Call StaticContext.setContext(Context) first.");
+ }
+ androidView = new MSurfaceView(ctx);
+
+ final AndroidEvents ae = new AndroidEvents();
+ androidView.setOnTouchListener(ae);
+ androidView.setClickable(false);
+ androidView.setOnKeyListener(ae);
+ androidView.setOnFocusChangeListener(ae);
+ androidView.setFocusable(true);
+ androidView.setFocusableInTouchMode(true);
+
+ final SurfaceHolder sh = androidView.getHolder();
+ sh.addCallback(WindowDriver.this);
+ sh.setFormat(getFormat(getRequestedCapabilities()));
+
+ // default size -> TBD !
+ defineSize(0, 0);
+ }
+
+ public SurfaceView getAndroidView() { return androidView; }
+
+ @Override
+ protected boolean canCreateNativeImpl() {
+ final boolean b = 0 != surfaceHandle;
+ Log.d(MD.TAG, "canCreateNativeImpl: "+b);
+ return b;
+ }
+
+ @Override
+ protected void createNativeImpl() {
+ Log.d(MD.TAG, "createNativeImpl 0 - surfaceHandle 0x"+Long.toHexString(surfaceHandle)+
+ ", format [a "+androidFormat+", n "+nativeFormat+"], "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight()+" - "+Thread.currentThread().getName());
+
+ if(0!=getParentWindowHandle()) {
+ throw new NativeWindowException("Window parenting not supported (yet)");
+ }
+ if(0==surfaceHandle) {
+ throw new InternalError("XXX");
+ }
+
+ final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) getScreen().getDisplay().getGraphicsDevice();
+ final EGLGraphicsConfiguration eglConfig = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
+ capsByFormat, (GLCapabilitiesImmutable) getRequestedCapabilities(),
+ (GLCapabilitiesChooser)capabilitiesChooser, getScreen().getGraphicsScreen(), nativeFormat,
+ isAndroidFormatTransparent(androidFormat));
+ if (eglConfig == null) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ final int nativeVisualID = eglConfig.getVisualID(VisualIDHolder.VIDType.NATIVE);
+ Log.d(MD.TAG, "nativeVisualID 0x"+Integer.toHexString(nativeVisualID));
+ if(VisualIDHolder.VID_UNDEFINED != nativeVisualID) {
+ setSurfaceVisualID0(surfaceHandle, nativeVisualID);
+ }
+
+ eglSurface = EGL.eglCreateWindowSurface(eglDevice.getHandle(), eglConfig.getNativeConfig(), surfaceHandle, null);
+ if (EGL.EGL_NO_SURFACE==eglSurface) {
+ throw new NativeWindowException("Creation of window surface failed: "+eglConfig+", surfaceHandle 0x"+Long.toHexString(surfaceHandle)+", error "+toHexString(EGL.eglGetError()));
+ }
+
+ // propagate data ..
+ setGraphicsConfiguration(eglConfig);
+ setWindowHandle(surfaceHandle);
+ focusChanged(false, true);
+ Log.d(MD.TAG, "createNativeImpl X");
+ }
+
+ @Override
+ protected void closeNativeImpl() {
+ release0(surfaceHandle);
+ surface = null;
+ surfaceHandle = 0;
+ eglSurface = 0;
+ }
+
+ @Override
+ public final long getSurfaceHandle() {
+ return eglSurface;
+ }
+
+ protected void requestFocusImpl(boolean reparented) {
+ if(null != androidView) {
+ Log.d(MD.TAG, "requestFocusImpl: reparented "+reparented);
+ androidView.post(new Runnable() {
+ public void run() {
+ androidView.requestFocus();
+ androidView.bringToFront();
+ }
+ });
+ }
+ }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ if( 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) {
+ Log.d(MD.TAG, "reconfigureWindowImpl.setFullscreen post creation (setContentView()) n/a");
+ return false;
+ }
+ if(width>0 || height>0) {
+ if(0!=getWindowHandle()) {
+ Log.d(MD.TAG, "reconfigureWindowImpl.setSize n/a");
+ return false;
+ }
+ }
+ if(x>=0 || y>=0) {
+ Log.d(MD.TAG, "reconfigureWindowImpl.setPos n/a");
+ return false;
+ }
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop ..
+ }
+
+ //----------------------------------------------------------------------
+ // Virtual On-Screen Keyboard / SoftInput
+ //
+
+ private class KeyboardVisibleReceiver extends ResultReceiver {
+ public KeyboardVisibleReceiver() {
+ super(null);
+ }
+
+ @Override
+ public void onReceiveResult(int r, Bundle data) {
+ boolean v = false;
+
+ switch(r) {
+ case InputMethodManager.RESULT_UNCHANGED_SHOWN:
+ case InputMethodManager.RESULT_SHOWN:
+ v = true;
+ break;
+ case InputMethodManager.RESULT_HIDDEN:
+ case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
+ v = false;
+ break;
+ }
+ Log.d(MD.TAG, "keyboardVisible: "+v);
+ keyboardVisibilityChanged(v);
+ }
+ }
+ private KeyboardVisibleReceiver keyboardVisibleReceiver = new KeyboardVisibleReceiver();
+
+ protected final boolean setKeyboardVisibleImpl(boolean visible) {
+ if(null != androidView) {
+ final InputMethodManager imm = (InputMethodManager) getAndroidView().getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ final IBinder winid = getAndroidView().getWindowToken();
+ if(visible) {
+ // Show soft-keyboard:
+ imm.showSoftInput(androidView, 0, keyboardVisibleReceiver);
+ } else {
+ // hide keyboard :
+ imm.hideSoftInputFromWindow(winid, 0, keyboardVisibleReceiver);
+ }
+ return visible;
+ } else {
+ return false; // nop
+ }
+ }
+
+ //----------------------------------------------------------------------
+ // Surface Callbacks
+ //
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ Log.d(MD.TAG, "surfaceCreated: "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight());
+ }
+
+ public void surfaceChanged(SurfaceHolder aHolder, int aFormat, int aWidth, int aHeight) {
+ Log.d(MD.TAG, "surfaceChanged: f "+nativeFormat+" -> "+aFormat+", "+aWidth+"x"+aHeight+", current surfaceHandle: 0x"+Long.toHexString(surfaceHandle));
+ if(0!=surfaceHandle && androidFormat != aFormat ) {
+ // re-create
+ Log.d(MD.TAG, "surfaceChanged (destroy old)");
+ if(!windowDestroyNotify(true)) {
+ destroy();
+ }
+ surfaceHandle = 0;
+ surface=null;
+ }
+ if(getScreen().isNativeValid()) {
+ getScreen().getCurrentScreenMode(); // if ScreenMode changed .. trigger ScreenMode event
+ }
+
+ if(0>getX() || 0>getY()) {
+ positionChanged(false, 0, 0);
+ }
+
+ if(0 == surfaceHandle) {
+ androidFormat = aFormat;
+ surface = aHolder.getSurface();
+ surfaceHandle = getSurfaceHandle0(surface);
+ acquire0(surfaceHandle);
+ nativeFormat = getSurfaceVisualID0(surfaceHandle);
+ final int nWidth = getWidth0(surfaceHandle);
+ final int nHeight = getHeight0(surfaceHandle);
+ capsByFormat = (GLCapabilitiesImmutable) fixCaps(true /* matchFormatPrecise */, nativeFormat, getRequestedCapabilities());
+ sizeChanged(false, nWidth, nHeight, false);
+
+ Log.d(MD.TAG, "surfaceRealized: isValid: "+surface.isValid()+
+ ", new surfaceHandle 0x"+Long.toHexString(surfaceHandle)+
+ ", format [a "+androidFormat+"/n "+nativeFormat+"], "+
+ getX()+"/"+getY()+" "+nWidth+"x"+nHeight+", visible: "+isVisible());
+
+ if(isVisible()) {
+ setVisible(true);
+ }
+ }
+ sizeChanged(false, aWidth, aHeight, false);
+ windowRepaint(0, 0, aWidth, aHeight);
+ Log.d(MD.TAG, "surfaceChanged: X");
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ Log.d(MD.TAG, "surfaceDestroyed");
+ windowDestroyNotify(true); // actually too late .. however ..
+ }
+
+ public void surfaceRedrawNeeded(SurfaceHolder holder) {
+ Log.d(MD.TAG, "surfaceRedrawNeeded");
+ windowRepaint(0, 0, getWidth(), getHeight());
+ }
+
+ private boolean ownAndroidWindow;
+ private MSurfaceView androidView;
+ private int nativeFormat; // chosen current native PixelFormat (suitable for EGL)
+ private int androidFormat; // chosen current android PixelFormat (-1, -2 ..)
+ private GLCapabilitiesImmutable capsByFormat; // fixed requestedCaps by PixelFormat
+ private Surface surface;
+ private volatile long surfaceHandle;
+ private long eglSurface;
+
+ class MSurfaceView extends SurfaceView {
+ public MSurfaceView (Context ctx) {
+ super(ctx);
+ setBackgroundDrawable(null);
+ // setBackgroundColor(Color.TRANSPARENT);
+ }
+ }
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ protected static native boolean initIDs0();
+ protected static native long getSurfaceHandle0(Surface surface);
+ protected static native int getSurfaceVisualID0(long surfaceHandle);
+ protected static native void setSurfaceVisualID0(long surfaceHandle, int nativeVisualID);
+ protected static native int getWidth0(long surfaceHandle);
+ protected static native int getHeight0(long surfaceHandle);
+ protected static native void acquire0(long surfaceHandle);
+ protected static native void release0(long surfaceHandle);
+}
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
index a7950048a..b3fdcad41 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTDisplay.java b/src/newt/classes/jogamp/newt/driver/awt/AWTDisplay.java
deleted file mode 100644
index 65f8b4715..000000000
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTDisplay.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.awt;
-
-import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
-import com.jogamp.newt.NewtFactory;
-import com.jogamp.newt.util.EDTUtil;
-
-import jogamp.newt.DisplayImpl;
-
-public class AWTDisplay extends DisplayImpl {
- public AWTDisplay() {
- }
-
- protected void createNativeImpl() {
- aDevice = AWTGraphicsDevice.createDefault();
- }
-
- protected void setAWTGraphicsDevice(AWTGraphicsDevice d) {
- aDevice = d;
- }
-
- protected void closeNativeImpl() { }
-
- @Override
- protected EDTUtil createEDTUtil() {
- final EDTUtil def;
- if(NewtFactory.useEDT()) {
- def = AWTEDTUtil.getSingleton();
- if(DEBUG) {
- System.err.println("AWTDisplay.createNative("+getFQName()+") Create EDTUtil: "+def.getClass().getName());
- }
- } else {
- def = null;
- }
- return def;
- }
-
- protected void dispatchMessagesNative() { /* nop */ }
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java b/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java
deleted file mode 100644
index a3c0281b1..000000000
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTScreen.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2008 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
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.awt;
-
-import java.awt.DisplayMode;
-
-import jogamp.newt.ScreenImpl;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
-import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
-
-public class AWTScreen extends ScreenImpl {
- public AWTScreen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice());
- }
-
- protected void setAWTGraphicsScreen(AWTGraphicsScreen s) {
- aScreen = s;
- }
-
- /**
- * Used by AWTWindow ..
- */
- @Override
- protected void updateVirtualScreenOriginAndSize() {
- super.updateVirtualScreenOriginAndSize();
- }
-
- protected void closeNativeImpl() { }
-
- protected int validateScreenIndex(int idx) {
- return idx; // pass through ...
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode();
- if(null != mode) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(mode.getWidth());
- virtualSize.setHeight(mode.getHeight());
- }
- }
-
-}
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java
deleted file mode 100644
index 2b2fed545..000000000
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.awt;
-
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.Frame;
-import java.awt.Insets;
-
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.util.Point;
-
-import jogamp.newt.WindowImpl;
-
-import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
-import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
-import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
-import com.jogamp.newt.event.awt.AWTKeyAdapter;
-import com.jogamp.newt.event.awt.AWTMouseAdapter;
-import com.jogamp.newt.event.awt.AWTWindowAdapter;
-
-/** An implementation of the Newt Window class built using the
- AWT. This is provided for convenience of porting to platforms
- supporting Java SE. */
-
-public class AWTWindow extends WindowImpl {
-
- public AWTWindow() {
- this(null);
- }
-
- public static Class>[] getCustomConstructorArgumentTypes() {
- return new Class>[] { Container.class } ;
- }
-
- public AWTWindow(Container container) {
- super();
- this.container = container;
- if(container instanceof Frame) {
- frame = (Frame) container;
- }
- }
-
- private boolean owningFrame;
- private Container container = null;
- private Frame frame = null; // same instance as container, just for impl. convenience
- private AWTCanvas canvas;
-
- protected void requestFocusImpl(boolean reparented) {
- container.requestFocus();
- }
-
- @Override
- protected void setTitleImpl(final String title) {
- if (frame != null) {
- frame.setTitle(title);
- }
- }
-
- protected void createNativeImpl() {
- if(0!=getParentWindowHandle()) {
- throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead");
- }
-
- if(null==container) {
- frame = new Frame();
- container = frame;
- owningFrame=true;
- } else {
- owningFrame=false;
- defineSize(container.getWidth(), container.getHeight());
- definePosition(container.getX(), container.getY());
- }
- if(null!=frame) {
- frame.setTitle(getTitle());
- }
- container.setLayout(new BorderLayout());
- canvas = new AWTCanvas(capsRequested, AWTWindow.this.capabilitiesChooser);
-
- addWindowListener(new LocalWindowListener());
-
- new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here
- new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here
-
- // canvas.addComponentListener(listener);
- container.add(canvas, BorderLayout.CENTER);
- container.setSize(getWidth(), getHeight());
- container.setLocation(getX(), getY());
- new AWTWindowAdapter(this).addTo(container); // fwd all AWT Window events to here
-
- reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY | FLAG_CHANGE_DECORATION, true));
- // throws exception if failed ..
-
- setWindowHandle(1); // just a marker ..
- }
-
- protected void closeNativeImpl() {
- setWindowHandle(0); // just a marker ..
- if(null!=container) {
- container.setVisible(false);
- container.remove(canvas);
- container.setEnabled(false);
- canvas.setEnabled(false);
- }
- if(owningFrame && null!=frame) {
- frame.dispose();
- owningFrame=false;
- frame = null;
- }
- }
-
- @Override
- public boolean hasDeviceChanged() {
- boolean res = canvas.hasDeviceChanged();
- if(res) {
- final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration();
- if (null == cfg) {
- throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this);
- }
- setGraphicsConfiguration(cfg);
-
- // propagate new info ..
- ((AWTScreen)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)cfg.getScreen());
- ((AWTDisplay)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)cfg.getScreen().getDevice());
-
- ((AWTScreen)getScreen()).updateVirtualScreenOriginAndSize();
- }
- return res;
- }
-
- protected void updateInsetsImpl(javax.media.nativewindow.util.Insets insets) {
- Insets contInsets = container.getInsets();
- insets.setLeftWidth(contInsets.left);
- insets.setRightWidth(contInsets.right);
- insets.setTopHeight(contInsets.top);
- insets.setBottomHeight(contInsets.bottom);
- }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- if(0 != ( FLAG_CHANGE_DECORATION & flags) && null!=frame) {
- if(!container.isDisplayable()) {
- frame.setUndecorated(isUndecorated());
- } else {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("AWTWindow can't undecorate already created frame");
- }
- }
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- container.setVisible(0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- container.setLocation(x, y);
- Insets insets = container.getInsets();
- container.setSize(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- if( 0 != ( FLAG_IS_VISIBLE & flags ) ) {
- if( !hasDeviceChanged() ) {
- // oops ??
- final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration();
- if(null == cfg) {
- throw new NativeWindowException("Error: !hasDeviceChanged && null == GraphicsConfiguration: "+this);
- }
- setGraphicsConfiguration(cfg);
- }
- }
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- return true;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- java.awt.Point ap = canvas.getLocationOnScreen();
- ap.translate(x, y);
- return new Point((int)(ap.getX()+0.5),(int)(ap.getY()+0.5));
- }
-
- @Override
- public Object getWrappedWindow() {
- return canvas;
- }
-
- class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter {
- @Override
- public void windowMoved(com.jogamp.newt.event.WindowEvent e) {
- if(null!=container) {
- definePosition(container.getX(), container.getY());
- }
- }
- @Override
- public void windowResized(com.jogamp.newt.event.WindowEvent e) {
- if(null!=canvas) {
- defineSize(canvas.getWidth(), canvas.getHeight());
- }
- }
- }
-}
diff --git a/src/newt/classes/jogamp/newt/driver/awt/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/awt/DisplayDriver.java
new file mode 100644
index 000000000..39d96585b
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/awt/DisplayDriver.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.awt;
+
+import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.util.EDTUtil;
+
+import jogamp.newt.DisplayImpl;
+
+public class DisplayDriver extends DisplayImpl {
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aDevice = AWTGraphicsDevice.createDefault();
+ }
+
+ protected void setAWTGraphicsDevice(AWTGraphicsDevice d) {
+ aDevice = d;
+ }
+
+ protected void closeNativeImpl() { }
+
+ @Override
+ protected EDTUtil createEDTUtil() {
+ final EDTUtil def;
+ if(NewtFactory.useEDT()) {
+ def = AWTEDTUtil.getSingleton();
+ if(DEBUG) {
+ System.err.println("AWTDisplay.createNative("+getFQName()+") Create EDTUtil: "+def.getClass().getName());
+ }
+ } else {
+ def = null;
+ }
+ return def;
+ }
+
+ protected void dispatchMessagesNative() { /* nop */ }
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java
new file mode 100644
index 000000000..6b1283a00
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2008 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
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.awt;
+
+import java.awt.DisplayMode;
+
+import jogamp.newt.ScreenImpl;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
+import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+
+public class ScreenDriver extends ScreenImpl {
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice());
+ }
+
+ protected void setAWTGraphicsScreen(AWTGraphicsScreen s) {
+ aScreen = s;
+ }
+
+ /**
+ * Used by AWTWindow ..
+ */
+ @Override
+ protected void updateVirtualScreenOriginAndSize() {
+ super.updateVirtualScreenOriginAndSize();
+ }
+
+ protected void closeNativeImpl() { }
+
+ protected int validateScreenIndex(int idx) {
+ return idx; // pass through ...
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode();
+ if(null != mode) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ virtualSize.setWidth(mode.getWidth());
+ virtualSize.setHeight(mode.getHeight());
+ }
+ }
+
+}
diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
new file mode 100644
index 000000000..1723ffee5
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.awt;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Frame;
+import java.awt.Insets;
+
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.newt.WindowImpl;
+
+import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
+import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
+import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+import com.jogamp.newt.event.awt.AWTKeyAdapter;
+import com.jogamp.newt.event.awt.AWTMouseAdapter;
+import com.jogamp.newt.event.awt.AWTWindowAdapter;
+
+/** An implementation of the Newt Window class built using the
+ AWT. This is provided for convenience of porting to platforms
+ supporting Java SE. */
+
+public class WindowDriver extends WindowImpl {
+
+ public WindowDriver() {
+ this(null);
+ }
+
+ public static Class>[] getCustomConstructorArgumentTypes() {
+ return new Class>[] { Container.class } ;
+ }
+
+ public WindowDriver(Container container) {
+ super();
+ this.container = container;
+ if(container instanceof Frame) {
+ frame = (Frame) container;
+ }
+ }
+
+ private boolean owningFrame;
+ private Container container = null;
+ private Frame frame = null; // same instance as container, just for impl. convenience
+ private AWTCanvas canvas;
+
+ protected void requestFocusImpl(boolean reparented) {
+ container.requestFocus();
+ }
+
+ @Override
+ protected void setTitleImpl(final String title) {
+ if (frame != null) {
+ frame.setTitle(title);
+ }
+ }
+
+ protected void createNativeImpl() {
+ if(0!=getParentWindowHandle()) {
+ throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead");
+ }
+
+ if(null==container) {
+ frame = new Frame();
+ container = frame;
+ owningFrame=true;
+ } else {
+ owningFrame=false;
+ defineSize(container.getWidth(), container.getHeight());
+ definePosition(container.getX(), container.getY());
+ }
+ if(null!=frame) {
+ frame.setTitle(getTitle());
+ }
+ container.setLayout(new BorderLayout());
+ canvas = new AWTCanvas(capsRequested, WindowDriver.this.capabilitiesChooser);
+
+ addWindowListener(new LocalWindowListener());
+
+ new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here
+ new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here
+
+ // canvas.addComponentListener(listener);
+ container.add(canvas, BorderLayout.CENTER);
+ container.setSize(getWidth(), getHeight());
+ container.setLocation(getX(), getY());
+ new AWTWindowAdapter(this).addTo(container); // fwd all AWT Window events to here
+
+ reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY | FLAG_CHANGE_DECORATION, true));
+ // throws exception if failed ..
+
+ setWindowHandle(1); // just a marker ..
+ }
+
+ protected void closeNativeImpl() {
+ setWindowHandle(0); // just a marker ..
+ if(null!=container) {
+ container.setVisible(false);
+ container.remove(canvas);
+ container.setEnabled(false);
+ canvas.setEnabled(false);
+ }
+ if(owningFrame && null!=frame) {
+ frame.dispose();
+ owningFrame=false;
+ frame = null;
+ }
+ }
+
+ @Override
+ public boolean hasDeviceChanged() {
+ boolean res = canvas.hasDeviceChanged();
+ if(res) {
+ final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration();
+ if (null == cfg) {
+ throw new NativeWindowException("Error Device change null GraphicsConfiguration: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+
+ // propagate new info ..
+ ((ScreenDriver)getScreen()).setAWTGraphicsScreen((AWTGraphicsScreen)cfg.getScreen());
+ ((DisplayDriver)getScreen().getDisplay()).setAWTGraphicsDevice((AWTGraphicsDevice)cfg.getScreen().getDevice());
+
+ ((ScreenDriver)getScreen()).updateVirtualScreenOriginAndSize();
+ }
+ return res;
+ }
+
+ protected void updateInsetsImpl(javax.media.nativewindow.util.Insets insets) {
+ Insets contInsets = container.getInsets();
+ insets.setLeftWidth(contInsets.left);
+ insets.setRightWidth(contInsets.right);
+ insets.setTopHeight(contInsets.top);
+ insets.setBottomHeight(contInsets.bottom);
+ }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ if(0 != ( FLAG_CHANGE_DECORATION & flags) && null!=frame) {
+ if(!container.isDisplayable()) {
+ frame.setUndecorated(isUndecorated());
+ } else {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("AWTWindow can't undecorate already created frame");
+ }
+ }
+ }
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ container.setVisible(0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ container.setLocation(x, y);
+ Insets insets = container.getInsets();
+ container.setSize(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ if( 0 != ( FLAG_IS_VISIBLE & flags ) ) {
+ if( !hasDeviceChanged() ) {
+ // oops ??
+ final AWTGraphicsConfiguration cfg = canvas.getAWTGraphicsConfiguration();
+ if(null == cfg) {
+ throw new NativeWindowException("Error: !hasDeviceChanged && null == GraphicsConfiguration: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+ }
+ }
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ java.awt.Point ap = canvas.getLocationOnScreen();
+ ap.translate(x, y);
+ return new Point((int)(ap.getX()+0.5),(int)(ap.getY()+0.5));
+ }
+
+ @Override
+ public Object getWrappedWindow() {
+ return canvas;
+ }
+
+ class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter {
+ @Override
+ public void windowMoved(com.jogamp.newt.event.WindowEvent e) {
+ if(null!=container) {
+ definePosition(container.getX(), container.getY());
+ }
+ }
+ @Override
+ public void windowResized(com.jogamp.newt.event.WindowEvent e) {
+ if(null!=canvas) {
+ defineSize(canvas.getWidth(), canvas.getHeight());
+ }
+ }
+ }
+}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/Display.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/Display.java
deleted file mode 100644
index f08890da6..000000000
--- a/src/newt/classes/jogamp/newt/driver/bcm/egl/Display.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2012 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.bcm.egl;
-
-import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.NativeWindowException;
-
-import jogamp.newt.NEWTJNILibLoader;
-import jogamp.opengl.egl.EGL;
-
-import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
-
-public class Display extends jogamp.newt.DisplayImpl {
-
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if (!Window.initIDs()) {
- throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs");
- }
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
-
- public Display() {
- }
-
- protected void createNativeImpl() {
- final long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight);
- if (handle == EGL.EGL_NO_DISPLAY) {
- throw new NativeWindowException("BC EGL CreateDisplay failed");
- }
- aDevice = new EGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, handle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT, null);
- }
-
- protected void closeNativeImpl() {
- if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
- DestroyDisplay(aDevice.getHandle());
- }
- }
-
- protected void dispatchMessagesNative() {
- // n/a .. DispatchMessages();
- }
-
- private native long CreateDisplay(int width, int height);
- private native void DestroyDisplay(long dpy);
- private native void DispatchMessages();
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/DisplayDriver.java
new file mode 100644
index 000000000..65ca63eec
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/DisplayDriver.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.bcm.egl;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+
+import jogamp.newt.NEWTJNILibLoader;
+import jogamp.opengl.egl.EGL;
+
+import com.jogamp.nativewindow.egl.EGLGraphicsDevice;
+
+public class DisplayDriver extends jogamp.newt.DisplayImpl {
+
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if (!WindowDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize BCEGL Window jmethodIDs");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ final long handle = CreateDisplay(ScreenDriver.fixedWidth, ScreenDriver.fixedHeight);
+ if (handle == EGL.EGL_NO_DISPLAY) {
+ throw new NativeWindowException("BC EGL CreateDisplay failed");
+ }
+ aDevice = new EGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, handle, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT, null);
+ }
+
+ protected void closeNativeImpl() {
+ if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
+ DestroyDisplay(aDevice.getHandle());
+ }
+ }
+
+ protected void dispatchMessagesNative() {
+ // n/a .. DispatchMessages();
+ }
+
+ private native long CreateDisplay(int width, int height);
+ private native void DestroyDisplay(long dpy);
+ private native void DispatchMessages();
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/Screen.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/Screen.java
deleted file mode 100644
index 909444d24..000000000
--- a/src/newt/classes/jogamp/newt/driver/bcm/egl/Screen.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2012 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.bcm.egl;
-
-import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-public class Screen extends jogamp.newt.ScreenImpl {
-
- static {
- Display.initSingleton();
- }
-
-
- public Screen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- }
-
- protected void closeNativeImpl() { }
-
- protected int validateScreenIndex(int idx) {
- return 0; // only one screen available
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(fixedWidth); // FIXME
- virtualSize.setHeight(fixedHeight); // FIXME
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- static final int fixedWidth = 1920; // FIXME
- static final int fixedHeight = 1080; // FIXME
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java
new file mode 100644
index 000000000..deb2a534b
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.bcm.egl;
+
+import javax.media.nativewindow.DefaultGraphicsScreen;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+public class ScreenDriver extends jogamp.newt.ScreenImpl {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() { }
+
+ protected int validateScreenIndex(int idx) {
+ return 0; // only one screen available
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ virtualSize.setWidth(fixedWidth); // FIXME
+ virtualSize.setHeight(fixedHeight); // FIXME
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ static final int fixedWidth = 1920; // FIXME
+ static final int fixedHeight = 1080; // FIXME
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/Window.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/Window.java
deleted file mode 100644
index 87170e4ab..000000000
--- a/src/newt/classes/jogamp/newt/driver/bcm/egl/Window.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2012 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.bcm.egl;
-
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.VisualIDHolder;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.Point;
-import javax.media.opengl.GLCapabilitiesImmutable;
-
-import jogamp.opengl.egl.EGLGraphicsConfiguration;
-
-public class Window extends jogamp.newt.WindowImpl {
- static {
- Display.initSingleton();
- }
-
- public Window() {
- }
-
- protected void createNativeImpl() {
- if(0!=getParentWindowHandle()) {
- throw new RuntimeException("Window parenting not supported (yet)");
- }
- // query a good configuration, however chose the final one by the native queried egl-cfg-id
- // after creation at {@link #windowCreated(int, int, int)}.
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- setGraphicsConfiguration(cfg);
- setSizeImpl(getScreen().getWidth(), getScreen().getHeight());
-
- setWindowHandle(realizeWindow(true, getWidth(), getHeight()));
- if (0 == getWindowHandle()) {
- throw new NativeWindowException("Error native Window Handle is null");
- }
- }
-
- protected void closeNativeImpl() {
- if(0!=windowHandleClose) {
- CloseWindow(getDisplayHandle(), windowHandleClose);
- }
- }
-
- protected void requestFocusImpl(boolean reparented) { }
-
- protected void setSizeImpl(int width, int height) {
- if(0!=getWindowHandle()) {
- // n/a in BroadcomEGL
- System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window");
- } else {
- defineSize(width, height);
- }
- }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- if(0!=getWindowHandle()) {
- if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
- if( 0 != ( FLAG_IS_FULLSCREEN & flags) ) {
- // n/a in BroadcomEGL
- System.err.println("setFullscreen n/a in BroadcomEGL");
- return false;
- }
- }
- }
- if(width>0 || height>0) {
- if(0!=getWindowHandle()) {
- // n/a in BroadcomEGL
- System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window");
- } else {
- defineSize((width>0)?width:getWidth(), (height>0)?height:getHeight());
- }
- }
- if(x>=0 || y>=0) {
- System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL");
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
- return true;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- return new Point(x,y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop ..
- }
-
- @Override
- public boolean surfaceSwap() {
- SwapWindow(getDisplayHandle(), getWindowHandle());
- return true;
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- protected static native boolean initIDs();
- private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height);
- private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle);
- private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle);
-
-
- private long realizeWindow(boolean chromaKey, int width, int height) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+getGraphicsConfiguration());
- }
- long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height);
- if (0 == handle) {
- throw new NativeWindowException("Error native Window Handle is null");
- }
- windowHandleClose = handle;
- return handle;
- }
-
- private void windowCreated(int cfgID, int width, int height) {
- defineSize(width, height);
- GLCapabilitiesImmutable capsReq = (GLCapabilitiesImmutable) getGraphicsConfiguration().getRequestedCapabilities();
- final AbstractGraphicsConfiguration cfg = EGLGraphicsConfiguration.create(capsReq, getScreen().getGraphicsScreen(), cfgID);
- if (null == cfg) {
- throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this);
- }
- setGraphicsConfiguration(cfg);
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+cfg);
- }
- }
-
- private long windowHandleClose;
-}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java
new file mode 100644
index 000000000..49d3d98ba
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/WindowDriver.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.bcm.egl;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.VisualIDHolder;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
+import javax.media.opengl.GLCapabilitiesImmutable;
+
+import jogamp.opengl.egl.EGLGraphicsConfiguration;
+
+public class WindowDriver extends jogamp.newt.WindowImpl {
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ }
+
+ protected void createNativeImpl() {
+ if(0!=getParentWindowHandle()) {
+ throw new RuntimeException("Window parenting not supported (yet)");
+ }
+ // query a good configuration, however chose the final one by the native queried egl-cfg-id
+ // after creation at {@link #windowCreated(int, int, int)}.
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+ setSizeImpl(getScreen().getWidth(), getScreen().getHeight());
+
+ setWindowHandle(realizeWindow(true, getWidth(), getHeight()));
+ if (0 == getWindowHandle()) {
+ throw new NativeWindowException("Error native Window Handle is null");
+ }
+ }
+
+ protected void closeNativeImpl() {
+ if(0!=windowHandleClose) {
+ CloseWindow(getDisplayHandle(), windowHandleClose);
+ }
+ }
+
+ protected void requestFocusImpl(boolean reparented) { }
+
+ protected void setSizeImpl(int width, int height) {
+ if(0!=getWindowHandle()) {
+ // n/a in BroadcomEGL
+ System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window");
+ } else {
+ defineSize(width, height);
+ }
+ }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ if(0!=getWindowHandle()) {
+ if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
+ if( 0 != ( FLAG_IS_FULLSCREEN & flags) ) {
+ // n/a in BroadcomEGL
+ System.err.println("setFullscreen n/a in BroadcomEGL");
+ return false;
+ }
+ }
+ }
+ if(width>0 || height>0) {
+ if(0!=getWindowHandle()) {
+ // n/a in BroadcomEGL
+ System.err.println("BCEGL Window.setSizeImpl n/a in BroadcomEGL with realized window");
+ } else {
+ defineSize((width>0)?width:getWidth(), (height>0)?height:getHeight());
+ }
+ }
+ if(x>=0 || y>=0) {
+ System.err.println("BCEGL Window.setPositionImpl n/a in BroadcomEGL");
+ }
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop ..
+ }
+
+ @Override
+ public boolean surfaceSwap() {
+ SwapWindow(getDisplayHandle(), getWindowHandle());
+ return true;
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ protected static native boolean initIDs();
+ private native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height);
+ private native void CloseWindow(long eglDisplayHandle, long eglWindowHandle);
+ private native void SwapWindow(long eglDisplayHandle, long eglWindowHandle);
+
+
+ private long realizeWindow(boolean chromaKey, int width, int height) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("BCEGL Window.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+getGraphicsConfiguration());
+ }
+ long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height);
+ if (0 == handle) {
+ throw new NativeWindowException("Error native Window Handle is null");
+ }
+ windowHandleClose = handle;
+ return handle;
+ }
+
+ private void windowCreated(int cfgID, int width, int height) {
+ defineSize(width, height);
+ GLCapabilitiesImmutable capsReq = (GLCapabilitiesImmutable) getGraphicsConfiguration().getRequestedCapabilities();
+ final AbstractGraphicsConfiguration cfg = EGLGraphicsConfiguration.create(capsReq, getScreen().getGraphicsScreen(), cfgID);
+ if (null == cfg) {
+ throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this);
+ }
+ setGraphicsConfiguration(cfg);
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("BCEGL Window.windowCreated(): "+toHexString(cfgID)+", "+width+"x"+height+", "+cfg);
+ }
+ }
+
+ private long windowHandleClose;
+}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java
deleted file mode 100644
index 62af02abb..000000000
--- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Display.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Copyright 2012 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 jogamp.newt.driver.bcm.vc.iv;
-
-import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.NativeWindowException;
-
-import jogamp.newt.DisplayImpl;
-import jogamp.newt.NEWTJNILibLoader;
-import jogamp.opengl.egl.EGL;
-import jogamp.opengl.egl.EGLDisplayUtil;
-
-public class Display extends DisplayImpl {
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if (!Display.initIDs()) {
- throw new NativeWindowException("Failed to initialize bcm.vc.iv Display jmethodIDs");
- }
- if (!Screen.initIDs()) {
- throw new NativeWindowException("Failed to initialize bcm.vc.iv Screen jmethodIDs");
- }
- if (!Window.initIDs()) {
- throw new NativeWindowException("Failed to initialize bcm.vc.iv Window jmethodIDs");
- }
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
-
- public Display() {
- }
-
- protected void createNativeImpl() {
- // FIXME: map name to EGL_*_DISPLAY
- aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
- }
-
- protected void closeNativeImpl() {
- aDevice.close();
- }
-
- protected void dispatchMessagesNative() {
- DispatchMessages();
- }
-
- protected static native boolean initIDs();
- private native void DispatchMessages();
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/DisplayDriver.java
new file mode 100644
index 000000000..08c5c573c
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/DisplayDriver.java
@@ -0,0 +1,78 @@
+/**
+ * Copyright 2012 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 jogamp.newt.driver.bcm.vc.iv;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.NEWTJNILibLoader;
+import jogamp.opengl.egl.EGL;
+import jogamp.opengl.egl.EGLDisplayUtil;
+
+public class DisplayDriver extends DisplayImpl {
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if (!DisplayDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize bcm.vc.iv Display jmethodIDs");
+ }
+ if (!ScreenDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize bcm.vc.iv Screen jmethodIDs");
+ }
+ if (!WindowDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize bcm.vc.iv Window jmethodIDs");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ // FIXME: map name to EGL_*_DISPLAY
+ aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+
+ protected void closeNativeImpl() {
+ aDevice.close();
+ }
+
+ protected void dispatchMessagesNative() {
+ DispatchMessages();
+ }
+
+ protected static native boolean initIDs();
+ private native void DispatchMessages();
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java
deleted file mode 100644
index 484d4bf81..000000000
--- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Screen.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * Copyright 2012 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 jogamp.newt.driver.bcm.vc.iv;
-
-import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-import jogamp.newt.ScreenImpl;
-
-public class Screen extends ScreenImpl {
- static {
- Display.initSingleton();
- }
-
- public Screen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- initNative();
- }
-
- protected void closeNativeImpl() { }
-
- protected int validateScreenIndex(int idx) {
- return 0; // only one screen available
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(cachedWidth);
- virtualSize.setHeight(cachedHeight);
- }
-
- protected void setScreenSize(int width, int height) {
- cachedWidth = width;
- cachedHeight = height;
- }
-
- private static int cachedWidth = 0;
- private static int cachedHeight = 0;
-
- protected static native boolean initIDs();
- protected native void initNative();
-}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java
new file mode 100644
index 000000000..787d1a1b4
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2012 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 jogamp.newt.driver.bcm.vc.iv;
+
+import javax.media.nativewindow.DefaultGraphicsScreen;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.newt.ScreenImpl;
+
+public class ScreenDriver extends ScreenImpl {
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ initNative();
+ }
+
+ protected void closeNativeImpl() { }
+
+ protected int validateScreenIndex(int idx) {
+ return 0; // only one screen available
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ virtualSize.setWidth(cachedWidth);
+ virtualSize.setHeight(cachedHeight);
+ }
+
+ protected void setScreenSize(int width, int height) {
+ cachedWidth = width;
+ cachedHeight = height;
+ }
+
+ private static int cachedWidth = 0;
+ private static int cachedHeight = 0;
+
+ protected static native boolean initIDs();
+ protected native void initNative();
+}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java
deleted file mode 100644
index 3d00949de..000000000
--- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/Window.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/**
- * Copyright 2012 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 jogamp.newt.driver.bcm.vc.iv;
-
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.VisualIDHolder;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.Point;
-
-import jogamp.newt.WindowImpl;
-import jogamp.newt.driver.linux.LinuxMouseTracker;
-
-public class Window extends WindowImpl {
- private static final String WINDOW_CLASS_NAME = "NewtWindow";
-
- static {
- Display.initSingleton();
- }
-
- public Window() {
- }
-
- protected void createNativeImpl() {
- if(0!=getParentWindowHandle()) {
- throw new RuntimeException("Window parenting not supported (yet)");
- }
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- setGraphicsConfiguration(cfg);
-
- nativeWindowHandle = CreateWindow(getWidth(), getHeight());
- if (nativeWindowHandle == 0) {
- throw new NativeWindowException("Error creating egl window: "+cfg);
- }
- setVisible0(nativeWindowHandle, false);
- setWindowHandle(nativeWindowHandle);
- if (0 == getWindowHandle()) {
- throw new NativeWindowException("Error native Window Handle is null");
- }
- windowHandleClose = nativeWindowHandle;
- addWindowListener(LinuxMouseTracker.getSingleton());
- focusChanged(false, true);
- }
-
- protected void closeNativeImpl() {
- removeWindowListener(LinuxMouseTracker.getSingleton());
-
- if(0!=windowHandleClose) {
- CloseWindow(windowHandleClose, windowUserData);
- windowUserData=0;
- }
- }
-
- protected void requestFocusImpl(boolean reparented) {
- focusChanged(false, true);
- }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- setVisible0(nativeWindowHandle, 0 != ( FLAG_IS_VISIBLE & flags));
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- if(0!=nativeWindowHandle) {
- if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
- final boolean fs = 0 != ( FLAG_IS_FULLSCREEN & flags) ;
- setFullScreen0(nativeWindowHandle, fs);
- if(fs) {
- return true;
- }
- }
- // int _x=(x>=0)?x:this.x;
- // int _y=(x>=0)?y:this.y;
- width=(width>0)?width:getWidth();
- height=(height>0)?height:getHeight();
- if(width>0 || height>0) {
- setSize0(nativeWindowHandle, width, height);
- }
- if(x>=0 || y>=0) {
- System.err.println("setPosition n/a in KD");
- }
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- return true;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- return new Point(x,y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop ..
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- protected static native boolean initIDs();
- private native long CreateWindow(int width, int height);
- private native long RealizeWindow(long eglWindowHandle);
- private native int CloseWindow(long eglWindowHandle, long userData);
- private native void setVisible0(long eglWindowHandle, boolean visible);
- private native void setSize0(long eglWindowHandle, int width, int height);
- private native void setFullScreen0(long eglWindowHandle, boolean fullscreen);
-
- private void windowCreated(long userData) {
- windowUserData=userData;
- }
-
- private long nativeWindowHandle;
- private long windowHandleClose;
- private long windowUserData;
-}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
new file mode 100644
index 000000000..6d4f36964
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java
@@ -0,0 +1,149 @@
+/**
+ * Copyright 2012 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 jogamp.newt.driver.bcm.vc.iv;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.VisualIDHolder;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.newt.WindowImpl;
+import jogamp.newt.driver.linux.LinuxMouseTracker;
+
+public class WindowDriver extends WindowImpl {
+ private static final String WINDOW_CLASS_NAME = "NewtWindow";
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ }
+
+ protected void createNativeImpl() {
+ if(0!=getParentWindowHandle()) {
+ throw new RuntimeException("Window parenting not supported (yet)");
+ }
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+
+ nativeWindowHandle = CreateWindow(getWidth(), getHeight());
+ if (nativeWindowHandle == 0) {
+ throw new NativeWindowException("Error creating egl window: "+cfg);
+ }
+ setVisible0(nativeWindowHandle, false);
+ setWindowHandle(nativeWindowHandle);
+ if (0 == getWindowHandle()) {
+ throw new NativeWindowException("Error native Window Handle is null");
+ }
+ windowHandleClose = nativeWindowHandle;
+ addWindowListener(LinuxMouseTracker.getSingleton());
+ focusChanged(false, true);
+ }
+
+ protected void closeNativeImpl() {
+ removeWindowListener(LinuxMouseTracker.getSingleton());
+
+ if(0!=windowHandleClose) {
+ CloseWindow(windowHandleClose, windowUserData);
+ windowUserData=0;
+ }
+ }
+
+ protected void requestFocusImpl(boolean reparented) {
+ focusChanged(false, true);
+ }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ setVisible0(nativeWindowHandle, 0 != ( FLAG_IS_VISIBLE & flags));
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ if(0!=nativeWindowHandle) {
+ if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
+ final boolean fs = 0 != ( FLAG_IS_FULLSCREEN & flags) ;
+ setFullScreen0(nativeWindowHandle, fs);
+ if(fs) {
+ return true;
+ }
+ }
+ // int _x=(x>=0)?x:this.x;
+ // int _y=(x>=0)?y:this.y;
+ width=(width>0)?width:getWidth();
+ height=(height>0)?height:getHeight();
+ if(width>0 || height>0) {
+ setSize0(nativeWindowHandle, width, height);
+ }
+ if(x>=0 || y>=0) {
+ System.err.println("setPosition n/a in KD");
+ }
+ }
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop ..
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ protected static native boolean initIDs();
+ private native long CreateWindow(int width, int height);
+ private native long RealizeWindow(long eglWindowHandle);
+ private native int CloseWindow(long eglWindowHandle, long userData);
+ private native void setVisible0(long eglWindowHandle, boolean visible);
+ private native void setSize0(long eglWindowHandle, int width, int height);
+ private native void setFullScreen0(long eglWindowHandle, boolean fullscreen);
+
+ private void windowCreated(long userData) {
+ windowUserData=userData;
+ }
+
+ private long nativeWindowHandle;
+ private long windowHandleClose;
+ private long windowUserData;
+}
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/Display.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/Display.java
deleted file mode 100644
index 20e151eb3..000000000
--- a/src/newt/classes/jogamp/newt/driver/intel/gdl/Display.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2008 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
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.intel.gdl;
-
-import jogamp.newt.*;
-import javax.media.nativewindow.*;
-
-public class Display extends jogamp.newt.DisplayImpl {
- static int initCounter = 0;
-
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if (!Screen.initIDs()) {
- throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs");
- }
- if (!Window.initIDs()) {
- throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs");
- }
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
-
- public Display() {
- }
-
- protected void createNativeImpl() {
- synchronized(Display.class) {
- if(0==initCounter) {
- displayHandle = CreateDisplay();
- if(0==displayHandle) {
- throw new NativeWindowException("Couldn't initialize GDL Display");
- }
- }
- initCounter++;
- }
- aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT, displayHandle);
- }
-
- protected void closeNativeImpl() {
- if(0==displayHandle) {
- throw new NativeWindowException("displayHandle null; initCnt "+initCounter);
- }
- synchronized(Display.class) {
- if(initCounter>0) {
- initCounter--;
- if(0==initCounter) {
- DestroyDisplay(displayHandle);
- }
- }
- }
- }
-
- protected void dispatchMessagesNative() {
- if(0!=displayHandle) {
- DispatchMessages(displayHandle, focusedWindow);
- }
- }
-
- protected void setFocus(Window focus) {
- focusedWindow = focus;
- }
-
- private long displayHandle = 0;
- private Window focusedWindow = null;
- private native long CreateDisplay();
- private native void DestroyDisplay(long displayHandle);
- private native void DispatchMessages(long displayHandle, Window focusedWindow);
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/DisplayDriver.java
new file mode 100644
index 000000000..97c384d33
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/DisplayDriver.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.intel.gdl;
+
+import jogamp.newt.*;
+import javax.media.nativewindow.*;
+
+public class DisplayDriver extends jogamp.newt.DisplayImpl {
+ static int initCounter = 0;
+
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if (!ScreenDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize GDL Screen jmethodIDs");
+ }
+ if (!WindowDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize GDL Window jmethodIDs");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ synchronized(DisplayDriver.class) {
+ if(0==initCounter) {
+ displayHandle = CreateDisplay();
+ if(0==displayHandle) {
+ throw new NativeWindowException("Couldn't initialize GDL Display");
+ }
+ }
+ initCounter++;
+ }
+ aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT, displayHandle);
+ }
+
+ protected void closeNativeImpl() {
+ if(0==displayHandle) {
+ throw new NativeWindowException("displayHandle null; initCnt "+initCounter);
+ }
+ synchronized(DisplayDriver.class) {
+ if(initCounter>0) {
+ initCounter--;
+ if(0==initCounter) {
+ DestroyDisplay(displayHandle);
+ }
+ }
+ }
+ }
+
+ protected void dispatchMessagesNative() {
+ if(0!=displayHandle) {
+ DispatchMessages(displayHandle, focusedWindow);
+ }
+ }
+
+ protected void setFocus(WindowDriver focus) {
+ focusedWindow = focus;
+ }
+
+ private long displayHandle = 0;
+ private WindowDriver focusedWindow = null;
+ private native long CreateDisplay();
+ private native void DestroyDisplay(long displayHandle);
+ private native void DispatchMessages(long displayHandle, WindowDriver focusedWindow);
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java
deleted file mode 100644
index 66ad1c691..000000000
--- a/src/newt/classes/jogamp/newt/driver/intel/gdl/Screen.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2008 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
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.intel.gdl;
-
-import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-public class Screen extends jogamp.newt.ScreenImpl {
-
- static {
- Display.initSingleton();
- }
-
- public Screen() {
- }
-
- protected void createNativeImpl() {
- AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice();
- GetScreenInfo(adevice.getHandle(), screen_idx);
- aScreen = new DefaultGraphicsScreen(adevice, screen_idx);
- }
-
- protected void closeNativeImpl() { }
-
- protected int validateScreenIndex(int idx) {
- return 0; // only one screen available
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(cachedWidth);
- virtualSize.setHeight(cachedHeight);
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- protected static native boolean initIDs();
- private native void GetScreenInfo(long displayHandle, int screen_idx);
-
- // called by GetScreenInfo() ..
- private void screenCreated(int width, int height) {
- cachedWidth = width;
- cachedHeight = height;
- }
-
- private static int cachedWidth = 0;
- private static int cachedHeight = 0;
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java
new file mode 100644
index 000000000..8eed14dde
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.intel.gdl;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.DefaultGraphicsScreen;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+public class ScreenDriver extends jogamp.newt.ScreenImpl {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice();
+ GetScreenInfo(adevice.getHandle(), screen_idx);
+ aScreen = new DefaultGraphicsScreen(adevice, screen_idx);
+ }
+
+ protected void closeNativeImpl() { }
+
+ protected int validateScreenIndex(int idx) {
+ return 0; // only one screen available
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ virtualSize.setWidth(cachedWidth);
+ virtualSize.setHeight(cachedHeight);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ protected static native boolean initIDs();
+ private native void GetScreenInfo(long displayHandle, int screen_idx);
+
+ // called by GetScreenInfo() ..
+ private void screenCreated(int width, int height) {
+ cachedWidth = width;
+ cachedHeight = height;
+ }
+
+ private static int cachedWidth = 0;
+ private static int cachedHeight = 0;
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java
deleted file mode 100644
index d5c75abd4..000000000
--- a/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (c) 2008 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
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.intel.gdl;
-
-import javax.media.nativewindow.*;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.Point;
-
-public class Window extends jogamp.newt.WindowImpl {
- static {
- Display.initSingleton();
- }
-
- public Window() {
- }
-
- static long nextWindowHandle = 1;
-
- protected void createNativeImpl() {
- if(0!=getParentWindowHandle()) {
- throw new NativeWindowException("GDL Window does not support window parenting");
- }
- final AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen();
- final AbstractGraphicsDevice aDevice = getScreen().getDisplay().getGraphicsDevice();
-
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(aDevice, capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, aScreen, VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- setGraphicsConfiguration(cfg);
-
- synchronized(Window.class) {
- setWindowHandle(nextWindowHandle++); // just a marker
-
- surfaceHandle = CreateSurface(aDevice.getHandle(), getScreen().getWidth(), getScreen().getHeight(), getX(), getY(), getWidth(), getHeight());
- if (surfaceHandle == 0) {
- throw new NativeWindowException("Error creating window");
- }
- }
- }
-
- protected void closeNativeImpl() {
- if(0!=surfaceHandle) {
- synchronized(Window.class) {
- CloseSurface(getDisplayHandle(), surfaceHandle);
- }
- surfaceHandle = 0;
- ((Display)getScreen().getDisplay()).setFocus(null);
- }
- }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- Screen screen = (Screen) getScreen();
-
- if(width>screen.getWidth()) {
- width=screen.getWidth();
- }
- if(height>screen.getHeight()) {
- height=screen.getHeight();
- }
- if((x+width)>screen.getWidth()) {
- x=screen.getWidth()-width;
- }
- if((y+height)>screen.getHeight()) {
- y=screen.getHeight()-height;
- }
-
- if(0!=surfaceHandle) {
- SetBounds0(surfaceHandle, getScreen().getWidth(), getScreen().getHeight(), x, y, width, height);
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- if(0 != ( FLAG_IS_VISIBLE & flags)) {
- ((Display)getScreen().getDisplay()).setFocus(this);
- }
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- return true;
- }
-
- protected void requestFocusImpl(boolean reparented) {
- ((Display)getScreen().getDisplay()).setFocus(this);
- }
-
- @Override
- public final long getSurfaceHandle() {
- return surfaceHandle;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- return new Point(x,y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop ..
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- protected static native boolean initIDs();
- private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height);
- private native void CloseSurface(long displayHandle, long surfaceHandle);
- private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height);
-
- private void updateBounds(int x, int y, int width, int height) {
- definePosition(x, y);
- defineSize(width, height);
- }
-
- private long surfaceHandle;
-}
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java
new file mode 100644
index 000000000..98335f192
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/WindowDriver.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.intel.gdl;
+
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
+
+public class WindowDriver extends jogamp.newt.WindowImpl {
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ }
+
+ static long nextWindowHandle = 1;
+
+ protected void createNativeImpl() {
+ if(0!=getParentWindowHandle()) {
+ throw new NativeWindowException("GDL Window does not support window parenting");
+ }
+ final AbstractGraphicsScreen aScreen = getScreen().getGraphicsScreen();
+ final AbstractGraphicsDevice aDevice = getScreen().getDisplay().getGraphicsDevice();
+
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(aDevice, capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, aScreen, VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+
+ synchronized(WindowDriver.class) {
+ setWindowHandle(nextWindowHandle++); // just a marker
+
+ surfaceHandle = CreateSurface(aDevice.getHandle(), getScreen().getWidth(), getScreen().getHeight(), getX(), getY(), getWidth(), getHeight());
+ if (surfaceHandle == 0) {
+ throw new NativeWindowException("Error creating window");
+ }
+ }
+ }
+
+ protected void closeNativeImpl() {
+ if(0!=surfaceHandle) {
+ synchronized(WindowDriver.class) {
+ CloseSurface(getDisplayHandle(), surfaceHandle);
+ }
+ surfaceHandle = 0;
+ ((DisplayDriver)getScreen().getDisplay()).setFocus(null);
+ }
+ }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ ScreenDriver screen = (ScreenDriver) getScreen();
+
+ if(width>screen.getWidth()) {
+ width=screen.getWidth();
+ }
+ if(height>screen.getHeight()) {
+ height=screen.getHeight();
+ }
+ if((x+width)>screen.getWidth()) {
+ x=screen.getWidth()-width;
+ }
+ if((y+height)>screen.getHeight()) {
+ y=screen.getHeight()-height;
+ }
+
+ if(0!=surfaceHandle) {
+ SetBounds0(surfaceHandle, getScreen().getWidth(), getScreen().getHeight(), x, y, width, height);
+ }
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ if(0 != ( FLAG_IS_VISIBLE & flags)) {
+ ((DisplayDriver)getScreen().getDisplay()).setFocus(this);
+ }
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ return true;
+ }
+
+ protected void requestFocusImpl(boolean reparented) {
+ ((DisplayDriver)getScreen().getDisplay()).setFocus(this);
+ }
+
+ @Override
+ public final long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop ..
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ protected static native boolean initIDs();
+ private native long CreateSurface(long displayHandle, int scrn_width, int scrn_height, int x, int y, int width, int height);
+ private native void CloseSurface(long displayHandle, long surfaceHandle);
+ private native void SetBounds0(long surfaceHandle, int scrn_width, int scrn_height, int x, int y, int width, int height);
+
+ private void updateBounds(int x, int y, int width, int height) {
+ definePosition(x, y);
+ defineSize(width, height);
+ }
+
+ private long surfaceHandle;
+}
diff --git a/src/newt/classes/jogamp/newt/driver/kd/Display.java b/src/newt/classes/jogamp/newt/driver/kd/Display.java
deleted file mode 100644
index a58ad477a..000000000
--- a/src/newt/classes/jogamp/newt/driver/kd/Display.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2012 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.kd;
-
-import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.NativeWindowException;
-
-import jogamp.newt.DisplayImpl;
-import jogamp.newt.NEWTJNILibLoader;
-import jogamp.opengl.egl.EGL;
-import jogamp.opengl.egl.EGLDisplayUtil;
-
-public class Display extends DisplayImpl {
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if (!Window.initIDs()) {
- throw new NativeWindowException("Failed to initialize kd.Window jmethodIDs");
- }
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
-
- public Display() {
- }
-
- protected void createNativeImpl() {
- // FIXME: map name to EGL_*_DISPLAY
- aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
- }
-
- protected void closeNativeImpl() {
- aDevice.close();
- }
-
- protected void dispatchMessagesNative() {
- DispatchMessages();
- }
-
- private native void DispatchMessages();
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/kd/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/kd/DisplayDriver.java
new file mode 100644
index 000000000..745be5dae
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/kd/DisplayDriver.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.kd;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.NEWTJNILibLoader;
+import jogamp.opengl.egl.EGL;
+import jogamp.opengl.egl.EGLDisplayUtil;
+
+public class DisplayDriver extends DisplayImpl {
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if (!WindowDriver.initIDs()) {
+ throw new NativeWindowException("Failed to initialize kd.Window jmethodIDs");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ // FIXME: map name to EGL_*_DISPLAY
+ aDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+
+ protected void closeNativeImpl() {
+ aDevice.close();
+ }
+
+ protected void dispatchMessagesNative() {
+ DispatchMessages();
+ }
+
+ private native void DispatchMessages();
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/kd/Screen.java b/src/newt/classes/jogamp/newt/driver/kd/Screen.java
deleted file mode 100644
index 53f5890b2..000000000
--- a/src/newt/classes/jogamp/newt/driver/kd/Screen.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2012 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.kd;
-
-import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-import jogamp.newt.ScreenImpl;
-
-public class Screen extends ScreenImpl {
- static {
- Display.initSingleton();
- }
-
- public Screen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- }
-
- protected void closeNativeImpl() { }
-
- protected int validateScreenIndex(int idx) {
- return 0; // only one screen available
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(cachedWidth);
- virtualSize.setHeight(cachedHeight);
- }
-
- protected void sizeChanged(int w, int h) {
- cachedWidth = w;
- cachedHeight = h;
- }
-
- private static int cachedWidth = 0;
- private static int cachedHeight = 0;
-}
diff --git a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java
new file mode 100644
index 000000000..656bcf5c9
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.kd;
+
+import javax.media.nativewindow.DefaultGraphicsScreen;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.newt.ScreenImpl;
+
+public class ScreenDriver extends ScreenImpl {
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() { }
+
+ protected int validateScreenIndex(int idx) {
+ return 0; // only one screen available
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ virtualSize.setWidth(cachedWidth);
+ virtualSize.setHeight(cachedHeight);
+ }
+
+ protected void sizeChanged(int w, int h) {
+ cachedWidth = w;
+ cachedHeight = h;
+ }
+
+ private static int cachedWidth = 0;
+ private static int cachedHeight = 0;
+}
diff --git a/src/newt/classes/jogamp/newt/driver/kd/Window.java b/src/newt/classes/jogamp/newt/driver/kd/Window.java
deleted file mode 100644
index ce65040c3..000000000
--- a/src/newt/classes/jogamp/newt/driver/kd/Window.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2012 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.kd;
-
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.VisualIDHolder;
-import javax.media.nativewindow.VisualIDHolder.VIDType;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.Point;
-import javax.media.opengl.GLCapabilitiesImmutable;
-
-import jogamp.newt.WindowImpl;
-import jogamp.opengl.egl.EGLGraphicsConfiguration;
-
-public class Window extends WindowImpl {
- private static final String WINDOW_CLASS_NAME = "NewtWindow";
-
- static {
- Display.initSingleton();
- }
-
- public Window() {
- }
-
- protected void createNativeImpl() {
- if(0!=getParentWindowHandle()) {
- throw new RuntimeException("Window parenting not supported (yet)");
- }
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- setGraphicsConfiguration(cfg);
-
- GLCapabilitiesImmutable eglCaps = (GLCapabilitiesImmutable) cfg.getChosenCapabilities();
- int eglConfigID = eglCaps.getVisualID(VIDType.EGL_CONFIG);
- long eglConfig = EGLGraphicsConfiguration.EGLConfigId2EGLConfig(getDisplayHandle(), eglConfigID);
-
- eglWindowHandle = CreateWindow(getDisplayHandle(), eglConfig);
- if (eglWindowHandle == 0) {
- throw new NativeWindowException("Error creating egl window: "+cfg+", eglConfigID "+eglConfigID+", eglConfig 0x"+Long.toHexString(eglConfig));
- }
- setVisible0(eglWindowHandle, false);
- setWindowHandle(RealizeWindow(eglWindowHandle));
- if (0 == getWindowHandle()) {
- throw new NativeWindowException("Error native Window Handle is null");
- }
- windowHandleClose = eglWindowHandle;
- }
-
- protected void closeNativeImpl() {
- if(0!=windowHandleClose) {
- CloseWindow(windowHandleClose, windowUserData);
- windowUserData=0;
- }
- }
-
- protected void requestFocusImpl(boolean reparented) { }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- setVisible0(eglWindowHandle, 0 != ( FLAG_IS_VISIBLE & flags));
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- if(0!=eglWindowHandle) {
- if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
- final boolean fs = 0 != ( FLAG_IS_FULLSCREEN & flags) ;
- setFullScreen0(eglWindowHandle, fs);
- if(fs) {
- return true;
- }
- }
- // int _x=(x>=0)?x:this.x;
- // int _y=(x>=0)?y:this.y;
- width=(width>0)?width:getWidth();
- height=(height>0)?height:getHeight();
- if(width>0 || height>0) {
- setSize0(eglWindowHandle, width, height);
- }
- if(x>=0 || y>=0) {
- System.err.println("setPosition n/a in KD");
- }
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
-
- return true;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- return new Point(x,y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop ..
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- protected static native boolean initIDs();
- private native long CreateWindow(long displayHandle, long eglConfig);
- private native long RealizeWindow(long eglWindowHandle);
- private native int CloseWindow(long eglWindowHandle, long userData);
- private native void setVisible0(long eglWindowHandle, boolean visible);
- private native void setSize0(long eglWindowHandle, int width, int height);
- private native void setFullScreen0(long eglWindowHandle, boolean fullscreen);
-
- private void windowCreated(long userData) {
- windowUserData=userData;
- }
-
- @Override
- protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) {
- if(isFullscreen()) {
- ((Screen)getScreen()).sizeChanged(getWidth(), getHeight());
- }
- super.sizeChanged(defer, newWidth, newHeight, force);
- }
-
- private long eglWindowHandle;
- private long windowHandleClose;
- private long windowUserData;
-}
diff --git a/src/newt/classes/jogamp/newt/driver/kd/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/kd/WindowDriver.java
new file mode 100644
index 000000000..c733a3e94
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/kd/WindowDriver.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.kd;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.VisualIDHolder;
+import javax.media.nativewindow.VisualIDHolder.VIDType;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.Point;
+import javax.media.opengl.GLCapabilitiesImmutable;
+
+import jogamp.newt.WindowImpl;
+import jogamp.opengl.egl.EGLGraphicsConfiguration;
+
+public class WindowDriver extends WindowImpl {
+ private static final String WINDOW_CLASS_NAME = "NewtWindow";
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ }
+
+ protected void createNativeImpl() {
+ if(0!=getParentWindowHandle()) {
+ throw new RuntimeException("Window parenting not supported (yet)");
+ }
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+
+ GLCapabilitiesImmutable eglCaps = (GLCapabilitiesImmutable) cfg.getChosenCapabilities();
+ int eglConfigID = eglCaps.getVisualID(VIDType.EGL_CONFIG);
+ long eglConfig = EGLGraphicsConfiguration.EGLConfigId2EGLConfig(getDisplayHandle(), eglConfigID);
+
+ eglWindowHandle = CreateWindow(getDisplayHandle(), eglConfig);
+ if (eglWindowHandle == 0) {
+ throw new NativeWindowException("Error creating egl window: "+cfg+", eglConfigID "+eglConfigID+", eglConfig 0x"+Long.toHexString(eglConfig));
+ }
+ setVisible0(eglWindowHandle, false);
+ setWindowHandle(RealizeWindow(eglWindowHandle));
+ if (0 == getWindowHandle()) {
+ throw new NativeWindowException("Error native Window Handle is null");
+ }
+ windowHandleClose = eglWindowHandle;
+ }
+
+ protected void closeNativeImpl() {
+ if(0!=windowHandleClose) {
+ CloseWindow(windowHandleClose, windowUserData);
+ windowUserData=0;
+ }
+ }
+
+ protected void requestFocusImpl(boolean reparented) { }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ setVisible0(eglWindowHandle, 0 != ( FLAG_IS_VISIBLE & flags));
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ if(0!=eglWindowHandle) {
+ if(0 != ( FLAG_CHANGE_FULLSCREEN & flags)) {
+ final boolean fs = 0 != ( FLAG_IS_FULLSCREEN & flags) ;
+ setFullScreen0(eglWindowHandle, fs);
+ if(fs) {
+ return true;
+ }
+ }
+ // int _x=(x>=0)?x:this.x;
+ // int _y=(x>=0)?y:this.y;
+ width=(width>0)?width:getWidth();
+ height=(height>0)?height:getHeight();
+ if(width>0 || height>0) {
+ setSize0(eglWindowHandle, width, height);
+ }
+ if(x>=0 || y>=0) {
+ System.err.println("setPosition n/a in KD");
+ }
+ }
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return new Point(x,y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop ..
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ protected static native boolean initIDs();
+ private native long CreateWindow(long displayHandle, long eglConfig);
+ private native long RealizeWindow(long eglWindowHandle);
+ private native int CloseWindow(long eglWindowHandle, long userData);
+ private native void setVisible0(long eglWindowHandle, boolean visible);
+ private native void setSize0(long eglWindowHandle, int width, int height);
+ private native void setFullScreen0(long eglWindowHandle, boolean fullscreen);
+
+ private void windowCreated(long userData) {
+ windowUserData=userData;
+ }
+
+ @Override
+ protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) {
+ if(isFullscreen()) {
+ ((ScreenDriver)getScreen()).sizeChanged(getWidth(), getHeight());
+ }
+ super.sizeChanged(defer, newWidth, newHeight, force);
+ }
+
+ private long eglWindowHandle;
+ private long windowHandleClose;
+ private long windowUserData;
+}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/DisplayDriver.java
new file mode 100644
index 000000000..1a3f14859
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/macosx/DisplayDriver.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2012 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.macosx;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+
+import com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice;
+
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.NEWTJNILibLoader;
+
+public class DisplayDriver extends DisplayImpl {
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if(!initNSApplication0()) {
+ throw new NativeWindowException("Failed to initialize native Application hook");
+ }
+ if(!WindowDriver.initIDs0()) {
+ throw new NativeWindowException("Failed to initialize jmethodIDs");
+ }
+ if(DEBUG) {
+ System.err.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName());
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+ public DisplayDriver() {
+ }
+
+ protected void dispatchMessagesNative() {
+ // nop
+ }
+
+ protected void createNativeImpl() {
+ aDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+
+ protected void closeNativeImpl() { }
+
+ public static void runNSApplication() {
+ runNSApplication0();
+ }
+ public static void stopNSApplication() {
+ stopNSApplication0();
+ }
+
+ private static native boolean initNSApplication0();
+ private static native void runNSApplication0();
+ private static native void stopNSApplication0();
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java b/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java
deleted file mode 100644
index 18f8d9538..000000000
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacDisplay.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2008 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
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.macosx;
-
-import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.NativeWindowException;
-
-import com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice;
-
-import jogamp.newt.DisplayImpl;
-import jogamp.newt.NEWTJNILibLoader;
-
-public class MacDisplay extends DisplayImpl {
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if(!initNSApplication0()) {
- throw new NativeWindowException("Failed to initialize native Application hook");
- }
- if(!MacWindow.initIDs0()) {
- throw new NativeWindowException("Failed to initialize jmethodIDs");
- }
- if(DEBUG) {
- System.err.println("MacDisplay.init App and IDs OK "+Thread.currentThread().getName());
- }
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
- public MacDisplay() {
- }
-
- protected void dispatchMessagesNative() {
- // nop
- }
-
- protected void createNativeImpl() {
- aDevice = new MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
- }
-
- protected void closeNativeImpl() { }
-
- public static void runNSApplication() {
- runNSApplication0();
- }
- public static void stopNSApplication() {
- stopNSApplication0();
- }
-
- private static native boolean initNSApplication0();
- private static native void runNSApplication0();
- private static native void stopNSApplication0();
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java b/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
index 46625f7a9..d39e0027b 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/MacKeyUtil.java
@@ -1,3 +1,30 @@
+/**
+ * Copyright 2011 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 jogamp.newt.driver.macosx;
import com.jogamp.newt.event.KeyEvent;
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java b/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java
deleted file mode 100644
index b9c725fd4..000000000
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacScreen.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2011 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.macosx;
-
-import java.util.List;
-
-import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.DimensionImmutable;
-import javax.media.nativewindow.util.Point;
-
-import jogamp.newt.ScreenImpl;
-
-import com.jogamp.common.util.IntObjectHashMap;
-import com.jogamp.newt.ScreenMode;
-import com.jogamp.newt.util.ScreenModeUtil;
-
-public class MacScreen extends ScreenImpl {
-
- // caching native CGDisplayScreenSize() results, since it's ridiculous slow (~6 ms each call)
- private static IntObjectHashMap/**/ scrnIdx2Dimension;
-
- static {
- MacDisplay.initSingleton();
- scrnIdx2Dimension = new IntObjectHashMap();
- scrnIdx2Dimension.setKeyNotFoundValue(null);
- }
-
- public MacScreen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- }
-
- protected void closeNativeImpl() { }
-
- private static native int getWidthImpl0(int scrn_idx);
- private static native int getHeightImpl0(int scrn_idx);
-
- private int[] getScreenModeIdx(int idx) {
- // caching native CGDisplayScreenSize() results, since it's ridiculous slow (~6 ms each call)
- DimensionImmutable dim = (DimensionImmutable) scrnIdx2Dimension.get(screen_idx);
- if(null == dim) {
- int[] res = getScreenSizeMM0(screen_idx);
- if(null == res || 0 == res.length) {
- return null;
- }
- dim = new Dimension(res[0], res[1]);
- scrnIdx2Dimension.put(screen_idx, dim);
- }
-
- int[] modeProps = getScreenMode0(screen_idx, idx, dim.getWidth(), dim.getHeight());
- if (null == modeProps || 0 == modeProps.length) {
- return null;
- }
- if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) {
- throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length);
- }
- return modeProps;
- }
-
- private int nativeModeIdx;
-
- protected int[] getScreenModeFirstImpl() {
- nativeModeIdx = 0;
- return getScreenModeNextImpl();
- }
-
- protected int[] getScreenModeNextImpl() {
- int[] modeProps = getScreenModeIdx(nativeModeIdx);
- if (null != modeProps && 0 < modeProps.length) {
- nativeModeIdx++;
- return modeProps;
- }
- return null;
- }
-
- protected ScreenMode getCurrentScreenModeImpl() {
- int[] modeProps = getScreenModeIdx(-1);
- if (null != modeProps && 0 < modeProps.length) {
- return ScreenModeUtil.streamIn(modeProps, 0);
- }
- return null;
- }
-
- protected boolean setCurrentScreenModeImpl(final ScreenMode screenMode) {
- final List screenModes = this.getScreenModesOrig();
- final int screenModeIdx = screenModes.indexOf(screenMode);
- if(0>screenModeIdx) {
- throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode);
- }
- final int nativeModeIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx);
- return setScreenMode0(screen_idx, nativeModeIdx);
- }
-
- protected int validateScreenIndex(int idx) {
- return idx;
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(getWidthImpl0(screen_idx));
- virtualSize.setHeight(getHeightImpl0(screen_idx));
- }
-
- private native int[] getScreenSizeMM0(int screen_idx);
- private native int[] getScreenMode0(int screen_index, int mode_index, int widthMM, int heightMM);
- private native boolean setScreenMode0(int screen_index, int mode_idx);
-}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
deleted file mode 100644
index 27d7a1679..000000000
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.macosx;
-
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeWindow;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.MutableSurface;
-import javax.media.nativewindow.VisualIDHolder;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.InsetsImmutable;
-import javax.media.nativewindow.util.Point;
-import javax.media.nativewindow.util.PointImmutable;
-
-import jogamp.newt.WindowImpl;
-import jogamp.newt.driver.DriverClearFocus;
-import jogamp.newt.driver.DriverUpdatePosition;
-
-import com.jogamp.newt.event.KeyEvent;
-
-public class MacWindow extends WindowImpl implements MutableSurface, DriverClearFocus, DriverUpdatePosition {
-
- static {
- MacDisplay.initSingleton();
- }
-
- public MacWindow() {
- }
-
- @Override
- protected void createNativeImpl() {
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- setGraphicsConfiguration(cfg);
- reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY, true));
- if (0 == getWindowHandle()) {
- throw new NativeWindowException("Error creating window");
- }
- }
-
- @Override
- protected void closeNativeImpl() {
- try {
- if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.CloseAction "+Thread.currentThread().getName()); }
- final long handle = getWindowHandle();
- setWindowHandle(0);
- surfaceHandle = 0;
- sscSurfaceHandle = 0;
- isOffscreenInstance = false;
- if (0 != handle) {
- close0(handle);
- }
- } catch (Throwable t) {
- if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("Warning: closeNative failed - "+Thread.currentThread().getName(), t);
- e.printStackTrace();
- }
- }
- }
-
- @Override
- protected int lockSurfaceImpl() {
- if(!isOffscreenInstance) {
- return lockSurface0(getWindowHandle()) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY;
- }
- return LOCK_SUCCESS;
- }
-
- @Override
- protected void unlockSurfaceImpl() {
- if(!isOffscreenInstance) {
- final long h = getWindowHandle();
- if(0 != h) {
- unlockSurface0(h);
- }
- }
- }
-
- @Override
- public final long getSurfaceHandle() {
- return 0 != sscSurfaceHandle ? sscSurfaceHandle : surfaceHandle;
- }
-
- public void setSurfaceHandle(long surfaceHandle) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("MacWindow.setSurfaceHandle(): 0x"+Long.toHexString(surfaceHandle));
- }
- sscSurfaceHandle = surfaceHandle;
- if (isNativeValid()) {
- if (0 != sscSurfaceHandle) {
- orderOut0( 0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() );
- } /** this is done by recreation!
- else if (isVisible()){
- orderFront0( 0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() );
- } */
- }
- }
-
- @Override
- protected void setTitleImpl(final String title) {
- setTitle0(getWindowHandle(), title);
- }
-
- protected void requestFocusImpl(boolean force) {
- if(!isOffscreenInstance) {
- requestFocus0(getWindowHandle(), force);
- } else {
- focusChanged(false, true);
- }
- }
-
- public final void clearFocus() {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("MacWindow: clearFocus() - requestFocusParent, isOffscreenInstance "+isOffscreenInstance);
- }
- if(!isOffscreenInstance) {
- resignFocus0(getWindowHandle());
- } else {
- focusChanged(false, false);
- }
- }
-
- public void updatePosition() {
- final Point pS = getTopLevelLocationOnScreen(getX(), getY());
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("MacWindow: updatePosition() - isOffscreenInstance "+isOffscreenInstance+", new abs pos: pS "+pS);
- }
- if( !isOffscreenInstance ) {
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY());
- } // else no offscreen position
- // no native event (fullscreen, some reparenting)
- super.positionChanged(true, getX(), getY());
- }
-
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- final Point pS = getTopLevelLocationOnScreen(x, y);
- isOffscreenInstance = 0 != sscSurfaceHandle || isOffscreenInstance(this, this.getParent());
-
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+pS+" - "+width+"x"+height+
- ", offscreenInstance "+isOffscreenInstance+
- ", "+getReconfigureFlagsAsString(null, flags));
- }
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 == ( FLAG_IS_VISIBLE & flags) ) {
- if ( !isOffscreenInstance ) {
- orderOut0(getWindowHandle());
- }
- // no native event ..
- visibleChanged(true, false);
- }
- if( 0 == getWindowHandle() && 0 != ( FLAG_IS_VISIBLE & flags) ||
- 0 != ( FLAG_CHANGE_DECORATION & flags) ||
- 0 != ( FLAG_CHANGE_PARENTING & flags) ||
- 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) {
- createWindow(isOffscreenInstance, 0 != getWindowHandle(), pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags));
- if(isVisible()) { flags |= FLAG_CHANGE_VISIBILITY; }
- }
- if(x>=0 && y>=0) {
- if( !isOffscreenInstance ) {
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY());
- } // else no offscreen position
- // no native event (fullscreen, some reparenting)
- super.positionChanged(true, x, y);
- }
- if(width>0 && height>0) {
- if( !isOffscreenInstance ) {
- setContentSize0(getWindowHandle(), width, height);
- } // else offscreen size is realized via recreation
- // no native event (fullscreen, some reparenting)
- sizeChanged(true, width, height, false); // incl. validation (incl. repositioning)
- }
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 != ( FLAG_IS_VISIBLE & flags) ) {
- if( !isOffscreenInstance ) {
- orderFront0(getWindowHandle());
- }
- // no native event ..
- visibleChanged(true, true);
- }
- if( !isOffscreenInstance ) {
- setAlwaysOnTop0(getWindowHandle(), 0 != ( FLAG_IS_ALWAYSONTOP & flags));
- }
- return true;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- Point p = new Point(x, y);
- // min val is 0
- p.setX(Math.max(p.getX(), 0));
- p.setY(Math.max(p.getY(), 0));
-
- final NativeWindow parent = getParent();
- if( null != parent && 0 != parent.getWindowHandle() ) {
- p.translate(parent.getLocationOnScreen(null));
- }
- return p;
- }
-
- private Point getTopLevelLocationOnScreen(int x, int y) {
- final InsetsImmutable _insets = getInsets(); // zero if undecorated
- // client position -> top-level window position
- x -= _insets.getLeftWidth() ;
- y -= _insets.getTopHeight() ;
- return getLocationOnScreenImpl(x, y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop - using event driven insetsChange(..)
- }
-
- @Override
- protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) {
- if(getWidth() != newWidth || getHeight() != newHeight) {
- final Point p0S = getTopLevelLocationOnScreen(getX(), getY());
- setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), p0S.getX(), p0S.getY());
- }
- super.sizeChanged(defer, newWidth, newHeight, force);
- }
-
- @Override
- protected void positionChanged(boolean defer, int newX, int newY) {
- // passed coordinates are in screen position of the client area
- if(getWindowHandle()!=0) {
- // screen position -> window position
- Point absPos = new Point(newX, newY);
- final NativeWindow parent = getParent();
- if(null != parent) {
- absPos.translate( parent.getLocationOnScreen(null).scale(-1, -1) );
- }
- super.positionChanged(defer, absPos.getX(), absPos.getY());
- }
- }
-
- @Override
- protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
- if( !isOffscreenInstance ) {
- return setPointerVisible0(getWindowHandle(), hasFocus(), pointerVisible);
- } // else may need offscreen solution ? FIXME
- return false;
- }
-
- @Override
- protected boolean confinePointerImpl(final boolean confine) {
- if( !isOffscreenInstance ) {
- return confinePointer0(getWindowHandle(), confine);
- } // else may need offscreen solution ? FIXME
- return false;
- }
-
- @Override
- protected void warpPointerImpl(final int x, final int y) {
- if( !isOffscreenInstance ) {
- warpPointer0(getWindowHandle(), x, y);
- } // else may need offscreen solution ? FIXME
- }
-
- @Override
- public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- // Note that we send the key char for the key code on this
- // platform -- we do not get any useful key codes out of the system
- final int keyCode2 = MacKeyUtil.validateKeyCode(keyCode, keyChar);
- final boolean valid = validateKeyEvent(eventType, modifiers, keyCode);
- if(DEBUG_IMPLEMENTATION) System.err.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()+" char: 0x"+Integer.toHexString(keyChar)+", code 0x"+Integer.toHexString(keyCode)+" -> 0x"+Integer.toHexString(keyCode2)+", valid "+valid);
- if(valid) {
- // only deliver keyChar on key Typed events, harmonizing platform behavior
- keyChar = KeyEvent.EVENT_KEY_TYPED == eventType ? keyChar : (char)-1;
- super.sendKeyEvent(eventType, modifiers, keyCode2, keyChar);
- }
- }
-
- @Override
- public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- // Note that we send the key char for the key code on this
- // platform -- we do not get any useful key codes out of the system
- final int keyCode2 = MacKeyUtil.validateKeyCode(keyCode, keyChar);
- final boolean valid = validateKeyEvent(eventType, modifiers, keyCode);
- if(DEBUG_IMPLEMENTATION) System.err.println("MacWindow.enqueueKeyEvent "+Thread.currentThread().getName()+" char: 0x"+Integer.toHexString(keyChar)+", code 0x"+Integer.toHexString(keyCode)+" -> 0x"+Integer.toHexString(keyCode2)+", valid "+valid);
- if(valid) {
- // only deliver keyChar on key Typed events, harmonizing platform behavior
- keyChar = KeyEvent.EVENT_KEY_TYPED == eventType ? keyChar : (char)-1;
- super.enqueueKeyEvent(wait, eventType, modifiers, keyCode2, keyChar);
- }
- }
-
- private int keyDownModifiers = 0;
- private int keyDownCode = 0;
-
- private boolean validateKeyEvent(int eventType, int modifiers, int keyCode) {
- switch(eventType) {
- case KeyEvent.EVENT_KEY_PRESSED:
- keyDownModifiers = modifiers;
- keyDownCode = keyCode;
- return true;
- case KeyEvent.EVENT_KEY_RELEASED:
- return keyDownModifiers == modifiers && keyDownCode == keyCode;
- case KeyEvent.EVENT_KEY_TYPED:
- final boolean matchKeyDown = keyDownModifiers == modifiers && keyDownCode == keyCode;
- keyDownModifiers = 0;
- keyDownCode = 0;
- return matchKeyDown;
- default:
- throw new NativeWindowException("Unexpected key event type " + eventType);
- }
- }
-
-
- //----------------------------------------------------------------------
- // Internals only
- //
-
- private void createWindow(final boolean offscreenInstance, final boolean recreate,
- final PointImmutable pS, final int width, final int height,
- final boolean fullscreen) {
-
- if(0!=getWindowHandle() && !recreate) {
- return;
- }
-
- try {
- if(0!=getWindowHandle()) {
- // save the view .. close the window
- surfaceHandle = changeContentView0(getParentWindowHandle(), getWindowHandle(), 0);
- if(recreate && 0==surfaceHandle) {
- throw new NativeWindowException("Internal Error - recreate, window but no view");
- }
- close0(getWindowHandle());
- setWindowHandle(0);
- } else {
- surfaceHandle = 0;
- }
- setWindowHandle(createWindow0(getParentWindowHandle(),
- pS.getX(), pS.getY(), width, height,
- (getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance),
- fullscreen,
- ((isUndecorated() || offscreenInstance) ?
- NSBorderlessWindowMask :
- NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask),
- NSBackingStoreBuffered,
- getScreen().getIndex(), surfaceHandle));
- if (getWindowHandle() == 0) {
- throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this);
- }
- surfaceHandle = contentView0(getWindowHandle());
- if( offscreenInstance ) {
- orderOut0(0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle());
- } else {
- setTitle0(getWindowHandle(), getTitle());
- }
- } catch (Exception ie) {
- ie.printStackTrace();
- }
- }
-
- protected static native boolean initIDs0();
- private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h,
- boolean opaque, boolean fullscreen, int windowStyle,
- int backingStoreType,
- int screen_idx, long view);
- private native boolean lockSurface0(long window);
- private native void unlockSurface0(long window);
- private native void requestFocus0(long window, boolean force);
- private native void resignFocus0(long window);
- /** in case of a child window, it actually only issues orderBack(..) */
- private native void orderOut0(long window);
- private native void orderFront0(long window);
- private native void close0(long window);
- private native void setTitle0(long window, String title);
- private native long contentView0(long window);
- private native long changeContentView0(long parentWindowOrViewHandle, long window, long view);
- private native void setContentSize0(long window, int w, int h);
- private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y);
- private native void setAlwaysOnTop0(long window, boolean atop);
- private static native Object getLocationOnScreen0(long windowHandle, int src_x, int src_y);
- private static native boolean setPointerVisible0(long windowHandle, boolean hasFocus, boolean visible);
- private static native boolean confinePointer0(long windowHandle, boolean confine);
- private static native void warpPointer0(long windowHandle, int x, int y);
-
- // Window styles
- private static final int NSBorderlessWindowMask = 0;
- private static final int NSTitledWindowMask = 1 << 0;
- private static final int NSClosableWindowMask = 1 << 1;
- private static final int NSMiniaturizableWindowMask = 1 << 2;
- private static final int NSResizableWindowMask = 1 << 3;
-
- // Window backing store types
- private static final int NSBackingStoreRetained = 0;
- private static final int NSBackingStoreNonretained = 1;
- private static final int NSBackingStoreBuffered = 2;
-
- private volatile long surfaceHandle = 0;
- private long sscSurfaceHandle = 0;
- private boolean isOffscreenInstance = false;
-
-}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java
new file mode 100644
index 000000000..24e60ba0a
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 2011 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.macosx;
+
+import java.util.List;
+
+import javax.media.nativewindow.DefaultGraphicsScreen;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.newt.ScreenImpl;
+
+import com.jogamp.common.util.IntObjectHashMap;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.util.ScreenModeUtil;
+
+public class ScreenDriver extends ScreenImpl {
+
+ // caching native CGDisplayScreenSize() results, since it's ridiculous slow (~6 ms each call)
+ private static IntObjectHashMap/**/ scrnIdx2Dimension;
+
+ static {
+ DisplayDriver.initSingleton();
+ scrnIdx2Dimension = new IntObjectHashMap();
+ scrnIdx2Dimension.setKeyNotFoundValue(null);
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() { }
+
+ private static native int getWidthImpl0(int scrn_idx);
+ private static native int getHeightImpl0(int scrn_idx);
+
+ private int[] getScreenModeIdx(int idx) {
+ // caching native CGDisplayScreenSize() results, since it's ridiculous slow (~6 ms each call)
+ DimensionImmutable dim = (DimensionImmutable) scrnIdx2Dimension.get(screen_idx);
+ if(null == dim) {
+ int[] res = getScreenSizeMM0(screen_idx);
+ if(null == res || 0 == res.length) {
+ return null;
+ }
+ dim = new Dimension(res[0], res[1]);
+ scrnIdx2Dimension.put(screen_idx, dim);
+ }
+
+ int[] modeProps = getScreenMode0(screen_idx, idx, dim.getWidth(), dim.getHeight());
+ if (null == modeProps || 0 == modeProps.length) {
+ return null;
+ }
+ if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) {
+ throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length);
+ }
+ return modeProps;
+ }
+
+ private int nativeModeIdx;
+
+ protected int[] getScreenModeFirstImpl() {
+ nativeModeIdx = 0;
+ return getScreenModeNextImpl();
+ }
+
+ protected int[] getScreenModeNextImpl() {
+ int[] modeProps = getScreenModeIdx(nativeModeIdx);
+ if (null != modeProps && 0 < modeProps.length) {
+ nativeModeIdx++;
+ return modeProps;
+ }
+ return null;
+ }
+
+ protected ScreenMode getCurrentScreenModeImpl() {
+ int[] modeProps = getScreenModeIdx(-1);
+ if (null != modeProps && 0 < modeProps.length) {
+ return ScreenModeUtil.streamIn(modeProps, 0);
+ }
+ return null;
+ }
+
+ protected boolean setCurrentScreenModeImpl(final ScreenMode screenMode) {
+ final List screenModes = this.getScreenModesOrig();
+ final int screenModeIdx = screenModes.indexOf(screenMode);
+ if(0>screenModeIdx) {
+ throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode);
+ }
+ final int nativeModeIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx);
+ return setScreenMode0(screen_idx, nativeModeIdx);
+ }
+
+ protected int validateScreenIndex(int idx) {
+ return idx;
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(0);
+ virtualOrigin.setY(0);
+ virtualSize.setWidth(getWidthImpl0(screen_idx));
+ virtualSize.setHeight(getHeightImpl0(screen_idx));
+ }
+
+ private native int[] getScreenSizeMM0(int screen_idx);
+ private native int[] getScreenMode0(int screen_index, int mode_index, int widthMM, int heightMM);
+ private native boolean setScreenMode0(int screen_index, int mode_idx);
+}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
new file mode 100644
index 000000000..ea48569bf
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
@@ -0,0 +1,431 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.macosx;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.MutableSurface;
+import javax.media.nativewindow.VisualIDHolder;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.InsetsImmutable;
+import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.PointImmutable;
+
+import jogamp.newt.WindowImpl;
+import jogamp.newt.driver.DriverClearFocus;
+import jogamp.newt.driver.DriverUpdatePosition;
+
+import com.jogamp.newt.event.KeyEvent;
+
+public class WindowDriver extends WindowImpl implements MutableSurface, DriverClearFocus, DriverUpdatePosition {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ }
+
+ @Override
+ protected void createNativeImpl() {
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+ reconfigureWindowImpl(getX(), getY(), getWidth(), getHeight(), getReconfigureFlags(FLAG_CHANGE_VISIBILITY, true));
+ if (0 == getWindowHandle()) {
+ throw new NativeWindowException("Error creating window");
+ }
+ }
+
+ @Override
+ protected void closeNativeImpl() {
+ try {
+ if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.CloseAction "+Thread.currentThread().getName()); }
+ final long handle = getWindowHandle();
+ setWindowHandle(0);
+ surfaceHandle = 0;
+ sscSurfaceHandle = 0;
+ isOffscreenInstance = false;
+ if (0 != handle) {
+ close0(handle);
+ }
+ } catch (Throwable t) {
+ if(DEBUG_IMPLEMENTATION) {
+ Exception e = new Exception("Warning: closeNative failed - "+Thread.currentThread().getName(), t);
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ protected int lockSurfaceImpl() {
+ if(!isOffscreenInstance) {
+ return lockSurface0(getWindowHandle()) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY;
+ }
+ return LOCK_SUCCESS;
+ }
+
+ @Override
+ protected void unlockSurfaceImpl() {
+ if(!isOffscreenInstance) {
+ final long h = getWindowHandle();
+ if(0 != h) {
+ unlockSurface0(h);
+ }
+ }
+ }
+
+ @Override
+ public final long getSurfaceHandle() {
+ return 0 != sscSurfaceHandle ? sscSurfaceHandle : surfaceHandle;
+ }
+
+ public void setSurfaceHandle(long surfaceHandle) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow.setSurfaceHandle(): 0x"+Long.toHexString(surfaceHandle));
+ }
+ sscSurfaceHandle = surfaceHandle;
+ if (isNativeValid()) {
+ if (0 != sscSurfaceHandle) {
+ orderOut0( 0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() );
+ } /** this is done by recreation!
+ else if (isVisible()){
+ orderFront0( 0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() );
+ } */
+ }
+ }
+
+ @Override
+ protected void setTitleImpl(final String title) {
+ setTitle0(getWindowHandle(), title);
+ }
+
+ protected void requestFocusImpl(boolean force) {
+ if(!isOffscreenInstance) {
+ requestFocus0(getWindowHandle(), force);
+ } else {
+ focusChanged(false, true);
+ }
+ }
+
+ public final void clearFocus() {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow: clearFocus() - requestFocusParent, isOffscreenInstance "+isOffscreenInstance);
+ }
+ if(!isOffscreenInstance) {
+ resignFocus0(getWindowHandle());
+ } else {
+ focusChanged(false, false);
+ }
+ }
+
+ public void updatePosition() {
+ final Point pS = getTopLevelLocationOnScreen(getX(), getY());
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow: updatePosition() - isOffscreenInstance "+isOffscreenInstance+", new abs pos: pS "+pS);
+ }
+ if( !isOffscreenInstance ) {
+ setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY());
+ } // else no offscreen position
+ // no native event (fullscreen, some reparenting)
+ super.positionChanged(true, getX(), getY());
+ }
+
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ final Point pS = getTopLevelLocationOnScreen(x, y);
+ isOffscreenInstance = 0 != sscSurfaceHandle || isOffscreenInstance(this, this.getParent());
+
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+pS+" - "+width+"x"+height+
+ ", offscreenInstance "+isOffscreenInstance+
+ ", "+getReconfigureFlagsAsString(null, flags));
+ }
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 == ( FLAG_IS_VISIBLE & flags) ) {
+ if ( !isOffscreenInstance ) {
+ orderOut0(getWindowHandle());
+ }
+ // no native event ..
+ visibleChanged(true, false);
+ }
+ if( 0 == getWindowHandle() && 0 != ( FLAG_IS_VISIBLE & flags) ||
+ 0 != ( FLAG_CHANGE_DECORATION & flags) ||
+ 0 != ( FLAG_CHANGE_PARENTING & flags) ||
+ 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) {
+ createWindow(isOffscreenInstance, 0 != getWindowHandle(), pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags));
+ if(isVisible()) { flags |= FLAG_CHANGE_VISIBILITY; }
+ }
+ if(x>=0 && y>=0) {
+ if( !isOffscreenInstance ) {
+ setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY());
+ } // else no offscreen position
+ // no native event (fullscreen, some reparenting)
+ super.positionChanged(true, x, y);
+ }
+ if(width>0 && height>0) {
+ if( !isOffscreenInstance ) {
+ setContentSize0(getWindowHandle(), width, height);
+ } // else offscreen size is realized via recreation
+ // no native event (fullscreen, some reparenting)
+ sizeChanged(true, width, height, false); // incl. validation (incl. repositioning)
+ }
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 != ( FLAG_IS_VISIBLE & flags) ) {
+ if( !isOffscreenInstance ) {
+ orderFront0(getWindowHandle());
+ }
+ // no native event ..
+ visibleChanged(true, true);
+ }
+ if( !isOffscreenInstance ) {
+ setAlwaysOnTop0(getWindowHandle(), 0 != ( FLAG_IS_ALWAYSONTOP & flags));
+ }
+ return true;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ Point p = new Point(x, y);
+ // min val is 0
+ p.setX(Math.max(p.getX(), 0));
+ p.setY(Math.max(p.getY(), 0));
+
+ final NativeWindow parent = getParent();
+ if( null != parent && 0 != parent.getWindowHandle() ) {
+ p.translate(parent.getLocationOnScreen(null));
+ }
+ return p;
+ }
+
+ private Point getTopLevelLocationOnScreen(int x, int y) {
+ final InsetsImmutable _insets = getInsets(); // zero if undecorated
+ // client position -> top-level window position
+ x -= _insets.getLeftWidth() ;
+ y -= _insets.getTopHeight() ;
+ return getLocationOnScreenImpl(x, y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop - using event driven insetsChange(..)
+ }
+
+ @Override
+ protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) {
+ if(getWidth() != newWidth || getHeight() != newHeight) {
+ final Point p0S = getTopLevelLocationOnScreen(getX(), getY());
+ setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), p0S.getX(), p0S.getY());
+ }
+ super.sizeChanged(defer, newWidth, newHeight, force);
+ }
+
+ @Override
+ protected void positionChanged(boolean defer, int newX, int newY) {
+ // passed coordinates are in screen position of the client area
+ if(getWindowHandle()!=0) {
+ // screen position -> window position
+ Point absPos = new Point(newX, newY);
+ final NativeWindow parent = getParent();
+ if(null != parent) {
+ absPos.translate( parent.getLocationOnScreen(null).scale(-1, -1) );
+ }
+ super.positionChanged(defer, absPos.getX(), absPos.getY());
+ }
+ }
+
+ @Override
+ protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
+ if( !isOffscreenInstance ) {
+ return setPointerVisible0(getWindowHandle(), hasFocus(), pointerVisible);
+ } // else may need offscreen solution ? FIXME
+ return false;
+ }
+
+ @Override
+ protected boolean confinePointerImpl(final boolean confine) {
+ if( !isOffscreenInstance ) {
+ return confinePointer0(getWindowHandle(), confine);
+ } // else may need offscreen solution ? FIXME
+ return false;
+ }
+
+ @Override
+ protected void warpPointerImpl(final int x, final int y) {
+ if( !isOffscreenInstance ) {
+ warpPointer0(getWindowHandle(), x, y);
+ } // else may need offscreen solution ? FIXME
+ }
+
+ @Override
+ public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
+ // Note that we send the key char for the key code on this
+ // platform -- we do not get any useful key codes out of the system
+ final int keyCode2 = MacKeyUtil.validateKeyCode(keyCode, keyChar);
+ final boolean valid = validateKeyEvent(eventType, modifiers, keyCode);
+ if(DEBUG_IMPLEMENTATION) System.err.println("MacWindow.sendKeyEvent "+Thread.currentThread().getName()+" char: 0x"+Integer.toHexString(keyChar)+", code 0x"+Integer.toHexString(keyCode)+" -> 0x"+Integer.toHexString(keyCode2)+", valid "+valid);
+ if(valid) {
+ // only deliver keyChar on key Typed events, harmonizing platform behavior
+ keyChar = KeyEvent.EVENT_KEY_TYPED == eventType ? keyChar : (char)-1;
+ super.sendKeyEvent(eventType, modifiers, keyCode2, keyChar);
+ }
+ }
+
+ @Override
+ public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
+ // Note that we send the key char for the key code on this
+ // platform -- we do not get any useful key codes out of the system
+ final int keyCode2 = MacKeyUtil.validateKeyCode(keyCode, keyChar);
+ final boolean valid = validateKeyEvent(eventType, modifiers, keyCode);
+ if(DEBUG_IMPLEMENTATION) System.err.println("MacWindow.enqueueKeyEvent "+Thread.currentThread().getName()+" char: 0x"+Integer.toHexString(keyChar)+", code 0x"+Integer.toHexString(keyCode)+" -> 0x"+Integer.toHexString(keyCode2)+", valid "+valid);
+ if(valid) {
+ // only deliver keyChar on key Typed events, harmonizing platform behavior
+ keyChar = KeyEvent.EVENT_KEY_TYPED == eventType ? keyChar : (char)-1;
+ super.enqueueKeyEvent(wait, eventType, modifiers, keyCode2, keyChar);
+ }
+ }
+
+ private int keyDownModifiers = 0;
+ private int keyDownCode = 0;
+
+ private boolean validateKeyEvent(int eventType, int modifiers, int keyCode) {
+ switch(eventType) {
+ case KeyEvent.EVENT_KEY_PRESSED:
+ keyDownModifiers = modifiers;
+ keyDownCode = keyCode;
+ return true;
+ case KeyEvent.EVENT_KEY_RELEASED:
+ return keyDownModifiers == modifiers && keyDownCode == keyCode;
+ case KeyEvent.EVENT_KEY_TYPED:
+ final boolean matchKeyDown = keyDownModifiers == modifiers && keyDownCode == keyCode;
+ keyDownModifiers = 0;
+ keyDownCode = 0;
+ return matchKeyDown;
+ default:
+ throw new NativeWindowException("Unexpected key event type " + eventType);
+ }
+ }
+
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ private void createWindow(final boolean offscreenInstance, final boolean recreate,
+ final PointImmutable pS, final int width, final int height,
+ final boolean fullscreen) {
+
+ if(0!=getWindowHandle() && !recreate) {
+ return;
+ }
+
+ try {
+ if(0!=getWindowHandle()) {
+ // save the view .. close the window
+ surfaceHandle = changeContentView0(getParentWindowHandle(), getWindowHandle(), 0);
+ if(recreate && 0==surfaceHandle) {
+ throw new NativeWindowException("Internal Error - recreate, window but no view");
+ }
+ close0(getWindowHandle());
+ setWindowHandle(0);
+ } else {
+ surfaceHandle = 0;
+ }
+ setWindowHandle(createWindow0(getParentWindowHandle(),
+ pS.getX(), pS.getY(), width, height,
+ (getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance),
+ fullscreen,
+ ((isUndecorated() || offscreenInstance) ?
+ NSBorderlessWindowMask :
+ NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask),
+ NSBackingStoreBuffered,
+ getScreen().getIndex(), surfaceHandle));
+ if (getWindowHandle() == 0) {
+ throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this);
+ }
+ surfaceHandle = contentView0(getWindowHandle());
+ if( offscreenInstance ) {
+ orderOut0(0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle());
+ } else {
+ setTitle0(getWindowHandle(), getTitle());
+ }
+ } catch (Exception ie) {
+ ie.printStackTrace();
+ }
+ }
+
+ protected static native boolean initIDs0();
+ private native long createWindow0(long parentWindowHandle, int x, int y, int w, int h,
+ boolean opaque, boolean fullscreen, int windowStyle,
+ int backingStoreType,
+ int screen_idx, long view);
+ private native boolean lockSurface0(long window);
+ private native void unlockSurface0(long window);
+ private native void requestFocus0(long window, boolean force);
+ private native void resignFocus0(long window);
+ /** in case of a child window, it actually only issues orderBack(..) */
+ private native void orderOut0(long window);
+ private native void orderFront0(long window);
+ private native void close0(long window);
+ private native void setTitle0(long window, String title);
+ private native long contentView0(long window);
+ private native long changeContentView0(long parentWindowOrViewHandle, long window, long view);
+ private native void setContentSize0(long window, int w, int h);
+ private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y);
+ private native void setAlwaysOnTop0(long window, boolean atop);
+ private static native Object getLocationOnScreen0(long windowHandle, int src_x, int src_y);
+ private static native boolean setPointerVisible0(long windowHandle, boolean hasFocus, boolean visible);
+ private static native boolean confinePointer0(long windowHandle, boolean confine);
+ private static native void warpPointer0(long windowHandle, int x, int y);
+
+ // Window styles
+ private static final int NSBorderlessWindowMask = 0;
+ private static final int NSTitledWindowMask = 1 << 0;
+ private static final int NSClosableWindowMask = 1 << 1;
+ private static final int NSMiniaturizableWindowMask = 1 << 2;
+ private static final int NSResizableWindowMask = 1 << 3;
+
+ // Window backing store types
+ private static final int NSBackingStoreRetained = 0;
+ private static final int NSBackingStoreNonretained = 1;
+ private static final int NSBackingStoreBuffered = 2;
+
+ private volatile long surfaceHandle = 0;
+ private long sscSurfaceHandle = 0;
+ private boolean isOffscreenInstance = false;
+
+}
diff --git a/src/newt/classes/jogamp/newt/driver/windows/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/windows/DisplayDriver.java
new file mode 100644
index 000000000..579ec5be8
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/windows/DisplayDriver.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.windows;
+
+import jogamp.nativewindow.windows.RegisteredClass;
+import jogamp.nativewindow.windows.RegisteredClassFactory;
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.NEWTJNILibLoader;
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+
+import com.jogamp.nativewindow.windows.WindowsGraphicsDevice;
+
+public class DisplayDriver extends DisplayImpl {
+
+ private static final String newtClassBaseName = "_newt_clazz" ;
+ private static RegisteredClassFactory sharedClassFactory;
+
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if (!WindowDriver.initIDs0()) {
+ throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs");
+ }
+ sharedClassFactory = new RegisteredClassFactory(newtClassBaseName, WindowDriver.getNewtWndProc0());
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+ private RegisteredClass sharedClass;
+
+ public DisplayDriver() {
+ }
+
+ protected void createNativeImpl() {
+ sharedClass = sharedClassFactory.getSharedClass();
+ aDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ }
+
+ protected void closeNativeImpl() {
+ sharedClassFactory.releaseSharedClass();
+ }
+
+ protected void dispatchMessagesNative() {
+ DispatchMessages0();
+ }
+
+ protected long getHInstance() {
+ return sharedClass.getHandle();
+ }
+
+ protected String getWindowClassName() {
+ return sharedClass.getName();
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ private static native void DispatchMessages0();
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
new file mode 100644
index 000000000..948b29460
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+package jogamp.newt.driver.windows;
+
+import javax.media.nativewindow.DefaultGraphicsScreen;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.newt.ScreenImpl;
+
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.util.ScreenModeUtil;
+
+public class ScreenDriver extends ScreenImpl {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() {
+ }
+
+ private int[] getScreenModeIdx(int idx) {
+ int[] modeProps = getScreenMode0(screen_idx, idx);
+ if (null == modeProps || 0 == modeProps.length) {
+ return null;
+ }
+ if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) {
+ throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length);
+ }
+ return modeProps;
+ }
+
+ private int nativeModeIdx;
+
+ protected int[] getScreenModeFirstImpl() {
+ nativeModeIdx = 0;
+ return getScreenModeNextImpl();
+ }
+
+ protected int[] getScreenModeNextImpl() {
+ int[] modeProps = getScreenModeIdx(nativeModeIdx);
+ if (null != modeProps && 0 < modeProps.length) {
+ nativeModeIdx++;
+ return modeProps;
+ }
+ return null;
+ }
+
+ protected ScreenMode getCurrentScreenModeImpl() {
+ int[] modeProps = getScreenModeIdx(-1);
+ if (null != modeProps && 0 < modeProps.length) {
+ return ScreenModeUtil.streamIn(modeProps, 0);
+ }
+ return null;
+ }
+
+ protected boolean setCurrentScreenModeImpl(ScreenMode sm) {
+ return setScreenMode0(screen_idx,
+ sm.getMonitorMode().getSurfaceSize().getResolution().getWidth(),
+ sm.getMonitorMode().getSurfaceSize().getResolution().getHeight(),
+ sm.getMonitorMode().getSurfaceSize().getBitsPerPixel(),
+ sm.getMonitorMode().getRefreshRate(),
+ sm.getRotation());
+ }
+
+ protected int validateScreenIndex(int idx) {
+ return 0; // big-desktop, only one screen available
+ }
+
+ protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
+ virtualOrigin.setX(getOriginX0(screen_idx));
+ virtualOrigin.setY(getOriginY0(screen_idx));
+ virtualSize.setWidth(getWidthImpl0(screen_idx));
+ virtualSize.setHeight(getHeightImpl0(screen_idx));
+ }
+
+ // Native calls
+ private native int getOriginX0(int screen_idx);
+ private native int getOriginY0(int screen_idx);
+ private native int getWidthImpl0(int scrn_idx);
+ private native int getHeightImpl0(int scrn_idx);
+
+ private native int[] getScreenMode0(int screen_index, int mode_index);
+ private native boolean setScreenMode0(int screen_index, int width, int height, int bits, int freq, int rot);
+}
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
new file mode 100644
index 000000000..39ea54575
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/windows/WindowDriver.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.windows;
+
+import jogamp.nativewindow.windows.GDI;
+import jogamp.nativewindow.windows.GDIUtil;
+import jogamp.newt.WindowImpl;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.GraphicsConfigurationFactory;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.VisualIDHolder;
+import javax.media.nativewindow.util.Insets;
+import javax.media.nativewindow.util.InsetsImmutable;
+import javax.media.nativewindow.util.Point;
+
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.MouseAdapter;
+import com.jogamp.newt.event.MouseEvent;
+
+public class WindowDriver extends WindowImpl {
+
+ private long hmon;
+ private long hdc;
+ private long hdc_old;
+ private long windowHandleClose;
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public WindowDriver() {
+ }
+
+ @Override
+ protected int lockSurfaceImpl() {
+ if (0 != hdc) {
+ throw new InternalError("surface not released");
+ }
+ hdc = GDI.GetDC(getWindowHandle());
+ hmon = MonitorFromWindow0(getWindowHandle());
+
+ // return ( 0 == hdc ) ? LOCK_SURFACE_NOT_READY : ( hdc_old != hdc ) ? LOCK_SURFACE_CHANGED : LOCK_SUCCESS ;
+ if( 0 == hdc ) {
+ return LOCK_SURFACE_NOT_READY;
+ }
+ if( hdc_old == hdc ) {
+ return LOCK_SUCCESS;
+ }
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("WindowsWindow: surface change "+toHexString(hdc_old)+" -> "+toHexString(hdc));
+ // Thread.dumpStack();
+ }
+ return LOCK_SURFACE_CHANGED;
+ }
+
+ @Override
+ protected void unlockSurfaceImpl() {
+ if (0 != hdc) {
+ GDI.ReleaseDC(getWindowHandle(), hdc);
+ hdc_old = hdc;
+ hdc=0;
+ }
+ }
+
+ @Override
+ public final long getSurfaceHandle() {
+ return hdc;
+ }
+
+ @Override
+ public boolean hasDeviceChanged() {
+ if(0!=getWindowHandle()) {
+ long _hmon = MonitorFromWindow0(getWindowHandle());
+ if (hmon != _hmon) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("Info: Window Device Changed "+Thread.currentThread().getName()+
+ ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon));
+ // Thread.dumpStack();
+ }
+ hmon = _hmon;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void createNativeImpl() {
+ final ScreenDriver screen = (ScreenDriver) getScreen();
+ final DisplayDriver display = (DisplayDriver) screen.getDisplay();
+ final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
+ capsRequested, capsRequested, capabilitiesChooser, screen.getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
+ if (null == cfg) {
+ throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
+ }
+ setGraphicsConfiguration(cfg);
+ final int flags = getReconfigureFlags(0, true) &
+ ( FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED ) ;
+ setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(),
+ getParentWindowHandle(), getX(), getY(), getWidth(), getHeight(), autoPosition(), flags));
+ if (getWindowHandle() == 0) {
+ throw new NativeWindowException("Error creating window");
+ }
+ windowHandleClose = getWindowHandle();
+ addMouseListener(new MouseTracker());
+
+ if(DEBUG_IMPLEMENTATION) {
+ Exception e = new Exception("Info: Window new window handle "+Thread.currentThread().getName()+
+ " (Parent HWND "+toHexString(getParentWindowHandle())+
+ ") : HWND "+toHexString(getWindowHandle())+", "+Thread.currentThread());
+ e.printStackTrace();
+ }
+ }
+
+ class MouseTracker extends MouseAdapter {
+ public void mouseEntered(MouseEvent e) {
+ WindowDriver.trackPointerLeave0(WindowDriver.this.getWindowHandle());
+ }
+ }
+
+ protected void closeNativeImpl() {
+ if(windowHandleClose != 0) {
+ if (hdc != 0) {
+ try {
+ GDI.ReleaseDC(windowHandleClose, hdc);
+ } catch (Throwable t) {
+ if(DEBUG_IMPLEMENTATION) {
+ Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
+ e.printStackTrace();
+ }
+ }
+ }
+ try {
+ GDI.SetParent(windowHandleClose, 0); // detach first, experience hang w/ SWT parent
+ GDI.DestroyWindow(windowHandleClose);
+ } catch (Throwable t) {
+ if(DEBUG_IMPLEMENTATION) {
+ Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
+ e.printStackTrace();
+ }
+ } finally {
+ windowHandleClose = 0;
+ }
+ }
+ hdc = 0;
+ hdc_old = 0;
+ }
+
+ protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
+ if(DEBUG_IMPLEMENTATION) {
+ System.err.println("WindowsWindow reconfig: "+x+"/"+y+" "+width+"x"+height+", "+
+ getReconfigureFlagsAsString(null, flags));
+ }
+
+ if(0 == ( FLAG_IS_UNDECORATED & flags)) {
+ final InsetsImmutable i = getInsets();
+
+ // client position -> top-level window position
+ x -= i.getLeftWidth() ;
+ y -= i.getTopHeight() ;
+
+ if(0 top-level window size
+ width += i.getTotalWidth();
+ height += i.getTotalHeight();
+ }
+ }
+ reconfigureWindow0( getParentWindowHandle(), getWindowHandle(), x, y, width, height, flags);
+
+ if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
+ visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
+ }
+ return true;
+ }
+
+ protected void requestFocusImpl(boolean force) {
+ requestFocus0(getWindowHandle(), force);
+ }
+
+ @Override
+ protected void setTitleImpl(final String title) {
+ setTitle0(getWindowHandle(), title);
+ }
+
+ @Override
+ protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
+ final Boolean[] res = new Boolean[] { Boolean.FALSE };
+
+ this.runOnEDTIfAvail(true, new Runnable() {
+ public void run() {
+ res[0] = Boolean.valueOf(setPointerVisible0(getWindowHandle(), pointerVisible));
+ }
+ });
+ return res[0].booleanValue();
+ }
+
+ @Override
+ protected boolean confinePointerImpl(final boolean confine) {
+ final Boolean[] res = new Boolean[] { Boolean.FALSE };
+
+ this.runOnEDTIfAvail(true, new Runnable() {
+ public void run() {
+ final Point p0 = getLocationOnScreenImpl(0, 0);
+ res[0] = Boolean.valueOf(confinePointer0(getWindowHandle(), confine,
+ p0.getX(), p0.getY(), p0.getX()+getWidth(), p0.getY()+getHeight()));
+ }
+ });
+ return res[0].booleanValue();
+ }
+
+ @Override
+ protected void warpPointerImpl(final int x, final int y) {
+ this.runOnEDTIfAvail(true, new Runnable() {
+ public void run() {
+ final Point sPos = getLocationOnScreenImpl(x, y);
+ warpPointer0(getWindowHandle(), sPos.getX(), sPos.getY());
+ }
+ });
+ return;
+ }
+
+ protected Point getLocationOnScreenImpl(int x, int y) {
+ return GDIUtil.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y);
+ }
+
+ protected void updateInsetsImpl(Insets insets) {
+ // nop - using event driven insetsChange(..)
+ }
+
+ private final int validateKeyCode(int eventType, int keyCode) {
+ switch(eventType) {
+ case KeyEvent.EVENT_KEY_PRESSED:
+ lastPressedKeyCode = keyCode;
+ break;
+ case KeyEvent.EVENT_KEY_TYPED:
+ if(-1==keyCode) {
+ keyCode = lastPressedKeyCode;
+ }
+ lastPressedKeyCode = -1;
+ break;
+ }
+ return keyCode;
+ }
+ private int lastPressedKeyCode = 0;
+
+ @Override
+ public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
+ // Note that we have to regenerate the keyCode for EVENT_KEY_TYPED on this platform
+ keyCode = validateKeyCode(eventType, keyCode);
+ super.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
+ }
+
+ @Override
+ public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
+ // Note that we have to regenerate the keyCode for EVENT_KEY_TYPED on this platform
+ keyCode = validateKeyCode(eventType, keyCode);
+ super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keyChar);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ protected static native boolean initIDs0();
+ protected static native long getNewtWndProc0();
+
+ private native long CreateWindow0(long hInstance, String wndClassName, String wndName,
+ long parentWindowHandle,
+ int x, int y, int width, int height, boolean autoPosition, int flags);
+ private native long MonitorFromWindow0(long windowHandle);
+ private native void reconfigureWindow0(long parentWindowHandle, long windowHandle,
+ int x, int y, int width, int height, int flags);
+ private static native void setTitle0(long windowHandle, String title);
+ private native void requestFocus0(long windowHandle, boolean force);
+
+ private static native boolean setPointerVisible0(long windowHandle, boolean visible);
+ private static native boolean confinePointer0(long windowHandle, boolean grab, int l, int t, int r, int b);
+ private static native void warpPointer0(long windowHandle, int x, int y);
+ private static native void trackPointerLeave0(long windowHandle);
+}
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsDisplay.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsDisplay.java
deleted file mode 100644
index 225b115e4..000000000
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowsDisplay.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.windows;
-
-import jogamp.nativewindow.windows.RegisteredClass;
-import jogamp.nativewindow.windows.RegisteredClassFactory;
-import jogamp.newt.DisplayImpl;
-import jogamp.newt.NEWTJNILibLoader;
-import javax.media.nativewindow.AbstractGraphicsDevice;
-import javax.media.nativewindow.NativeWindowException;
-
-import com.jogamp.nativewindow.windows.WindowsGraphicsDevice;
-
-public class WindowsDisplay extends DisplayImpl {
-
- private static final String newtClassBaseName = "_newt_clazz" ;
- private static RegisteredClassFactory sharedClassFactory;
-
- static {
- NEWTJNILibLoader.loadNEWT();
-
- if (!WindowsWindow.initIDs0()) {
- throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs");
- }
- sharedClassFactory = new RegisteredClassFactory(newtClassBaseName, WindowsWindow.getNewtWndProc0());
- }
-
- public static void initSingleton() {
- // just exist to ensure static init has been run
- }
-
- private RegisteredClass sharedClass;
-
- public WindowsDisplay() {
- }
-
- protected void createNativeImpl() {
- sharedClass = sharedClassFactory.getSharedClass();
- aDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
- }
-
- protected void closeNativeImpl() {
- sharedClassFactory.releaseSharedClass();
- }
-
- protected void dispatchMessagesNative() {
- DispatchMessages0();
- }
-
- protected long getHInstance() {
- return sharedClass.getHandle();
- }
-
- protected String getWindowClassName() {
- return sharedClass.getName();
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
- private static native void DispatchMessages0();
-}
-
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java
deleted file mode 100644
index f8bce9da3..000000000
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowsScreen.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-package jogamp.newt.driver.windows;
-
-import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
-
-import jogamp.newt.ScreenImpl;
-
-import com.jogamp.newt.ScreenMode;
-import com.jogamp.newt.util.ScreenModeUtil;
-
-public class WindowsScreen extends ScreenImpl {
-
- static {
- WindowsDisplay.initSingleton();
- }
-
- public WindowsScreen() {
- }
-
- protected void createNativeImpl() {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
- }
-
- protected void closeNativeImpl() {
- }
-
- private int[] getScreenModeIdx(int idx) {
- int[] modeProps = getScreenMode0(screen_idx, idx);
- if (null == modeProps || 0 == modeProps.length) {
- return null;
- }
- if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) {
- throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length);
- }
- return modeProps;
- }
-
- private int nativeModeIdx;
-
- protected int[] getScreenModeFirstImpl() {
- nativeModeIdx = 0;
- return getScreenModeNextImpl();
- }
-
- protected int[] getScreenModeNextImpl() {
- int[] modeProps = getScreenModeIdx(nativeModeIdx);
- if (null != modeProps && 0 < modeProps.length) {
- nativeModeIdx++;
- return modeProps;
- }
- return null;
- }
-
- protected ScreenMode getCurrentScreenModeImpl() {
- int[] modeProps = getScreenModeIdx(-1);
- if (null != modeProps && 0 < modeProps.length) {
- return ScreenModeUtil.streamIn(modeProps, 0);
- }
- return null;
- }
-
- protected boolean setCurrentScreenModeImpl(ScreenMode sm) {
- return setScreenMode0(screen_idx,
- sm.getMonitorMode().getSurfaceSize().getResolution().getWidth(),
- sm.getMonitorMode().getSurfaceSize().getResolution().getHeight(),
- sm.getMonitorMode().getSurfaceSize().getBitsPerPixel(),
- sm.getMonitorMode().getRefreshRate(),
- sm.getRotation());
- }
-
- protected int validateScreenIndex(int idx) {
- return 0; // big-desktop, only one screen available
- }
-
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(getOriginX0(screen_idx));
- virtualOrigin.setY(getOriginY0(screen_idx));
- virtualSize.setWidth(getWidthImpl0(screen_idx));
- virtualSize.setHeight(getHeightImpl0(screen_idx));
- }
-
- // Native calls
- private native int getOriginX0(int screen_idx);
- private native int getOriginY0(int screen_idx);
- private native int getWidthImpl0(int scrn_idx);
- private native int getHeightImpl0(int scrn_idx);
-
- private native int[] getScreenMode0(int screen_index, int mode_index);
- private native boolean setScreenMode0(int screen_index, int width, int height, int bits, int freq, int rot);
-}
diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
deleted file mode 100644
index 6a8c81f3d..000000000
--- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 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:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution 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.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package jogamp.newt.driver.windows;
-
-import jogamp.nativewindow.windows.GDI;
-import jogamp.nativewindow.windows.GDIUtil;
-import jogamp.newt.WindowImpl;
-
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.GraphicsConfigurationFactory;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.VisualIDHolder;
-import javax.media.nativewindow.util.Insets;
-import javax.media.nativewindow.util.InsetsImmutable;
-import javax.media.nativewindow.util.Point;
-
-import com.jogamp.newt.event.KeyEvent;
-import com.jogamp.newt.event.MouseAdapter;
-import com.jogamp.newt.event.MouseEvent;
-
-public class WindowsWindow extends WindowImpl {
-
- private long hmon;
- private long hdc;
- private long hdc_old;
- private long windowHandleClose;
-
- static {
- WindowsDisplay.initSingleton();
- }
-
- public WindowsWindow() {
- }
-
- @Override
- protected int lockSurfaceImpl() {
- if (0 != hdc) {
- throw new InternalError("surface not released");
- }
- hdc = GDI.GetDC(getWindowHandle());
- hmon = MonitorFromWindow0(getWindowHandle());
-
- // return ( 0 == hdc ) ? LOCK_SURFACE_NOT_READY : ( hdc_old != hdc ) ? LOCK_SURFACE_CHANGED : LOCK_SUCCESS ;
- if( 0 == hdc ) {
- return LOCK_SURFACE_NOT_READY;
- }
- if( hdc_old == hdc ) {
- return LOCK_SUCCESS;
- }
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("WindowsWindow: surface change "+toHexString(hdc_old)+" -> "+toHexString(hdc));
- // Thread.dumpStack();
- }
- return LOCK_SURFACE_CHANGED;
- }
-
- @Override
- protected void unlockSurfaceImpl() {
- if (0 != hdc) {
- GDI.ReleaseDC(getWindowHandle(), hdc);
- hdc_old = hdc;
- hdc=0;
- }
- }
-
- @Override
- public final long getSurfaceHandle() {
- return hdc;
- }
-
- @Override
- public boolean hasDeviceChanged() {
- if(0!=getWindowHandle()) {
- long _hmon = MonitorFromWindow0(getWindowHandle());
- if (hmon != _hmon) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("Info: Window Device Changed "+Thread.currentThread().getName()+
- ", HMON "+toHexString(hmon)+" -> "+toHexString(_hmon));
- // Thread.dumpStack();
- }
- hmon = _hmon;
- return true;
- }
- }
- return false;
- }
-
- protected void createNativeImpl() {
- final WindowsScreen screen = (WindowsScreen) getScreen();
- final WindowsDisplay display = (WindowsDisplay) screen.getDisplay();
- final AbstractGraphicsConfiguration cfg = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested).chooseGraphicsConfiguration(
- capsRequested, capsRequested, capabilitiesChooser, screen.getGraphicsScreen(), VisualIDHolder.VID_UNDEFINED);
- if (null == cfg) {
- throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this);
- }
- setGraphicsConfiguration(cfg);
- final int flags = getReconfigureFlags(0, true) &
- ( FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED ) ;
- setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(),
- getParentWindowHandle(), getX(), getY(), getWidth(), getHeight(), autoPosition(), flags));
- if (getWindowHandle() == 0) {
- throw new NativeWindowException("Error creating window");
- }
- windowHandleClose = getWindowHandle();
- addMouseListener(new MouseTracker());
-
- if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("Info: Window new window handle "+Thread.currentThread().getName()+
- " (Parent HWND "+toHexString(getParentWindowHandle())+
- ") : HWND "+toHexString(getWindowHandle())+", "+Thread.currentThread());
- e.printStackTrace();
- }
- }
-
- class MouseTracker extends MouseAdapter {
- public void mouseEntered(MouseEvent e) {
- WindowsWindow.trackPointerLeave0(WindowsWindow.this.getWindowHandle());
- }
- }
-
- protected void closeNativeImpl() {
- if(windowHandleClose != 0) {
- if (hdc != 0) {
- try {
- GDI.ReleaseDC(windowHandleClose, hdc);
- } catch (Throwable t) {
- if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
- e.printStackTrace();
- }
- }
- }
- try {
- GDI.SetParent(windowHandleClose, 0); // detach first, experience hang w/ SWT parent
- GDI.DestroyWindow(windowHandleClose);
- } catch (Throwable t) {
- if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
- e.printStackTrace();
- }
- } finally {
- windowHandleClose = 0;
- }
- }
- hdc = 0;
- hdc_old = 0;
- }
-
- protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
- if(DEBUG_IMPLEMENTATION) {
- System.err.println("WindowsWindow reconfig: "+x+"/"+y+" "+width+"x"+height+", "+
- getReconfigureFlagsAsString(null, flags));
- }
-
- if(0 == ( FLAG_IS_UNDECORATED & flags)) {
- final InsetsImmutable i = getInsets();
-
- // client position -> top-level window position
- x -= i.getLeftWidth() ;
- y -= i.getTopHeight() ;
-
- if(0 top-level window size
- width += i.getTotalWidth();
- height += i.getTotalHeight();
- }
- }
- reconfigureWindow0( getParentWindowHandle(), getWindowHandle(), x, y, width, height, flags);
-
- if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
- visibleChanged(false, 0 != ( FLAG_IS_VISIBLE & flags));
- }
- return true;
- }
-
- protected void requestFocusImpl(boolean force) {
- requestFocus0(getWindowHandle(), force);
- }
-
- @Override
- protected void setTitleImpl(final String title) {
- setTitle0(getWindowHandle(), title);
- }
-
- @Override
- protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
- final Boolean[] res = new Boolean[] { Boolean.FALSE };
-
- this.runOnEDTIfAvail(true, new Runnable() {
- public void run() {
- res[0] = Boolean.valueOf(setPointerVisible0(getWindowHandle(), pointerVisible));
- }
- });
- return res[0].booleanValue();
- }
-
- @Override
- protected boolean confinePointerImpl(final boolean confine) {
- final Boolean[] res = new Boolean[] { Boolean.FALSE };
-
- this.runOnEDTIfAvail(true, new Runnable() {
- public void run() {
- final Point p0 = getLocationOnScreenImpl(0, 0);
- res[0] = Boolean.valueOf(confinePointer0(getWindowHandle(), confine,
- p0.getX(), p0.getY(), p0.getX()+getWidth(), p0.getY()+getHeight()));
- }
- });
- return res[0].booleanValue();
- }
-
- @Override
- protected void warpPointerImpl(final int x, final int y) {
- this.runOnEDTIfAvail(true, new Runnable() {
- public void run() {
- final Point sPos = getLocationOnScreenImpl(x, y);
- warpPointer0(getWindowHandle(), sPos.getX(), sPos.getY());
- }
- });
- return;
- }
-
- protected Point getLocationOnScreenImpl(int x, int y) {
- return GDIUtil.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y);
- }
-
- protected void updateInsetsImpl(Insets insets) {
- // nop - using event driven insetsChange(..)
- }
-
- private final int validateKeyCode(int eventType, int keyCode) {
- switch(eventType) {
- case KeyEvent.EVENT_KEY_PRESSED:
- lastPressedKeyCode = keyCode;
- break;
- case KeyEvent.EVENT_KEY_TYPED:
- if(-1==keyCode) {
- keyCode = lastPressedKeyCode;
- }
- lastPressedKeyCode = -1;
- break;
- }
- return keyCode;
- }
- private int lastPressedKeyCode = 0;
-
- @Override
- public void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
- // Note that we have to regenerate the keyCode for EVENT_KEY_TYPED on this platform
- keyCode = validateKeyCode(eventType, keyCode);
- super.sendKeyEvent(eventType, modifiers, keyCode, keyChar);
- }
-
- @Override
- public void enqueueKeyEvent(boolean wait, int eventType, int modifiers, int keyCode, char keyChar) {
- // Note that we have to regenerate the keyCode for EVENT_KEY_TYPED on this platform
- keyCode = validateKeyCode(eventType, keyCode);
- super.enqueueKeyEvent(wait, eventType, modifiers, keyCode, keyChar);
- }
-
- //----------------------------------------------------------------------
- // Internals only
- //
- protected static native boolean initIDs0();
- protected static native long getNewtWndProc0();
-
- private native long CreateWindow0(long hInstance, String wndClassName, String wndName,
- long parentWindowHandle,
- int x, int y, int width, int height, boolean autoPosition, int flags);
- private native long MonitorFromWindow0(long windowHandle);
- private native void reconfigureWindow0(long parentWindowHandle, long windowHandle,
- int x, int y, int width, int height, int flags);
- private static native void setTitle0(long windowHandle, String title);
- private native void requestFocus0(long windowHandle, boolean force);
-
- private static native boolean setPointerVisible0(long windowHandle, boolean visible);
- private static native boolean confinePointer0(long windowHandle, boolean grab, int l, int t, int r, int b);
- private static native void warpPointer0(long windowHandle, int x, int y);
- private static native void trackPointerLeave0(long windowHandle);
-}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
new file mode 100644
index 000000000..714324d63
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package jogamp.newt.driver.x11;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.NativeWindowFactory;
+
+import com.jogamp.nativewindow.x11.X11GraphicsDevice;
+
+import jogamp.nativewindow.x11.X11Util;
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.NEWTJNILibLoader;
+
+public class DisplayDriver extends DisplayImpl {
+
+ static {
+ NEWTJNILibLoader.loadNEWT();
+
+ if ( !initIDs0(X11Util.XERROR_STACKDUMP) ) {
+ throw new NativeWindowException("Failed to initialize X11Display jmethodIDs");
+ }
+
+ if (!WindowDriver.initIDs0()) {
+ throw new NativeWindowException("Failed to initialize X11Window jmethodIDs");
+ }
+ }
+
+ public static void initSingleton() {
+ // just exist to ensure static init has been run
+ }
+
+
+ public DisplayDriver() {
+ }
+
+ public String validateDisplayName(String name, long handle) {
+ return X11Util.validateDisplayName(name, handle);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * We use a private non-shared X11 Display instance for EDT window operations and one for exposed animation, eg. OpenGL.
+ *
+ * In case {@link X11Util#HAS_XLOCKDISPLAY_BUG} and {@link X11Util#XINITTHREADS_ALWAYS_ENABLED},
+ * we use null locking. Even though this seems not to be rational, it gives most stable results on all platforms.
+ *
+ *
+ * Otherwise we use basic locking via the constructor {@link X11GraphicsDevice#X11GraphicsDevice(long, int, boolean)},
+ * since it is possible to share this device via {@link com.jogamp.newt.NewtFactory#createDisplay(String, boolean)}.
+ *
+ */
+ @SuppressWarnings("unused")
+ protected void createNativeImpl() {
+ long handle = X11Util.openDisplay(name);
+ if( 0 == handle ) {
+ throw new RuntimeException("Error creating display(Win): "+name);
+ }
+ if(USE_SEPARATE_DISPLAY_FOR_EDT) {
+ edtDisplayHandle = X11Util.openDisplay(name);
+ if( 0 == edtDisplayHandle ) {
+ X11Util.closeDisplay(handle);
+ throw new RuntimeException("Error creating display(EDT): "+name);
+ }
+ } else {
+ edtDisplayHandle = handle;
+ }
+ try {
+ CompleteDisplay0(edtDisplayHandle);
+ } catch(RuntimeException e) {
+ closeNativeImpl();
+ throw e;
+ }
+
+ // see API doc above!
+ if(X11Util.XINITTHREADS_ALWAYS_ENABLED && X11Util.HAS_XLOCKDISPLAY_BUG) {
+ aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock(), false);
+ } else {
+ aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, false);
+ }
+ }
+
+ protected void closeNativeImpl() {
+ DisplayRelease0(edtDisplayHandle, javaObjectAtom, windowDeleteAtom);
+ javaObjectAtom = 0;
+ windowDeleteAtom = 0;
+ // closing using ATI driver bug 'same order'
+ final long handle = getHandle();
+ X11Util.closeDisplay(handle);
+ if(handle != edtDisplayHandle) {
+ X11Util.closeDisplay(edtDisplayHandle);
+ }
+ edtDisplayHandle = 0;
+ }
+
+ protected void dispatchMessagesNative() {
+ if(0 != edtDisplayHandle) {
+ DispatchMessages0(edtDisplayHandle, javaObjectAtom, windowDeleteAtom);
+ }
+ }
+
+ protected long getEDTHandle() { return edtDisplayHandle; }
+ protected long getJavaObjectAtom() { return javaObjectAtom; }
+ protected long getWindowDeleteAtom() { return windowDeleteAtom; }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+ private static native boolean initIDs0(boolean debug);
+
+ private native void CompleteDisplay0(long handle);
+
+ private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) {
+ this.javaObjectAtom=javaObjectAtom;
+ this.windowDeleteAtom=windowDeleteAtom;
+ }
+ private native void DisplayRelease0(long handle, long javaObjectAtom, long windowDeleteAtom);
+
+ private native void DispatchMessages0(long display, long javaObjectAtom, long windowDeleteAtom);
+
+ /**
+ * 2011/06/14 libX11 1.4.2 and libxcb 1.7 bug 20708 - Multithreading Issues w/ OpenGL, ..
+ * https://bugs.freedesktop.org/show_bug.cgi?id=20708
+ * https://jogamp.org/bugzilla/show_bug.cgi?id=502
+ * Affects: Ubuntu 11.04, OpenSuSE 11, ..
+ * Workaround: Using a separate X11 Display connection for event dispatching (EDT)
+ */
+ private final boolean USE_SEPARATE_DISPLAY_FOR_EDT = true;
+
+ private long edtDisplayHandle;
+
+ /** X11 Window delete atom marker used on EDT */
+ private long windowDeleteAtom;
+
+ /** X11 Window java object property used on EDT */
+ private long javaObjectAtom;
+}
+
diff --git a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java
new file mode 100644
index 000000000..10f6b84da
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java
@@ -0,0 +1,357 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * Copyright (c) 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:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+package jogamp.newt.driver.x11;
+
+import java.util.List;
+
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.Point;
+
+import jogamp.nativewindow.x11.X11Util;
+import jogamp.newt.DisplayImpl;
+import jogamp.newt.DisplayImpl.DisplayRunnable;
+import jogamp.newt.ScreenImpl;
+
+import com.jogamp.nativewindow.x11.X11GraphicsDevice;
+import com.jogamp.nativewindow.x11.X11GraphicsScreen;
+import com.jogamp.newt.ScreenMode;
+import com.jogamp.newt.util.ScreenModeUtil;
+
+public class ScreenDriver extends ScreenImpl {
+
+ static {
+ DisplayDriver.initSingleton();
+ }
+
+ public ScreenDriver() {
+ }
+
+ protected void createNativeImpl() {
+ // validate screen index
+ Long handle = display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ public Long run(long dpy) {
+ return new Long(GetScreen0(dpy, screen_idx));
+ } } );
+ if (handle.longValue() == 0) {
+ throw new RuntimeException("Error creating screen: " + screen_idx);
+ }
+ aScreen = new X11GraphicsScreen((X11GraphicsDevice) getDisplay().getGraphicsDevice(), screen_idx);
+ }
+
+ protected void closeNativeImpl() {
+ }
+
+ private int[] nrotations;
+ private int nrotation_index;
+ private int nres_number;
+ private int nres_index;
+ private int[] nrates;
+ private int nrate_index;
+ private int nmode_number;
+
+ protected int[] getScreenModeFirstImpl() {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ public int[] run(long dpy) {
+ // initialize iterators and static data
+ nrotations = getAvailableScreenModeRotations0(dpy, screen_idx);
+ if(null==nrotations || 0==nrotations.length) {
+ return null;
+ }
+ nrotation_index = 0;
+
+ nres_number = getNumScreenModeResolutions0(dpy, screen_idx);
+ if(0==nres_number) {
+ return null;
+ }
+ nres_index = 0;
+
+ nrates = getScreenModeRates0(dpy, screen_idx, nres_index);
+ if(null==nrates || 0==nrates.length) {
+ return null;
+ }
+ nrate_index = 0;
+
+ nmode_number = 0;
+
+ return getScreenModeNextImpl();
+ } } );
+ }
+
+ protected int[] getScreenModeNextImpl() {
+ // assemble: w x h x bpp x f x r
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ public int[] run(long dpy) {
+ /**
+ System.err.println("******** mode: "+nmode_number);
+ System.err.println("rot "+nrotation_index);
+ System.err.println("rate "+nrate_index);
+ System.err.println("res "+nres_index); */
+
+ int[] res = getScreenModeResolution0(dpy, screen_idx, nres_index);
+ if(null==res || 0==res.length) {
+ return null;
+ }
+ if(0>=res[0] || 0>=res[1]) {
+ throw new InternalError("invalid resolution: "+res[0]+"x"+res[1]+" for res idx "+nres_index+"/"+nres_number);
+ }
+ int rate = nrates[nrate_index];
+ if(0>=rate) {
+ rate = default_sm_rate;
+ if(DEBUG) {
+ System.err.println("Invalid rate: "+rate+" at index "+nrate_index+"/"+nrates.length+", using default: "+default_sm_rate);
+ }
+ }
+ int rotation = nrotations[nrotation_index];
+
+ int[] props = new int[ 1 + ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL ];
+ int i = 0;
+ props[i++] = nres_index; // use resolution index, not unique for native -> ScreenMode
+ props[i++] = 0; // set later for verification of iterator
+ props[i++] = res[0]; // width
+ props[i++] = res[1]; // height
+ props[i++] = default_sm_bpp; // FIXME
+ props[i++] = res[2]; // widthmm
+ props[i++] = res[3]; // heightmm
+ props[i++] = rate; // rate
+ props[i++] = rotation;
+ props[i - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = i - 1; // count without extra element
+
+ nmode_number++;
+
+ // iteration: r -> f -> bpp -> [w x h]
+ nrotation_index++;
+ if(nrotation_index == nrotations.length) {
+ nrotation_index=0;
+ nrate_index++;
+ if(null == nrates || nrate_index == nrates.length){
+ nres_index++;
+ if(nres_index == nres_number) {
+ // done
+ nrates=null;
+ nrotations=null;
+ return null;
+ }
+
+ nrates = getScreenModeRates0(dpy, screen_idx, nres_index);
+ if(null==nrates || 0==nrates.length) {
+ return null;
+ }
+ nrate_index = 0;
+ }
+ }
+
+ return props;
+ } } );
+ }
+
+ protected ScreenMode getCurrentScreenModeImpl() {
+ return runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ public ScreenMode run(long dpy) {
+ long screenConfigHandle = getScreenConfiguration0(dpy, screen_idx);
+ if(0 == screenConfigHandle) {
+ return null;
+ }
+ int[] res;
+ int rate, rot;
+ try {
+ int resNumber = getNumScreenModeResolutions0(dpy, screen_idx);
+ if(0==resNumber) {
+ return null;
+ }
+
+ int resIdx = getCurrentScreenResolutionIndex0(screenConfigHandle);
+ if(0>resIdx) {
+ return null;
+ }
+ if(resIdx>=resNumber) {
+ throw new RuntimeException("Invalid resolution index: ! "+resIdx+" < "+resNumber);
+ }
+ res = getScreenModeResolution0(dpy, screen_idx, resIdx);
+ if(null==res || 0==res.length) {
+ return null;
+ }
+ if(0>=res[0] || 0>=res[1]) {
+ throw new InternalError("invalid resolution: "+res[0]+"x"+res[1]+" for res idx "+resIdx+"/"+resNumber);
+ }
+ rate = getCurrentScreenRate0(screenConfigHandle);
+ if(0>rate) {
+ return null;
+ }
+ rot = getCurrentScreenRotation0(screenConfigHandle);
+ if(0>rot) {
+ return null;
+ }
+ } finally {
+ freeScreenConfiguration0(screenConfigHandle);
+ }
+ int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL];
+ int i = 0;
+ props[i++] = 0; // set later for verification of iterator
+ props[i++] = res[0]; // width
+ props[i++] = res[1]; // height
+ props[i++] = default_sm_bpp; // FIXME
+ props[i++] = res[2]; // widthmm
+ props[i++] = res[3]; // heightmm
+ props[i++] = rate; // rate
+ props[i++] = rot;
+ props[i - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = i; // count
+ return ScreenModeUtil.streamIn(props, 0);
+ } } );
+ }
+
+ protected boolean setCurrentScreenModeImpl(final ScreenMode screenMode) {
+ final List screenModes = this.getScreenModesOrig();
+ final int screenModeIdx = screenModes.indexOf(screenMode);
+ if(0>screenModeIdx) {
+ throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode);
+ }
+ final long t0 = System.currentTimeMillis();
+ boolean done = runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable() {
+ public Boolean run(long dpy) {
+ boolean done = false;
+ long screenConfigHandle = getScreenConfiguration0(dpy, screen_idx);
+ if(0 == screenConfigHandle) {
+ return Boolean.valueOf(done);
+ }
+ try {
+ int resNumber = getNumScreenModeResolutions0(dpy, screen_idx);
+ int resIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx);
+ if(0>resIdx || resIdx>=resNumber) {
+ throw new RuntimeException("Invalid resolution index: ! 0 < "+resIdx+" < "+resNumber+", screenMode["+screenModeIdx+"] "+screenMode);
+ }
+
+ final int f = screenMode.getMonitorMode().getRefreshRate();
+ final int r = screenMode.getRotation();
+
+ if( setCurrentScreenModeStart0(dpy, screen_idx, screenConfigHandle, resIdx, f, r) ) {
+ while(!done && System.currentTimeMillis()-t0 < SCREEN_MODE_CHANGE_TIMEOUT) {
+ done = setCurrentScreenModePollEnd0(dpy, screen_idx, resIdx, f, r);
+ if(!done) {
+ try { Thread.sleep(10); } catch (InterruptedException e) { }
+ }
+ }
+ }
+ } finally {
+ freeScreenConfiguration0(screenConfigHandle);
+ }
+ return Boolean.valueOf(done);
+ }
+ }).booleanValue();
+
+ if(DEBUG || !done) {
+ System.err.println("X11Screen.setCurrentScreenModeImpl: TO ("+SCREEN_MODE_CHANGE_TIMEOUT+") reached: "+
+ (System.currentTimeMillis()-t0)+"ms; Current: "+getCurrentScreenMode()+"; Desired: "+screenMode);
+ }
+ return done;
+ }
+
+ private class XineramaEnabledQuery implements DisplayImpl.DisplayRunnable {
+ public Boolean run(long dpy) {
+ return new Boolean(X11Util.XineramaIsEnabled(dpy));
+ }
+ }
+ private XineramaEnabledQuery xineramaEnabledQuery = new XineramaEnabledQuery();
+
+ protected int validateScreenIndex(final int idx) {
+ if(getDisplay().isNativeValid()) {
+ return runWithLockedDisplayHandle( xineramaEnabledQuery ).booleanValue() ? 0 : idx;
+ } else {
+ return runWithTempDisplayHandle( xineramaEnabledQuery ).booleanValue() ? 0 : idx;
+ }
+ }
+
+ protected void getVirtualScreenOriginAndSize(final Point virtualOrigin, final Dimension virtualSize) {
+ display.runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable
+ */
+public class TestInitConcurrent02NEWT extends InitConcurrentBaseNEWT {
+
+ @Test
+ public void test02TwoThreads() throws InterruptedException {
+ runJOGLTasks(2, false);
+ }
+
+ @Test
+ public void test02FourThreads() throws InterruptedException {
+ runJOGLTasks(4, false);
+ }
+
+ @Test
+ public void test16SixteenThreads() throws InterruptedException {
+ if( Platform.getCPUFamily() != Platform.CPUFamily.ARM ) {
+ runJOGLTasks(16, false);
+ } else {
+ runJOGLTasks( 8, false);
+ }
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i=0; i--) {
- if(!tasks[i].done()) {
- return false;
- }
- }
- return true;
- }
- protected static String doneDump(JOGLTask[] tasks) {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- for(int i=0; i0) {
- sb.append(", ");
- }
- sb.append(i).append(": ").append(tasks[i].done());
- }
- sb.append("]");
- return sb.toString();
- }
-
- protected static boolean isDead(Thread[] threads) {
- for(int i=threads.length-1; i>=0; i--) {
- if(threads[i].isAlive()) {
- return false;
- }
- }
- return true;
- }
- protected static String isAliveDump(Thread[] threads) {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- for(int i=0; i0) {
- sb.append(", ");
- }
- sb.append(i).append(": ").append(threads[i].isAlive());
- }
- sb.append("]");
- return sb.toString();
- }
-
- protected void runJOGLTasks(int num) throws InterruptedException {
- final String currentThreadName = Thread.currentThread().getName();
- final Object sync = new Object();
- final JOGLTask[] tasks = new JOGLTask[num];
- final Thread[] threads = new Thread[num];
- int i;
- for(i=0; i
Date: Tue, 2 Oct 2012 07:28:00 +0200
Subject: Relax Bug 613 workaround of commit
92398025abdabb2fdef0d78edd41e730991a6f94
Utilizing a GlobalToolkitLock in general to lock the display connection results in deadlock
situations where locked surfaces signal other [offscreen] surfaces to render.
We have to see whether we find a better solution, for now sporadic XCB assertion still happen.
But it is preferrable to point to the root cause, then to jumping through hoops to complicate locking
or even to deadlock.
Locking:
- X11GLXGraphicsConfigurationFactory add missing device locking in:
- getAvailableCapabilities
- chooseGraphicsConfigurationStatic
- Newt/X11Window: Discard display events after window close.
Relax ATI XCB/threading bug workaround:
- ToolkitProperties: requiresGlobalToolkitLock() -> hasThreadingIssues()
- NativeWindowFactory: Don't use GlobalToolkitLock in case of 'threadingIssues' the impact is too severe (see above)
- NativeWindowFactory: Add getGlobalToolkitLockIfRequired(): To be used for small code blocks.
If having 'threadingIssues' a GlobalToolkitLock is returned, otherwise NullToolkitLock.
- X11GLXContext: [create/destroy]ContextARBImpl: Use 'NativeWindowFactory.getGlobalToolkitLockIfRequired()' for extra locking
Misc Cleanup:
- *DrawableFactory createMutableSurface: Also create new device if type is not suitable
- *DrawableFactory createDummySurfaceImpl: Pass chosenCaps and use it (preserves orig. requested user caps)
---
.../jogamp/opengl/GLDrawableFactoryImpl.java | 9 ++---
.../jogamp/opengl/egl/EGLDrawableFactory.java | 8 ++---
.../macosx/cgl/MacOSXCGLDrawableFactory.java | 9 ++---
.../windows/wgl/WindowsWGLDrawableFactory.java | 13 +++----
.../jogamp/opengl/x11/glx/X11GLXContext.java | 24 +++++++++----
.../opengl/x11/glx/X11GLXDrawableFactory.java | 22 ++++++------
.../glx/X11GLXGraphicsConfigurationFactory.java | 41 ++++++++++++++--------
.../com/jogamp/nativewindow/swt/SWTAccessor.java | 2 +-
.../media/nativewindow/NativeWindowFactory.java | 40 ++++++++-------------
.../jogamp/nativewindow/GlobalToolkitLock.java | 13 ++++---
.../nativewindow/NativeWindowFactoryImpl.java | 5 ---
.../jogamp/nativewindow/ToolkitProperties.java | 8 ++---
.../classes/jogamp/nativewindow/jawt/JAWTUtil.java | 3 --
.../jogamp/nativewindow/macosx/OSXUtil.java | 2 +-
.../jogamp/nativewindow/windows/GDIUtil.java | 2 +-
.../classes/jogamp/nativewindow/x11/X11Util.java | 10 +++---
.../jogamp/newt/driver/x11/DisplayDriver.java | 2 +-
.../jogamp/newt/driver/x11/WindowDriver.java | 2 +-
src/newt/native/X11Display.c | 4 +--
src/newt/native/X11Window.c | 2 +-
20 files changed, 113 insertions(+), 108 deletions(-)
(limited to 'src/newt/native/X11Window.c')
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
index bd2db1b81..0ea565b89 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableFactoryImpl.java
@@ -188,7 +188,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
if( chosenCaps.isFBO() && isFBOAvailable ) {
// need to hook-up a native dummy surface since source may not have
- final ProxySurface dummySurface = createDummySurfaceImpl(adevice, true, chosenCaps, null, 64, 64);
+ final ProxySurface dummySurface = createDummySurfaceImpl(adevice, false, chosenCaps, (GLCapabilitiesImmutable)config.getRequestedCapabilities(), null, 64, 64);
dummySurface.setUpstreamSurfaceHook(new DelegatedUpstreamSurfaceHookWithSurfaceSize(dummySurface.getUpstreamSurfaceHook(), target));
result = createFBODrawableImpl(dummySurface, chosenCaps, 0);
} else {
@@ -299,7 +299,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
if( capsChosen.isFBO() ) {
device.lock();
try {
- final ProxySurface dummySurface = createDummySurfaceImpl(device, true, capsRequested, null, width, height);
+ final ProxySurface dummySurface = createDummySurfaceImpl(device, true, capsChosen, capsRequested, null, width, height);
final GLDrawableImpl dummyDrawable = createOnscreenDrawableImpl(dummySurface);
return new GLFBODrawableImpl.ResizeableImpl(this, dummyDrawable, dummySurface, capsChosen, 0);
} finally {
@@ -370,7 +370,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
}
device.lock();
try {
- return createDummySurfaceImpl(device, true, requestedCaps, chooser, width, height);
+ return createDummySurfaceImpl(device, true, requestedCaps, requestedCaps, chooser, width, height);
} finally {
device.unlock();
}
@@ -386,6 +386,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
* @param device a valid platform dependent target device.
* @param createNewDevice if true a new device instance is created using device details,
* otherwise device instance is used as-is.
+ * @param chosenCaps
* @param requestedCaps
* @param chooser the custom chooser, may be null for default
* @param width the initial width as returned by {@link NativeSurface#getWidth()}, not the actual dummy surface width.
@@ -395,7 +396,7 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory {
* @return the created {@link ProxySurface} instance w/o defined surface handle but platform specific {@link UpstreamSurfaceHook}.
*/
public abstract ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice device, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height);
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height);
//---------------------------------------------------------------------------
//
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
index a907c4aff..da3907193 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
@@ -367,7 +367,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
if( hasPBuffer[0] ) {
// 2nd case create defaultDevice shared resource using pbuffer surface
- surface = createDummySurfaceImpl(eglDevice, false, reqCapsPBuffer, null, 64, 64); // egl pbuffer offscreen
+ surface = createDummySurfaceImpl(eglDevice, false, reqCapsPBuffer, reqCapsPBuffer, null, 64, 64); // egl pbuffer offscreen
upstreamSurface = (ProxySurface)surface;
upstreamSurface.createNotify();
deviceFromUpstreamSurface = false;
@@ -664,7 +664,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final boolean ownDevice;
final EGLGraphicsDevice device;
- if(createNewDevice || ! ( deviceReq instanceof EGLGraphicsDevice ) ) {
+ if( createNewDevice || ! (deviceReq instanceof EGLGraphicsDevice) ) {
final long nativeDisplayID = ( deviceReq instanceof EGLGraphicsDevice) ?
( (EGLGraphicsDevice) deviceReq ).getNativeDisplayID() : deviceReq.getHandle() ;
device = EGLDisplayUtil.eglCreateEGLGraphicsDevice(nativeDisplayID, deviceReq.getConnection(), deviceReq.getUnitID());
@@ -683,8 +683,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOffscreenBitOnly(requestedCaps); // complete validation in EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(..) above
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixOffscreenBitOnly(chosenCaps); // complete validation in EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(..) above
return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, new EGLDummyUpstreamSurfaceHook(width, height));
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
index d59197e1d..ec3156f52 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -226,7 +226,8 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
- final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, new GLCapabilities(glp), null, 64, 64));
+ final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
+ final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
sharedDrawable.setRealized(true);
final MacOSXCGLContext sharedContext = (MacOSXCGLContext) sharedDrawable.createContext(null);
@@ -358,7 +359,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested,
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final MacOSXGraphicsDevice device;
- if(createNewDevice) {
+ if( createNewDevice || !(deviceReq instanceof MacOSXGraphicsDevice) ) {
device = new MacOSXGraphicsDevice(deviceReq.getUnitID());
} else {
device = (MacOSXGraphicsDevice)deviceReq;
@@ -373,8 +374,8 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(requestedCaps);
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps);
return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser,
new OSXDummyUpstreamSurfaceHook(width, height));
}
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
index 91d5c225a..c6bc61a27 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -318,7 +318,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
- final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, new GLCapabilities(glp), null, 64, 64));
+ final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
+ final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
sharedDrawable.setRealized(true);
final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null);
@@ -543,7 +544,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested,
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final WindowsGraphicsDevice device;
- if(createNewDevice) {
+ if(createNewDevice || !(deviceReq instanceof WindowsGraphicsDevice)) {
device = new WindowsGraphicsDevice(deviceReq.getConnection(), deviceReq.getUnitID());
} else {
device = (WindowsGraphicsDevice)deviceReq;
@@ -558,18 +559,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
final WindowsGraphicsDevice device;
- if(createNewDevice) {
+ if( createNewDevice || !(deviceReq instanceof WindowsGraphicsDevice) ) {
device = new WindowsGraphicsDevice(deviceReq.getConnection(), deviceReq.getUnitID());
} else {
device = (WindowsGraphicsDevice)deviceReq;
}
final AbstractGraphicsScreen screen = new DefaultGraphicsScreen(device, 0);
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(requestedCaps);
+ chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps);
final WindowsWGLGraphicsConfiguration config = WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(chosenCaps, requestedCaps, chooser, screen);
if(null == config) {
- throw new GLException("Choosing GraphicsConfiguration failed w/ "+requestedCaps+" on "+screen);
+ throw new GLException("Choosing GraphicsConfiguration failed w/ "+chosenCaps+" on "+screen);
}
return new GDISurface(config, 0, new GDIDummyUpstreamSurfaceHook(width, height), createNewDevice);
}
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
index 72ddd2693..f7389d42e 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
@@ -48,6 +48,8 @@ import java.util.Map;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.ToolkitLock;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
@@ -180,11 +182,16 @@ public abstract class X11GLXContext extends GLContextImpl {
@Override
protected void destroyContextARBImpl(long ctx) {
- X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration();
- long display = config.getScreen().getDevice().getHandle();
-
- glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, ctx);
+ final ToolkitLock tkLock = NativeWindowFactory.getGlobalToolkitLockIfRequired();
+ tkLock.lock();
+ try {
+ long display = drawable.getNativeSurface().getDisplayHandle();
+
+ glXMakeContextCurrent(display, 0, 0, 0);
+ GLX.glXDestroyContext(display, ctx);
+ } finally {
+ tkLock.unlock();
+ }
}
private static final int ctx_arb_attribs_idx_major = 0;
private static final int ctx_arb_attribs_idx_minor = 2;
@@ -243,6 +250,8 @@ public abstract class X11GLXContext extends GLContextImpl {
AbstractGraphicsDevice device = config.getScreen().getDevice();
final long display = device.getHandle();
+ final ToolkitLock tkLock = NativeWindowFactory.getGlobalToolkitLockIfRequired();
+ tkLock.lock();
try {
// critical path, a remote display might not support this command,
// hence we need to catch the X11 Error within this block.
@@ -253,7 +262,10 @@ public abstract class X11GLXContext extends GLContextImpl {
Throwable t = new Throwable(getThreadName()+": Info: X11GLXContext.createContextARBImpl glXCreateContextAttribsARB failed with "+getGLVersion(major, minor, ctp, "@creation"), re);
t.printStackTrace();
}
+ } finally {
+ tkLock.unlock();
}
+
if(0!=ctx) {
if (!glXMakeContextCurrent(display, drawable.getHandle(), drawableRead.getHandle(), ctx)) {
if(DEBUG) {
@@ -420,7 +432,7 @@ public abstract class X11GLXContext extends GLContextImpl {
@Override
protected void destroyImpl() throws GLException {
- GLX.glXDestroyContext(drawable.getNativeSurface().getDisplayHandle(), contextHandle);
+ destroyContextARBImpl(contextHandle);
}
@Override
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 018f6a6ea..e38aabef8 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -229,7 +229,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
@Override
public SharedResourceRunner.Resource createSharedResource(String connection) {
- final X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT, true);
+ final X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
sharedDevice.lock();
try {
final X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, sharedDevice.getDefaultScreen());
@@ -246,8 +246,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
-
- final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, new GLCapabilities(glp), null, 64, 64));
+
+ final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
+ final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl(createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
sharedDrawable.setRealized(true);
final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null);
@@ -499,11 +500,10 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
GLCapabilitiesImmutable capsRequested,
GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) {
final X11GraphicsDevice device;
- if(createNewDevice) {
- // Null X11 resource locking, due to private non-shared Display handle
- device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true);
+ if( createNewDevice || !(deviceReq instanceof X11GraphicsDevice) ) {
+ device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true /* owner */);
} else {
- device = (X11GraphicsDevice)deviceReq;
+ device = (X11GraphicsDevice) deviceReq;
}
final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());
final X11GLXGraphicsConfiguration config = X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED);
@@ -512,17 +512,17 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
}
return new WrappedSurface(config, 0, upstreamHook, createNewDevice);
}
-
+
@Override
public final ProxySurface createDummySurfaceImpl(AbstractGraphicsDevice deviceReq, boolean createNewDevice,
- GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(requestedCaps);
+ GLCapabilitiesImmutable chosenCaps, GLCapabilitiesImmutable requestedCaps, GLCapabilitiesChooser chooser, int width, int height) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixOnscreenGLCapabilities(chosenCaps);
return createMutableSurfaceImpl(deviceReq, createNewDevice, chosenCaps, requestedCaps, chooser, new X11DummyUpstreamSurfaceHook(width, height));
}
@Override
protected final ProxySurface createProxySurfaceImpl(AbstractGraphicsDevice deviceReq, int screenIdx, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstream) {
- final X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true);
+ final X11GraphicsDevice device = new X11GraphicsDevice(X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true /* owner */);
final X11GraphicsScreen screen = new X11GraphicsScreen(device, screenIdx);
final int xvisualID = X11Lib.GetVisualIDFromWindow(device.getHandle(), windowHandle);
if(VisualIDHolder.VID_UNDEFINED == xvisualID) {
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java
index ef2d3283d..8ac324205 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfigurationFactory.java
@@ -127,16 +127,22 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF
throw new GLException("Shared resource for device n/a: "+device);
}
final X11GraphicsScreen sharedScreen = (X11GraphicsScreen) sharedResource.getScreen();
- final boolean isMultisampleAvailable = factory.isGLXMultisampleAvailable(sharedScreen.getDevice());
+ final X11GraphicsDevice sharedDevice = (X11GraphicsDevice) sharedScreen.getDevice();
+ final boolean isMultisampleAvailable = sharedResource.isGLXMultisampleAvailable();
final GLProfile glp = GLProfile.getDefault(device);
List availableCaps = null;
-
- if( sharedResource.isGLXVersionGreaterEqualOneThree() ) {
- availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp, isMultisampleAvailable);
- }
- if( null == availableCaps || availableCaps.isEmpty() ) {
- availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp, isMultisampleAvailable);
+
+ sharedDevice.lock();
+ try {
+ if( sharedResource.isGLXVersionGreaterEqualOneThree() ) {
+ availableCaps = getAvailableGLCapabilitiesFBConfig(sharedScreen, glp, isMultisampleAvailable);
+ }
+ if( null == availableCaps || availableCaps.isEmpty() ) {
+ availableCaps = getAvailableGLCapabilitiesXVisual(sharedScreen, glp, isMultisampleAvailable);
+ }
+ } finally {
+ sharedDevice.unlock();
}
if( null != availableCaps && availableCaps.size() > 1 ) {
Collections.sort(availableCaps, XVisualIDComparator);
@@ -215,16 +221,21 @@ public class X11GLXGraphicsConfigurationFactory extends GLGraphicsConfigurationF
capsChosen = GLGraphicsConfigurationUtil.fixGLCapabilities( capsChosen, factory, x11Device);
final boolean usePBuffer = !capsChosen.isOnscreen() && capsChosen.isPBuffer();
-
+
X11GLXGraphicsConfiguration res = null;
- if( factory.isGLXVersionGreaterEqualOneThree(x11Device) ) {
- res = chooseGraphicsConfigurationFBConfig(capsChosen, capsReq, chooser, x11Screen, xvisualID);
- }
- if(null==res) {
- if(usePBuffer) {
- throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for visualID "+toHexString(xvisualID)+", "+capsChosen);
+ x11Device.lock();
+ try {
+ if( factory.isGLXVersionGreaterEqualOneThree(x11Device) ) {
+ res = chooseGraphicsConfigurationFBConfig(capsChosen, capsReq, chooser, x11Screen, xvisualID);
+ }
+ if(null==res) {
+ if(usePBuffer) {
+ throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig for visualID "+toHexString(xvisualID)+", "+capsChosen);
+ }
+ res = chooseGraphicsConfigurationXVisual(capsChosen, capsReq, chooser, x11Screen, xvisualID);
}
- res = chooseGraphicsConfigurationXVisual(capsChosen, capsReq, chooser, x11Screen, xvisualID);
+ } finally {
+ x11Device.unlock();
}
if(null==res) {
throw new GLException("Error: Couldn't create X11GLXGraphicsConfiguration based on FBConfig and XVisual for visualID "+toHexString(xvisualID)+", "+x11Screen+", "+capsChosen);
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
index 1cc796086..7be747ff5 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
@@ -210,7 +210,7 @@ public class SWTAccessor {
if( null != OS_gtk_class ) {
long widgedHandle = callStaticMethodL2L(OS_GTK_WIDGET_WINDOW, handle);
long displayHandle = callStaticMethodL2L(OS_gdk_x11_drawable_get_xdisplay, widgedHandle);
- return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false);
+ return new X11GraphicsDevice(displayHandle, AbstractGraphicsDevice.DEFAULT_UNIT, false /* owner */);
}
final String nwt = NativeWindowFactory.getNativeWindowType(false);
if( NativeWindowFactory.TYPE_WINDOWS == nwt ) {
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index 1962bcd09..006ee4c97 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -42,6 +42,7 @@ import java.util.HashMap;
import java.util.Map;
import jogamp.nativewindow.Debug;
+import jogamp.nativewindow.GlobalToolkitLock;
import jogamp.nativewindow.NativeWindowFactoryImpl;
import jogamp.nativewindow.ToolkitProperties;
import jogamp.nativewindow.ResourceToolkitLock;
@@ -102,7 +103,7 @@ public abstract class NativeWindowFactory {
private static ToolkitLock jawtUtilJAWTToolkitLock;
private static boolean requiresToolkitLock;
- private static boolean requiresGlobalToolkitLock;
+ private static boolean desktopHasThreadingIssues;
private static volatile boolean isJVMShuttingDown = false;
@@ -183,15 +184,11 @@ public abstract class NativeWindowFactory {
final Boolean res1 = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "requiresToolkitLock", null, null, cl);
requiresToolkitLock = res1.booleanValue();
- if(requiresToolkitLock) {
- final Boolean res2 = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "requiresGlobalToolkitLock", null, null, cl);
- requiresGlobalToolkitLock = res2.booleanValue();
- } else {
- requiresGlobalToolkitLock = false;
- }
+ final Boolean res2 = (Boolean) ReflectionUtil.callStaticMethod(clazzName, "hasThreadingIssues", null, null, cl);
+ desktopHasThreadingIssues = res2.booleanValue();
} else {
requiresToolkitLock = false;
- requiresGlobalToolkitLock = false;
+ desktopHasThreadingIssues = false;
}
}
@@ -293,7 +290,7 @@ public abstract class NativeWindowFactory {
}
if(DEBUG) {
- System.err.println("NativeWindowFactory requiresToolkitLock "+requiresToolkitLock+", requiresGlobalToolkitLock "+requiresGlobalToolkitLock);
+ System.err.println("NativeWindowFactory requiresToolkitLock "+requiresToolkitLock+", desktopHasThreadingIssues "+desktopHasThreadingIssues);
System.err.println("NativeWindowFactory isAWTAvailable "+isAWTAvailable+", defaultFactory "+factory);
}
@@ -329,11 +326,6 @@ public abstract class NativeWindowFactory {
return requiresToolkitLock;
}
- /** @return true if the underlying toolkit requires global locking, otherwise false. */
- public static boolean requiresGlobalToolkitLock() {
- return requiresGlobalToolkitLock;
- }
-
/** @return true if not headless, AWT Component and NativeWindow's AWT part available */
public static boolean isAWTAvailable() { return isAWTAvailable; }
@@ -382,11 +374,15 @@ public abstract class NativeWindowFactory {
public static ToolkitLock getNullToolkitLock() {
return NativeWindowFactoryImpl.getNullToolkitLock();
}
-
- public static ToolkitLock getGlobalToolkitLock() {
- return NativeWindowFactoryImpl.getGlobalToolkitLock();
- }
+ /**
+ * Ony call this for small code segments for desktop w/ threading issues.
+ * @return {@link GlobalToolkitLock} if desktop has threading issues, otherwise {@link #getNullToolkitLock()}
+ */
+ public static ToolkitLock getGlobalToolkitLockIfRequired() {
+ return desktopHasThreadingIssues ? GlobalToolkitLock.getSingleton() : getNullToolkitLock();
+ }
+
/**
* Provides the system default {@link ToolkitLock} for the default system windowing type.
* @see #getNativeWindowType(boolean)
@@ -400,7 +396,6 @@ public abstract class NativeWindowFactory {
* Provides the default {@link ToolkitLock} for type.
*
*
JAWT {@link ToolkitLock} if required and type is of {@link #TYPE_AWT} and AWT available,
- *
{@link jogamp.nativewindow.GlobalToolkitLock} if required, otherwise
*
{@link jogamp.nativewindow.ResourceToolkitLock} if required, otherwise
*
{@link jogamp.nativewindow.NullToolkitLock}
*
@@ -410,9 +405,6 @@ public abstract class NativeWindowFactory {
if( TYPE_AWT == type && isAWTAvailable() ) {
return getAWTToolkitLock();
}
- if( requiresGlobalToolkitLock ) {
- return NativeWindowFactoryImpl.getGlobalToolkitLock();
- }
return ResourceToolkitLock.create();
}
return NativeWindowFactoryImpl.getNullToolkitLock();
@@ -422,7 +414,6 @@ public abstract class NativeWindowFactory {
* Provides the default {@link ToolkitLock} for type and deviceHandle.
*
*
JAWT {@link ToolkitLock} if required and type is of {@link #TYPE_AWT} and AWT available,
- *
{@link jogamp.nativewindow.GlobalToolkitLock} if required, otherwise
*
{@link jogamp.nativewindow.ResourceToolkitLock} if required, otherwise
- * This is the last resort for unstable driver, e.g. proprietary ATI/X11 12.8 and 12.9,
- * where multiple X11 display connections to the same connection name are not treated
- * thread safe within the GL/X11 driver.
+ * This is the last resort for unstable driver where multiple X11 display connections
+ * to the same connection name are not treated thread safe within the GL/X11 driver.
*
*/
public class GlobalToolkitLock implements ToolkitLock {
private static final RecursiveLock globalLock = LockFactory.createRecursiveLock();
+ private static GlobalToolkitLock singleton = new GlobalToolkitLock();
- /** Singleton via {@link NativeWindowFactoryImpl#getGlobalToolkitLock()} */
- protected GlobalToolkitLock() { }
+ public static final GlobalToolkitLock getSingleton() {
+ return singleton;
+ }
+
+ private GlobalToolkitLock() { }
@Override
public final void lock() {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
index c35cede77..a3a66b7f1 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java
@@ -44,16 +44,11 @@ import com.jogamp.common.util.ReflectionUtil.AWTNames;
public class NativeWindowFactoryImpl extends NativeWindowFactory {
private static final ToolkitLock nullToolkitLock = new NullToolkitLock();
- private static final ToolkitLock globalToolkitLock = new GlobalToolkitLock();
public static ToolkitLock getNullToolkitLock() {
return nullToolkitLock;
}
- public static ToolkitLock getGlobalToolkitLock() {
- return globalToolkitLock;
- }
-
// This subclass of NativeWindowFactory handles the case of
// NativeWindows being passed in
protected NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java b/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java
index 2062d1f58..ed23def8f 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/ToolkitProperties.java
@@ -13,15 +13,11 @@ import javax.media.nativewindow.NativeWindowFactory;
public static boolean requiresToolkitLock() {}
- public static boolean requiresGlobalToolkitLock() {}
+ public static boolean hasThreadingIssues() {}
*
* Above static methods are invoked by {@link NativeWindowFactory#initSingleton()},
* or {@link NativeWindowFactory#shutdown()} via reflection.
*
- *
- * If requiresGlobalToolkitLock() == true, then
- * requiresToolkitLock() == true shall be valid as well.
- *
*/
public interface ToolkitProperties {
@@ -46,6 +42,6 @@ public interface ToolkitProperties {
/**
* Called by {@link NativeWindowFactory#initSingleton()}
*/
- // boolean requiresGlobalToolkitLock();
+ // boolean hasThreadingIssues();
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
index 67c64a95c..349da8ee6 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java
@@ -237,18 +237,15 @@ public class JAWTUtil {
jawtToolkitLock = new ToolkitLock() {
public final void lock() {
- NativeWindowFactory.getGlobalToolkitLock().lock();
JAWTUtil.lockToolkit();
if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.lock()"); }
}
public final void unlock() {
if(TRACE_LOCK) { System.err.println("JAWTToolkitLock.unlock()"); }
JAWTUtil.unlockToolkit();
- NativeWindowFactory.getGlobalToolkitLock().unlock();
}
@Override
public final void validateLocked() throws RuntimeException {
- NativeWindowFactory.getGlobalToolkitLock().validateLocked();
JAWTUtil.validateLocked();
}
public final void dispose() {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index 481cbbe39..a195f137e 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -76,7 +76,7 @@ public class OSXUtil implements ToolkitProperties {
* Called by {@link NativeWindowFactory#initSingleton()}
* @see ToolkitProperties
*/
- public static final boolean requiresGlobalToolkitLock() { return false; }
+ public static final boolean hasThreadingIssues() { return false; }
public static boolean isNSView(long object) {
return isNSView0(object);
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java
index 4408a0903..2f4e18359 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java
@@ -84,7 +84,7 @@ public class GDIUtil implements ToolkitProperties {
* Called by {@link NativeWindowFactory#initSingleton()}
* @see ToolkitProperties
*/
- public static final boolean requiresGlobalToolkitLock() { return false; }
+ public static final boolean hasThreadingIssues() { return false; }
private static RegisteredClass dummyWindowClass = null;
private static Object dummyWindowSync = new Object();
diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
index 103995a8d..c771cd67a 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11Util.java
@@ -95,7 +95,7 @@ public class X11Util implements ToolkitProperties {
private static String nullDisplayName = null;
private static volatile boolean isInit = false;
private static boolean markAllDisplaysUnclosable = false; // ATI/AMD X11 driver issues
- private static boolean requiresGlobalToolkitLock = false; // ATI/AMD X11 driver issues
+ private static boolean hasThreadingIssues = false; // ATI/AMD X11 driver issues
private static Object setX11ErrorHandlerLock = new Object();
private static final String X11_EXTENSION_ATIFGLRXDRI = "ATIFGLRXDRI";
@@ -137,7 +137,7 @@ public class X11Util implements ToolkitProperties {
hasX11_EXTENSION_ATIFGLRXDRI = false;
hasX11_EXTENSION_ATIFGLEXTENSION = false;
}
- requiresGlobalToolkitLock = ATI_HAS_MULTITHREADING_BUG && ( hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION );
+ hasThreadingIssues = ATI_HAS_MULTITHREADING_BUG && ( hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION );
markAllDisplaysUnclosable = ATI_HAS_XCLOSEDISPLAY_BUG && ( hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION );
if(DEBUG) {
@@ -147,7 +147,7 @@ public class X11Util implements ToolkitProperties {
",\n\t X11_EXTENSION_ATIFGLRXDRI " + hasX11_EXTENSION_ATIFGLRXDRI+
",\n\t X11_EXTENSION_ATIFGLEXTENSION " + hasX11_EXTENSION_ATIFGLEXTENSION+
",\n\t requiresToolkitLock "+requiresToolkitLock()+
- ",\n\t requiresGlobalToolkitLock "+requiresGlobalToolkitLock()+
+ ",\n\t hasThreadingIssues "+hasThreadingIssues()+
",\n\t markAllDisplaysUnclosable "+getMarkAllDisplaysUnclosable()
);
// Thread.dumpStack();
@@ -228,8 +228,8 @@ public class X11Util implements ToolkitProperties {
* Called by {@link NativeWindowFactory#initSingleton()}
* @see ToolkitProperties
*/
- public static final boolean requiresGlobalToolkitLock() {
- return requiresGlobalToolkitLock; // JAWT locking: yes, instead of native X11 locking w use a global lock.
+ public static final boolean hasThreadingIssues() {
+ return hasThreadingIssues; // JOGL impl. may utilize special locking "somewhere"
}
public static void setX11ErrorHandler(boolean onoff, boolean quiet) {
diff --git a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
index 6e80e966a..a3230fa62 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
@@ -80,7 +80,7 @@ public class DisplayDriver extends DisplayImpl {
if( 0 == handle ) {
throw new RuntimeException("Error creating display(Win): "+name);
}
- aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, true);
+ aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
try {
CompleteDisplay0(aDevice.getHandle());
} catch(RuntimeException e) {
diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
index bde723634..92f174e39 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
@@ -73,7 +73,7 @@ public class WindowDriver extends WindowImpl {
if( 0 == renderDeviceHandle ) {
throw new RuntimeException("Error creating display(EDT): "+edtDevice.getConnection());
}
- renderDevice = new X11GraphicsDevice(renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true);
+ renderDevice = new X11GraphicsDevice(renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */);
final AbstractGraphicsScreen renderScreen = new X11GraphicsScreen(renderDevice, screen.getIndex());
final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested);
diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c
index 56c11fab4..69a115ab1 100644
--- a/src/newt/native/X11Display.c
+++ b/src/newt/native/X11Display.c
@@ -329,10 +329,10 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
char text[255];
// XEventsQueued(dpy, X):
- // QueuedAlready : No I/O Flush or system call doesn't work on some cards (eg ATI) ?)
+ // QueuedAlready == XQLength(): No I/O Flush or system call doesn't work on some cards (eg ATI) ?)
// QueuedAfterFlush == XPending(): I/O Flush only if no already queued events are available
// QueuedAfterReading : QueuedAlready + if queue==0, attempt to read more ..
- if ( 0 >= XPending(dpy) ) {
+ if ( 0 >= XEventsQueued(dpy, QueuedAfterFlush) ) {
// DBG_PRINT( "X11: DispatchMessages 0x%X - Leave 1\n", dpy);
return;
}
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 2e16e7cae..202ad6fff 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -701,7 +701,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom);
XDestroyWindow(dpy, w);
- XSync(dpy, False);
+ XSync(dpy, True); // discard all events now, no more handler
(*env)->DeleteGlobalRef(env, jwindow);
--
cgit v1.2.3
From ed596d9a329f1788979e148a4d09df7815ada527 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 8 Apr 2013 02:47:23 +0200
Subject: Bug 641 NEWT: X11 Deliver keyCode layout independent, keySym layout
dependent and UTF-16 keyChar value
On X11, the layout dependent keySym was not delivered [1],
as well as the UTF-8 to UTF-16 translation was missing [2].
[1] is solved using XLookupString w/o ShiftMask
[2] is solved using JNI's NewStringUTF, which takes UTF-8.
---
make/scripts/tests.sh | 6 +-
.../jogamp/newt/driver/x11/DisplayDriver.java | 16 +++--
.../jogamp/newt/driver/x11/WindowDriver.java | 16 +++--
src/newt/native/X11Display.c | 74 +++++++++++++++++-----
src/newt/native/X11Window.c | 4 +-
5 files changed, 83 insertions(+), 33 deletions(-)
(limited to 'src/newt/native/X11Window.c')
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index cb8abc8bf..eee4edec0 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -170,7 +170,7 @@ function jrun() {
#D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT -Djogl.debug.GLContext"
#D_ARGS="-Dnewt.debug.Window -Djogl.debug.Animator -Dnewt.debug.Screen"
#D_ARGS="-Dnativewindow.debug.JAWT -Dnewt.debug.Window"
- #D_ARGS="-Dnewt.debug.Window.KeyEvent"
+ D_ARGS="-Dnewt.debug.Window.KeyEvent"
#D_ARGS="-Dnewt.debug.Window.MouseEvent"
#D_ARGS="-Dnewt.debug.Window.MouseEvent -Dnewt.debug.Window.KeyEvent"
#D_ARGS="-Dnewt.debug.Window -Dnativewindow.debug=all"
@@ -276,7 +276,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestRedSquareES1NEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testawtswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasSWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $*
@@ -291,7 +291,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWTBug450 $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $*
-testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestTeapotNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestTeapotNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl3.newt.TestGeomShader01TextureGL3NEWT $*
#
diff --git a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
index f3a548a08..4fe025ec4 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/DisplayDriver.java
@@ -91,9 +91,10 @@ public class DisplayDriver extends DisplayImpl {
@Override
protected void closeNativeImpl() {
- DisplayRelease0(aDevice.getHandle(), javaObjectAtom, windowDeleteAtom);
+ DisplayRelease0(aDevice.getHandle(), javaObjectAtom, windowDeleteAtom /*, kbdHandle */); // XKB disabled for now
javaObjectAtom = 0;
windowDeleteAtom = 0;
+ // kbdHandle = 0;
aDevice.close(); // closes X11 display
}
@@ -103,7 +104,7 @@ public class DisplayDriver extends DisplayImpl {
try {
final long handle = aDevice.getHandle();
if(0 != handle) {
- DispatchMessages0(handle, javaObjectAtom, windowDeleteAtom);
+ DispatchMessages0(handle, javaObjectAtom, windowDeleteAtom /*, kbdHandle */); // XKB disabled for now
}
} finally {
if(null != aDevice) { // could be pulled by destroy event
@@ -114,6 +115,7 @@ public class DisplayDriver extends DisplayImpl {
protected long getJavaObjectAtom() { return javaObjectAtom; }
protected long getWindowDeleteAtom() { return windowDeleteAtom; }
+ // protected long getKbdHandle() { return kbdHandle; } // XKB disabled for now
/** Returns null if !{@link #isNativeValid()}, otherwise the Boolean value of {@link X11GraphicsDevice#isXineramaEnabled()}. */
protected Boolean isXineramaEnabled() { return isNativeValid() ? Boolean.valueOf(((X11GraphicsDevice)aDevice).isXineramaEnabled()) : null; }
@@ -126,18 +128,22 @@ public class DisplayDriver extends DisplayImpl {
private native void CompleteDisplay0(long handle);
- private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) {
+ private void displayCompleted(long javaObjectAtom, long windowDeleteAtom /*, long kbdHandle */) {
this.javaObjectAtom=javaObjectAtom;
this.windowDeleteAtom=windowDeleteAtom;
+ // this.kbdHandle = kbdHandle; // XKB disabled for now
}
- private native void DisplayRelease0(long handle, long javaObjectAtom, long windowDeleteAtom);
+ private native void DisplayRelease0(long handle, long javaObjectAtom, long windowDeleteAtom /*, long kbdHandle */); // XKB disabled for now
- private native void DispatchMessages0(long display, long javaObjectAtom, long windowDeleteAtom);
+ private native void DispatchMessages0(long display, long javaObjectAtom, long windowDeleteAtom /* , long kbdHandle */); // XKB disabled for now
/** X11 Window delete atom marker used on EDT */
private long windowDeleteAtom;
/** X11 Window java object property used on EDT */
private long javaObjectAtom;
+
+ /** X11 Keyboard handle used on EDT */
+ // private long kbdHandle; // XKB disabled for now
}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
index 8d33d4d73..666d0cb5b 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/WindowDriver.java
@@ -116,7 +116,7 @@ public class WindowDriver extends WindowImpl {
edtDevice.lock();
try {
CloseWindow0(edtDevice.getHandle(), windowHandleClose,
- display.getJavaObjectAtom(), display.getWindowDeleteAtom());
+ display.getJavaObjectAtom(), display.getWindowDeleteAtom() /* , display.getKbdHandle() */); // XKB disabled for now
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t);
@@ -271,13 +271,13 @@ public class WindowDriver extends WindowImpl {
super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotation);
}
- @Override
- public final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ protected final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar0, String keyString) {
// handleKeyEvent(true, false, eventType, modifiers, keyCode, keyChar);
final boolean isModifierKey = KeyEvent.isModifierKey(keyCode);
final boolean isAutoRepeat = 0 != ( KeyEvent.AUTOREPEAT_MASK & modifiers );
- // System.err.println("*** sendKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar+">, mods "+toHexString(modifiers)+
- // ", isKeyCodeTracked "+isKeyCodeTracked(keyCode)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isAutoRepeat+", [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis());
+ final char keyChar = ( null != keyString ) ? keyString.charAt(0) : keyChar0;
+ // System.err.println("*** sendKeyEvent: event "+KeyEvent.getEventTypeString(eventType)+", keyCode "+toHexString(keyCode)+", keyChar <"+keyChar0+">/<"+keyChar+">, keyString "+keyString+", mods "+toHexString(modifiers)+
+ // ", isKeyCodeTracked "+isKeyCodeTracked(keyCode)+", was: pressed "+isKeyPressed(keyCode)+", repeat "+isAutoRepeat+", [modifierKey "+isModifierKey+"] - "+System.currentTimeMillis());
if( !isAutoRepeat || !isModifierKey ) { // ! ( isModifierKey && isAutoRepeat )
switch(eventType) {
@@ -295,6 +295,10 @@ public class WindowDriver extends WindowImpl {
}
}
+ @Override
+ public final void sendKeyEvent(short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
+ throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
+ }
@Override
public final void enqueueKeyEvent(boolean wait, short eventType, int modifiers, short keyCode, short keySym, char keyChar) {
throw new InternalError("XXX: Adapt Java Code to Native Code Changes");
@@ -315,7 +319,7 @@ public class WindowDriver extends WindowImpl {
private native long CreateWindow0(long parentWindowHandle, long display, int screen_index,
int visualID, long javaObjectAtom, long windowDeleteAtom,
int x, int y, int width, int height, boolean autoPosition, int flags);
- private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom);
+ private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom /*, long kbdHandle*/ ); // XKB disabled for now
private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle,
long windowDeleteAtom, int x, int y, int width, int height, int flags);
private native void requestFocus0(long display, long windowHandle, boolean force);
diff --git a/src/newt/native/X11Display.c b/src/newt/native/X11Display.c
index d927b8069..a2df0d2e2 100644
--- a/src/newt/native/X11Display.c
+++ b/src/newt/native/X11Display.c
@@ -28,6 +28,8 @@
#include "X11Common.h"
+// #include // XKB disabled for now
+
jclass X11NewtWindowClazz = NULL;
jmethodID insetsChangedID = NULL;
jmethodID visibleChangedID = NULL;
@@ -223,6 +225,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_initIDs0
}
}
+ // displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJJ)V"); // Variant using XKB
displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJ)V");
getCurrentThreadNameID = (*env)->GetStaticMethodID(env, X11NewtWindowClazz, "getCurrentThreadName", "()Ljava/lang/String;");
dumpStackID = (*env)->GetStaticMethodID(env, X11NewtWindowClazz, "dumpStack", "()V");
@@ -235,7 +238,7 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_initIDs0
windowDestroyNotifyID = (*env)->GetMethodID(env, X11NewtWindowClazz, "windowDestroyNotify", "(Z)Z");
windowRepaintID = (*env)->GetMethodID(env, X11NewtWindowClazz, "windowRepaint", "(ZIIII)V");
sendMouseEventID = (*env)->GetMethodID(env, X11NewtWindowClazz, "sendMouseEvent", "(SIIISF)V");
- sendKeyEventID = (*env)->GetMethodID(env, X11NewtWindowClazz, "sendKeyEvent", "(SISSC)V");
+ sendKeyEventID = (*env)->GetMethodID(env, X11NewtWindowClazz, "sendKeyEvent", "(SISSCLjava/lang/String;)V");
requestFocusID = (*env)->GetMethodID(env, X11NewtWindowClazz, "requestFocus", "(Z)V");
if (displayCompletedID == NULL ||
@@ -270,6 +273,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_CompleteDisplay
Display * dpy = (Display *)(intptr_t)display;
jlong javaObjectAtom;
jlong windowDeleteAtom;
+ // jlong kbdHandle; // XKB disabled for now
if(dpy==NULL) {
NewtCommon_FatalError(env, "invalid display connection..");
@@ -288,10 +292,11 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_CompleteDisplay
}
// XSetCloseDownMode(dpy, RetainTemporary); // Just a try ..
+ // kbdHandle = (jlong) (intptr_t) XkbGetKeyboard(dpy, XkbAllComponentsMask, XkbUseCoreKbd); // XKB disabled for now
DBG_PRINT("X11: X11Display_completeDisplay dpy %p\n", dpy);
- (*env)->CallVoidMethod(env, obj, displayCompletedID, javaObjectAtom, windowDeleteAtom);
+ (*env)->CallVoidMethod(env, obj, displayCompletedID, javaObjectAtom, windowDeleteAtom /*, kbdHandle*/); // XKB disabled for now
}
/*
@@ -300,11 +305,12 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_CompleteDisplay
* Signature: (JJJ)V
*/
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DisplayRelease0
- (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong windowDeleteAtom)
+ (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/)
{
Display * dpy = (Display *)(intptr_t)display;
Atom wm_javaobject_atom = (Atom)javaObjectAtom;
Atom wm_delete_atom = (Atom)windowDeleteAtom;
+ // XkbDescPtr kbdDesc = (XkbDescPtr)(intptr_t)kbdHandle; // XKB disabled for now
if(dpy==NULL) {
NewtCommon_FatalError(env, "invalid display connection..");
@@ -314,6 +320,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DisplayRelease0
(void) wm_javaobject_atom;
(void) wm_delete_atom;
+ // XkbFreeKeyboard(kbdDesc, XkbAllNamesMask, True); // XKB disabled for now
+
XSync(dpy, True); // discard all pending events
DBG_PRINT("X11: X11Display_DisplayRelease dpy %p\n", dpy);
}
@@ -321,13 +329,14 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DisplayRelease0
/*
* Class: jogamp_newt_driver_x11_DisplayDriver
* Method: DispatchMessages
- * Signature: (JIJJ)V
+ * Signature: (JJJ)V
*/
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0
- (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong windowDeleteAtom)
+ (JNIEnv *env, jobject obj, jlong display, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/)
{
Display * dpy = (Display *) (intptr_t) display;
Atom wm_delete_atom = (Atom)windowDeleteAtom;
+ // XkbDescPtr kbdDesc = (XkbDescPtr)(intptr_t)kbdHandle; // XKB disabled for now
int num_events = 100;
int autoRepeatModifiers = 0;
@@ -335,6 +344,12 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
return;
}
+ /** XKB disabled for now
+ if( NULL == kbdDesc) {
+ NewtCommon_throwNewRuntimeException(env, "NULL kbd handle, bail out!");
+ return;
+ } */
+
// Periodically take a break
while( num_events > 0 ) {
jobject jwindow = NULL;
@@ -344,7 +359,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
jshort javaVKeyUS = 0;
jshort javaVKeyNN = 0;
jint modifiers = 0;
- char keyChar = 0;
+ uint16_t keyChar = 0;
+ jstring keyString = NULL;
char text[255];
// XEventsQueued(dpy, X):
@@ -403,23 +419,43 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
// fall through intended
case KeyPress: {
KeySym shiftedKeySym; // layout depending keySym w/ SHIFT
+ KeySym unShiftedKeySym; // layout depending keySym w/o SHIFT
+ unsigned int xkey_state = evt.xkey.state;
keyCode = evt.xkey.keycode;
- keySym = XkbKeycodeToKeysym(dpy, keyCode, 0 /* group */, 0 /* shift level */); // layout depending keySym w/o SHIFT
- if( XLookupString(&evt.xkey, text, 255, &shiftedKeySym, 0) == 1 ) {
- keyChar=text[0];
+ // Layout depending keySym w/o SHIFT,
+ // using fixed group 0 (US default layout)
+ //
+ // unsigned int mods_rtrn = 0;
+ // Bool res = XkbTranslateKeyCode (kbdDesc, keyCode, 0, &mods_rtrn, &keySym); // XKB disabled for now
+ // if( !res ) {
+ keySym = XkbKeycodeToKeysym(dpy, keyCode, 0 /* group */, 0 /* shift level */);
+ // }
+
+ text[0] = 0; text[1] = 0; text[2] = 0;
+ int charCount = XLookupString(&evt.xkey, text, 2, &shiftedKeySym, NULL);
+ if( 1 == charCount ) {
+ keyChar = 0x00FF & (uint16_t) (text[0]);
+ } else if( 2 == charCount ) {
+ // Example: UTF-16: 00DF, UTF-8: c3 9f, LATIN SMALL LETTER SHARP S
+ keyChar = ( 0x00FF & (uint16_t)(text[0]) ) << 8 | ( 0x00FF & (uint16_t)(text[1]) ); // UTF-16BE
+ keyString = (*env)->NewStringUTF(env, text);
}
- javaVKeyNN = X11KeySym2NewtVKey(keySym);
- javaVKeyUS = javaVKeyNN; // FIXME!
- modifiers |= X11InputState2NewtModifiers(evt.xkey.state, javaVKeyNN, evt.type == KeyPress) | autoRepeatModifiers;
+ evt.xkey.state = evt.xkey.state & ~ShiftMask; // clear shift
+ XLookupString(&evt.xkey, text, 0, &unShiftedKeySym, NULL);
+ // unShiftedKeySym = XLookupKeysym(&evt.xkey, 0 /* index ? */);
+
+ javaVKeyNN = X11KeySym2NewtVKey(unShiftedKeySym);
+ javaVKeyUS = X11KeySym2NewtVKey(keySym);
+ modifiers |= X11InputState2NewtModifiers(xkey_state, javaVKeyNN, evt.type == KeyPress) | autoRepeatModifiers;
#ifdef DEBUG_KEYS
- fprintf(stderr, "NEWT X11 Key: keyCode 0x%X keySym 0x%X (shifted: 0x%X), keyChar '%c', javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n",
- (int)keyCode, (int)keySym, (int)shiftedKeySym, keyChar,
+ fprintf(stderr, "NEWT X11 Key: keyCode 0x%X keySym 0x%X, (0x%X, shifted: 0x%X), keyChar '%c' 0x%X %d, javaVKey[US 0x%X, NN 0x%X], xstate 0x%X %u, jmods 0x%X\n",
+ (int)keyCode, (int)keySym, (int) unShiftedKeySym, (int)shiftedKeySym, keyChar, keyChar, charCount,
(int)javaVKeyUS, (int)javaVKeyNN,
- (int)evt.xkey.state, (int)evt.xkey.state, (int)modifiers);
+ (int)xkey_state, (int)xkey_state, (int)modifiers);
#endif
}
break;
@@ -463,13 +499,17 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessage
modifiers,
(jint) evt.xcrossing.x, (jint) evt.xcrossing.y, (jshort) 0, 0.0f /*rotation*/);
break;
+ case MappingNotify:
+ DBG_PRINT( "X11: event . MappingNotify call %p type %d\n", (void*)evt.xmapping.window, evt.xmapping.type);
+ XRefreshKeyboardMapping(&evt.xmapping);
+ break;
case KeyPress:
(*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jshort) EVENT_KEY_PRESSED,
- modifiers, javaVKeyUS, javaVKeyNN, (jchar) keyChar);
+ modifiers, javaVKeyUS, javaVKeyNN, (jchar) keyChar, keyString);
break;
case KeyRelease:
(*env)->CallVoidMethod(env, jwindow, sendKeyEventID, (jshort) EVENT_KEY_RELEASED,
- modifiers, javaVKeyUS, javaVKeyNN, (jchar) keyChar);
+ modifiers, javaVKeyUS, javaVKeyNN, (jchar) keyChar, keyString);
break;
case DestroyNotify:
DBG_PRINT( "X11: event . DestroyNotify call %p, parent %p, child-event: %d\n",
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index 202ad6fff..9e96169f5 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -671,7 +671,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CreateWindow0
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
- (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong windowDeleteAtom)
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jlong javaObjectAtom, jlong windowDeleteAtom /*, jlong kbdHandle*/) // XKB disabled for now
{
Display * dpy = (Display *) (intptr_t) display;
Window w = (Window)window;
@@ -698,7 +698,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_WindowDriver_CloseWindow0
XUnmapWindow(dpy, w);
// Drain all events related to this window ..
- Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom);
+ Java_jogamp_newt_driver_x11_DisplayDriver_DispatchMessages0(env, obj, display, javaObjectAtom, windowDeleteAtom /*, kbdHandle */); // XKB disabled for now
XDestroyWindow(dpy, w);
XSync(dpy, True); // discard all events now, no more handler
--
cgit v1.2.3
From 6ebf649d1b87944257fe492e0aef842d1b8debc2 Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Mon, 6 May 2013 17:27:09 +0200
Subject: Fix Bug 600 and Bug 721: Adding support for multiple monitors w/ NEWT
- Support for all monitor devices and their available modes
- X11: Use RandR 1.3 if available
- Retrieve information
- Changing a monitor device's mode
- Support for dedicated and spannig fullscreen
- See
- TODO:
- X11 RandR does _not_ relayout the virtual screen size
and neither the CRT's viewport.
We may need to relayout them if they were covering a seamless region
to achieve same experience!
- OSX: No machine to attach a secondary CRT -> TEST!
- Tested Manually for Regressions
- Linux ARMv6hf (Rasp-Pi/BCM, Panda/X11)
- Android (Huawei, Kindle)
- Tested Manually and junit:
- X11/Linux
- NV, ATI-Catalyst w/ 2 CRTs
- VBox w/ 4 CRTs
- Win/Windows
- NV, w/ 2 CRTs
- VBox w/ 4 CRTs
- X11/OpenIndiana, NV, 1 CRT
---
make/build-newt.xml | 1 +
make/scripts/java-win64-dbg.bat | 1 +
make/scripts/tests-x64.bat | 13 +-
make/scripts/tests.sh | 18 +-
.../javax/media/nativewindow/util/Dimension.java | 5 +
.../javax/media/nativewindow/util/Insets.java | 8 +
.../javax/media/nativewindow/util/Point.java | 4 +
.../javax/media/nativewindow/util/Rectangle.java | 86 ++-
.../nativewindow/util/RectangleImmutable.java | 20 +
.../javax/media/nativewindow/util/SurfaceSize.java | 4 +-
.../classes/com/jogamp/newt/MonitorDevice.java | 235 ++++++++
src/newt/classes/com/jogamp/newt/MonitorMode.java | 346 ++++++++++++
src/newt/classes/com/jogamp/newt/Screen.java | 93 ++--
src/newt/classes/com/jogamp/newt/ScreenMode.java | 208 -------
src/newt/classes/com/jogamp/newt/Window.java | 38 +-
.../com/jogamp/newt/event/MonitorEvent.java | 71 +++
.../com/jogamp/newt/event/MonitorModeListener.java | 37 ++
.../classes/com/jogamp/newt/event/NEWTEvent.java | 7 +-
.../classes/com/jogamp/newt/event/OutputEvent.java | 51 ++
.../com/jogamp/newt/event/ScreenModeListener.java | 39 --
.../classes/com/jogamp/newt/opengl/GLWindow.java | 13 +
.../classes/com/jogamp/newt/util/MonitorMode.java | 102 ----
.../com/jogamp/newt/util/MonitorModeUtil.java | 247 +++++++++
.../com/jogamp/newt/util/ScreenModeUtil.java | 341 ------------
.../classes/jogamp/newt/MonitorDeviceImpl.java | 147 +++++
src/newt/classes/jogamp/newt/MonitorModeProps.java | 355 ++++++++++++
src/newt/classes/jogamp/newt/OffscreenWindow.java | 13 +-
src/newt/classes/jogamp/newt/ScreenImpl.java | 569 ++++++++++----------
src/newt/classes/jogamp/newt/ScreenModeStatus.java | 231 --------
.../classes/jogamp/newt/ScreenMonitorState.java | 195 +++++++
src/newt/classes/jogamp/newt/WindowImpl.java | 201 +++++--
.../jogamp/newt/driver/android/ScreenDriver.java | 99 +++-
.../jogamp/newt/driver/android/WindowDriver.java | 16 +-
.../jogamp/newt/driver/awt/ScreenDriver.java | 24 +-
.../jogamp/newt/driver/bcm/egl/ScreenDriver.java | 56 +-
.../jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java | 56 +-
.../jogamp/newt/driver/intel/gdl/ScreenDriver.java | 56 +-
.../jogamp/newt/driver/kd/ScreenDriver.java | 54 +-
.../jogamp/newt/driver/macosx/ScreenDriver.java | 129 ++---
.../jogamp/newt/driver/macosx/WindowDriver.java | 15 +-
.../jogamp/newt/driver/windows/ScreenDriver.java | 146 +++--
src/newt/classes/jogamp/newt/driver/x11/RandR.java | 47 +-
.../classes/jogamp/newt/driver/x11/RandR11.java | 320 +++++++----
.../classes/jogamp/newt/driver/x11/RandR13.java | 276 +++++++++-
.../jogamp/newt/driver/x11/ScreenDriver.java | 146 +++--
src/newt/native/MacWindow.m | 235 ++++----
src/newt/native/NewtMacWindow.h | 1 -
src/newt/native/NewtMacWindow.m | 4 +-
src/newt/native/ScreenMode.h | 15 +-
src/newt/native/Window.h | 17 +-
src/newt/native/WindowsWindow.c | 305 ++++++++---
src/newt/native/X11RandR11.c | 44 +-
src/newt/native/X11RandR13.c | 597 ++++++++++++---------
src/newt/native/X11Screen.c | 31 +-
src/newt/native/X11Screen.h | 1 +
src/newt/native/X11Window.c | 18 +-
.../opengl/test/android/NEWTElektronActivity.java | 16 +-
.../opengl/test/android/NEWTGearsES1Activity.java | 16 +-
.../opengl/test/android/NEWTGearsES2Activity.java | 16 +-
.../test/android/NEWTGearsES2ActivityLauncher.java | 1 +
.../test/android/NEWTGearsES2TransActivity.java | 16 +-
.../opengl/test/android/NEWTGraphUI1pActivity.java | 16 +-
.../opengl/test/android/NEWTGraphUI2pActivity.java | 16 +-
.../test/android/NEWTRedSquareES1Activity.java | 16 +-
.../test/android/NEWTRedSquareES2Activity.java | 16 +-
.../jogl/demos/es2/newt/TestGearsES2NEWT.java | 16 +-
.../test/junit/jogl/glsl/TestRulerNEWT01.java | 16 +-
.../test/junit/newt/ManualScreenMode03NEWT.java | 32 +-
.../test/junit/newt/TestScreenMode00NEWT.java | 119 ++--
.../test/junit/newt/TestScreenMode00bNEWT.java | 24 +-
.../test/junit/newt/TestScreenMode01NEWT.java | 133 ++---
.../test/junit/newt/TestScreenMode01aNEWT.java | 212 ++++++++
.../test/junit/newt/TestScreenMode01bNEWT.java | 210 +++++---
.../test/junit/newt/TestScreenMode01cNEWT.java | 249 +++++++++
.../test/junit/newt/TestScreenMode02NEWT.java | 75 +--
75 files changed, 5159 insertions(+), 2463 deletions(-)
create mode 100644 src/newt/classes/com/jogamp/newt/MonitorDevice.java
create mode 100644 src/newt/classes/com/jogamp/newt/MonitorMode.java
delete mode 100644 src/newt/classes/com/jogamp/newt/ScreenMode.java
create mode 100644 src/newt/classes/com/jogamp/newt/event/MonitorEvent.java
create mode 100644 src/newt/classes/com/jogamp/newt/event/MonitorModeListener.java
create mode 100644 src/newt/classes/com/jogamp/newt/event/OutputEvent.java
delete mode 100644 src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java
delete mode 100644 src/newt/classes/com/jogamp/newt/util/MonitorMode.java
create mode 100644 src/newt/classes/com/jogamp/newt/util/MonitorModeUtil.java
delete mode 100644 src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java
create mode 100644 src/newt/classes/jogamp/newt/MonitorDeviceImpl.java
create mode 100644 src/newt/classes/jogamp/newt/MonitorModeProps.java
delete mode 100644 src/newt/classes/jogamp/newt/ScreenModeStatus.java
create mode 100644 src/newt/classes/jogamp/newt/ScreenMonitorState.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01aNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01cNEWT.java
(limited to 'src/newt/native/X11Window.c')
diff --git a/make/build-newt.xml b/make/build-newt.xml
index 862b78422..30c2ddfd1 100644
--- a/make/build-newt.xml
+++ b/make/build-newt.xml
@@ -593,6 +593,7 @@
+
diff --git a/make/scripts/java-win64-dbg.bat b/make/scripts/java-win64-dbg.bat
index 8669ba8f8..136fe4667 100755
--- a/make/scripts/java-win64-dbg.bat
+++ b/make/scripts/java-win64-dbg.bat
@@ -52,6 +52,7 @@ REM set D_ARGS="-Dnativewindow.debug.TraceLock"
REM set D_ARGS="-Dnewt.debug.Display" "-Dnewt.debug.EDT" "-Dnewt.debug.Window"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnewt.debug.Display" "-Dnewt.debug.EDT" "-Djogl.debug.GLContext"
REM set D_ARGS="-Dnewt.debug.Screen" "-Dnewt.debug.EDT" "-Dnativewindow.debug=all"
+REM set D_ARGS="-Dnewt.debug.Screen"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnewt.debug.Display" "-Dnewt.test.Window.reparent.incompatible=true"
REM set X_ARGS="-Dsun.java2d.noddraw=true" "-Dsun.java2d.opengl=true" "-Dsun.awt.noerasebackground=true"
diff --git a/make/scripts/tests-x64.bat b/make/scripts/tests-x64.bat
index 0133859fd..27ecfb2cc 100755
--- a/make/scripts/tests-x64.bat
+++ b/make/scripts/tests-x64.bat
@@ -55,7 +55,7 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.awt.TestIsReali
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT -time 30000
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT %*
-scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT %*
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT %*
REM scripts\java-win64.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT -vsync -time 4000 -x 10 -y 10 -width 100 -height 100 -screen 0
REM scripts\java-win64.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT -vsync -time 40000 -width 100 -height 100 -screen 0 %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT -time 5000
@@ -106,10 +106,13 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestFocus01Swin
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.nativewindow.TestRecursiveToolkitLockCORE
-REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode00NEWT
-REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode01NEWT
-REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT
-REM scripts\java-win64.bat com.jogamp.opengl.test.junit.newt.ManualScreenMode03NEWT
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode00NEWT %*
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode01aNEWT %*
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode01bNEWT %*
+scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode01cNEWT %*
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode01NEWT %*
+REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT %*
+REM scripts\java-win64.bat com.jogamp.opengl.test.junit.newt.ManualScreenMode03NEWT %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple %*
REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube %*
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index b53c2f760..c6f69ab74 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -135,6 +135,8 @@ function jrun() {
#D_ARGS="-Djogl.debug.EGLDisplayUtil -Dnativewindow.debug.GraphicsConfiguration -Djogl.debug.GLDrawable"
#D_ARGS="-Djogl.debug.EGLDisplayUtil -Dnativewindow.debug.X11Util"
#D_ARGS="-Djogl.debug.GLDrawable"
+ #D_ARGS="-Dnewt.debug.Screen"
+ #D_ARGS="-Dnewt.test.Screen.disableRandR13"
#D_ARGS="-Dnewt.test.Screen.disableScreenMode -Dnewt.debug.Screen"
#D_ARGS="-Dnewt.debug.Screen -Djogl.debug.Animator"
#D_ARGS="-Djogl.debug.ExtensionAvailabilityCache -Djogl.debug=all -Dnativewindow.debug=all -Djogamp.debug.ProcAddressHelper=true -Djogamp.debug.NativeLibrary=true -Djogamp.debug.NativeLibrary.Lookup=true"
@@ -284,7 +286,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $*
-testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestRedSquareES2NEWT $*
#testswt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasSWT $*
#testswt com.jogamp.opengl.test.junit.jogl.demos.es2.swt.TestGearsES2SWT $*
@@ -384,10 +386,12 @@ testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode00bNEWT
#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode01NEWT
-#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode01bNEWT
-#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT
-#testnoawt com.jogamp.opengl.test.junit.newt.ManualScreenMode03NEWT
-#testnoawt -Djava.awt.headless=true com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT
+#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode01aNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode01bNEWT $*
+testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode01cNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.newt.TestScreenMode02NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.newt.ManualScreenMode03NEWT $*
+#testnoawt -Djava.awt.headless=true com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT $*
#
# awt (testawt)
@@ -509,7 +513,9 @@ testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#
# Texture / TextureUtils
#
-#testawt com.jogamp.opengl.test.junit.jogl.util.texture.TestTexture01AWT
+#testawt com.jogamp.opengl.test.junit.jogl.util.texture.TestTexture01AWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.util.texture.TestTexture02AWT $*
+
#testnoawt com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGImage00NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGImage01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGJoglAWTCompareNewtAWT $*
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java
index 0a5a94565..4fae98f08 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java
@@ -57,7 +57,9 @@ public class Dimension implements Cloneable, DimensionImmutable {
}
}
+ @Override
public int getWidth() { return width; }
+ @Override
public int getHeight() { return height; }
public void setWidth(int width) {
@@ -77,10 +79,12 @@ public class Dimension implements Cloneable, DimensionImmutable {
return this;
}
+ @Override
public String toString() {
return new String(width+" x "+height);
}
+ @Override
public boolean equals(Object obj) {
if(this == obj) { return true; }
if (obj instanceof Dimension) {
@@ -91,6 +95,7 @@ public class Dimension implements Cloneable, DimensionImmutable {
return false;
}
+ @Override
public int hashCode() {
// 31 * x == (x << 5) - x
int hash = 31 + width;
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java
index 199ec27cb..f22668f55 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java
@@ -57,11 +57,17 @@ public class Insets implements Cloneable, InsetsImmutable {
}
}
+ @Override
public final int getLeftWidth() { return l; }
+ @Override
public final int getRightWidth() { return r; }
+ @Override
public final int getTotalWidth() { return l + r; }
+ @Override
public final int getTopHeight() { return t; }
+ @Override
public final int getBottomHeight() { return b; }
+ @Override
public final int getTotalHeight() { return t + b; }
public void setLeftWidth(int left) { l = left; }
@@ -69,6 +75,7 @@ public class Insets implements Cloneable, InsetsImmutable {
public void setTopHeight(int top) { t = top; }
public void setBottomHeight(int bottom) { b = bottom; }
+ @Override
public boolean equals(Object obj) {
if(this == obj) { return true; }
if (obj instanceof Insets) {
@@ -79,6 +86,7 @@ public class Insets implements Cloneable, InsetsImmutable {
return false;
}
+ @Override
public int hashCode() {
int sum1 = l + b;
int sum2 = t + r;
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java
index c53b16928..8e6caf72b 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java
@@ -54,6 +54,7 @@ public class Point implements Cloneable, PointImmutable {
}
}
+ @Override
public boolean equals(Object obj) {
if(this == obj) { return true; }
if (obj instanceof Point) {
@@ -63,14 +64,17 @@ public class Point implements Cloneable, PointImmutable {
return false;
}
+ @Override
public final int getX() {
return x;
}
+ @Override
public final int getY() {
return y;
}
+ @Override
public int hashCode() {
// 31 * x == (x << 5) - x
int hash = 31 + x;
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java
index 8d6bfe48f..8e6fc8e36 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java
@@ -28,6 +28,8 @@
package javax.media.nativewindow.util;
+import java.util.List;
+
public class Rectangle implements Cloneable, RectangleImmutable {
int x;
int y;
@@ -57,15 +59,90 @@ public class Rectangle implements Cloneable, RectangleImmutable {
}
}
+ @Override
public final int getX() { return x; }
+ @Override
public final int getY() { return y; }
+ @Override
public final int getWidth() { return width; }
+ @Override
public final int getHeight() { return height; }
- public void setX(int x) { this.x = x; }
- public void setY(int y) { this.y = y; }
- public void setWidth(int width) { this.width = width; }
- public void setHeight(int height) { this.height = height; }
+
+ public final void setX(int x) { this.x = x; }
+ public final void setY(int y) { this.y = y; }
+ public final void setWidth(int width) { this.width = width; }
+ public final void setHeight(int height) { this.height = height; }
+ @Override
+ public final RectangleImmutable union(final RectangleImmutable r) {
+ return union(r.getX(), r.getY(), r.getX() + r.getWidth(), r.getY() + r.getHeight());
+ }
+ @Override
+ public final RectangleImmutable union(final int rx1, final int ry1, final int rx2, final int ry2) {
+ final int x1 = Math.min(x, rx1);
+ final int y1 = Math.min(y, ry1);
+ final int x2 = Math.max(x + width, rx2);
+ final int y2 = Math.max(y + height, ry2);
+ return new Rectangle(x1, y1, x2 - x1, y2 - y1);
+ }
+ /**
+ * Calculates the union of the given rectangles, stores it in this instance and returns this instance.
+ * @param rectangles given list of rectangles
+ * @return this instance holding the union of given rectangles.
+ */
+ public final Rectangle union(final List rectangles) {
+ int x1=Integer.MAX_VALUE, y1=Integer.MAX_VALUE;
+ int x2=Integer.MIN_VALUE, y2=Integer.MIN_VALUE;
+ for(int i=rectangles.size()-1; i>=0; i--) {
+ final RectangleImmutable vp = rectangles.get(i);
+ x1 = Math.min(x1, vp.getX());
+ x2 = Math.max(x2, vp.getX() + vp.getWidth());
+ y1 = Math.min(y1, vp.getY());
+ y2 = Math.max(y2, vp.getY() + vp.getHeight());
+ }
+ setX(x1);
+ setY(y1);
+ setWidth(x2 - x1);
+ setHeight(y2 - y1);
+ return this;
+ }
+
+ @Override
+ public final RectangleImmutable intersection(RectangleImmutable r) {
+ return intersection(r.getX(), r.getY(), r.getX() + r.getWidth(), r.getY() + r.getHeight());
+ }
+ @Override
+ public final RectangleImmutable intersection(final int rx1, final int ry1, final int rx2, final int ry2) {
+ final int x1 = Math.max(x, rx1);
+ final int y1 = Math.max(y, ry1);
+ final int x2 = Math.min(x + width, rx2);
+ final int y2 = Math.min(y + height, ry2);
+ final int ix, iy, iwidth, iheight;
+ if( x2 < x1 ) {
+ ix = 0;
+ iwidth = 0;
+ } else {
+ ix = x1;
+ iwidth = x2 - x1;
+ }
+ if( y2 < y1 ) {
+ iy = 0;
+ iheight = 0;
+ } else {
+ iy = y1;
+ iheight = y2 - y1;
+ }
+ return new Rectangle (ix, iy, iwidth, iheight);
+ }
+ @Override
+ public final float coverage(RectangleImmutable r) {
+ final RectangleImmutable isect = intersection(r);
+ final float sqI = (float) ( isect.getWidth()*isect.getHeight() );
+ final float sqT = (float) ( width*height );
+ return sqI / sqT;
+ }
+
+ @Override
public boolean equals(Object obj) {
if(this == obj) { return true; }
if (obj instanceof Rectangle) {
@@ -76,6 +153,7 @@ public class Rectangle implements Cloneable, RectangleImmutable {
return false;
}
+ @Override
public int hashCode() {
int sum1 = x + height;
int sum2 = width + y;
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/RectangleImmutable.java b/src/nativewindow/classes/javax/media/nativewindow/util/RectangleImmutable.java
index d3b43c864..7531989de 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/RectangleImmutable.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/RectangleImmutable.java
@@ -41,6 +41,26 @@ public interface RectangleImmutable extends WriteCloneable {
int getY();
+ /** Returns the union of this rectangle and the given rectangle. */
+ RectangleImmutable union(final RectangleImmutable r);
+ /** Returns the union of this rectangleand the given coordinates. */
+ RectangleImmutable union(final int rx1, final int ry1, final int rx2, final int ry2);
+ /** Returns the intersection of this rectangleand the given rectangle. */
+ RectangleImmutable intersection(RectangleImmutable r);
+ /** Returns the intersection of this rectangleand the given coordinates. */
+ RectangleImmutable intersection(final int rx1, final int ry1, final int rx2, final int ry2);
+ /**
+ * Returns the coverage of given rectangle w/ this this one, i.e. between 0.0 and 1.0.
+ *
+ *
+ */
+ float coverage(RectangleImmutable r);
+
/**
* Checks whether two rect objects are equal. Two instances
* of Rectangle are equal if the four integer values
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java b/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java
index 8f21bc49b..d7e451af8 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java
@@ -36,8 +36,8 @@ package javax.media.nativewindow.util;
*
*/
public class SurfaceSize {
- DimensionImmutable resolution;
- int bitsPerPixel;
+ final DimensionImmutable resolution;
+ final int bitsPerPixel;
public SurfaceSize(DimensionImmutable resolution, int bitsPerPixel) {
if(null==resolution || bitsPerPixel<=0) {
diff --git a/src/newt/classes/com/jogamp/newt/MonitorDevice.java b/src/newt/classes/com/jogamp/newt/MonitorDevice.java
new file mode 100644
index 000000000..fbe4d8cf0
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/MonitorDevice.java
@@ -0,0 +1,235 @@
+/**
+ * Copyright 2013 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 java.util.List;
+
+import javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.RectangleImmutable;
+
+import com.jogamp.common.util.ArrayHashSet;
+
+/**
+ * Visual output device, i.e. a CRT, LED ..consisting of it's components:
+ *
+ *
Immutable
+ *
+ *
nativeId
+ *
{@link DimensionImmutable} size in [mm]
+ *
{@link MonitorMode} original mode
+ *
List<MonitorMode> supportedModes
+ *
+ *
Mutable
+ *
+ *
{@link MonitorMode} current mode
+ *
{@link RectangleImmutable} viewport (rotated)
+ *
+ *
+ */
+public abstract class MonitorDevice {
+ protected final Screen screen; // backref
+ protected final int nativeId; // unique monitor device ID
+ protected final DimensionImmutable sizeMM; // in [mm]
+ protected final MonitorMode originalMode;
+ protected final ArrayHashSet supportedModes; // FIXME: May need to support mutable mode, i.e. adding modes on the fly!
+ protected MonitorMode currentMode;
+ protected boolean modeChanged;
+ protected Rectangle viewport;
+
+ protected MonitorDevice(Screen screen, int nativeId, DimensionImmutable sizeMM, Rectangle viewport, MonitorMode currentMode, ArrayHashSet supportedModes) {
+ this.screen = screen;
+ this.nativeId = nativeId;
+ this.sizeMM = sizeMM;
+ this.originalMode = currentMode;
+ this.supportedModes = supportedModes;
+ this.currentMode = currentMode;
+ this.viewport = viewport;
+ this.modeChanged = false;
+ }
+
+ /** Returns the {@link Screen} owning this monitor. */
+ public final Screen getScreen() {
+ return screen;
+ }
+
+ /**
+ * Tests equality of two MonitorDevice objects
+ * by evaluating equality of it's components:
+ *
+ *
nativeID
+ *
+ *
+ */
+ public final boolean equals(Object obj) {
+ if (this == obj) { return true; }
+ if (obj instanceof MonitorDevice) {
+ MonitorDevice md = (MonitorDevice)obj;
+ return md.nativeId == nativeId;
+ }
+ return false;
+ }
+
+ /**
+ * Returns a combined hash code of it's elements:
+ *
+ *
nativeID
+ *
+ */
+ public final int hashCode() {
+ return nativeId;
+ }
+
+ /** @return the immutable unique native Id of this monitor device. */
+ public final int getId() { return nativeId; }
+
+ /**
+ * @return the immutable monitor size in millimeters.
+ */
+ public final DimensionImmutable getSizeMM() {
+ return sizeMM;
+ }
+
+ /**
+ * Return the immutable original {@link com.jogamp.newt.MonitorMode}, as used at NEWT initialization.
+ * @return original {@link MonitorMode} which is element of the list {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}.
+ */
+ public final MonitorMode getOriginalMode() {
+ return originalMode;
+ }
+
+ /**
+ * FIXME: May need to support mutable mode, i.e. adding modes on the fly!
+ * @return the immutable list of {@link MonitorMode}s supported by this monitor. Use w/ care, it's not a copy!
+ */
+ public final List getSupportedModes() {
+ return supportedModes.getData();
+ }
+
+ /** @return the {@link RectangleImmutable rectangular} portion of the rotated virtual {@link Screen} size represented by this monitor. */
+ public final RectangleImmutable getViewport() {
+ return viewport;
+ }
+
+ /** Returns true if given coordinates are contained by this {@link #getViewport() viewport}, otherwise false. */
+ public final boolean contains(int x, int y) {
+ return x >= viewport.getX() &&
+ x < viewport.getX() + viewport.getWidth() &&
+ y >= viewport.getY() &&
+ y < viewport.getY() + viewport.getHeight() ;
+ }
+
+ /**
+ * Returns the coverage of given rectangle w/ this this {@link #getViewport() viewport}, i.e. between 0.0 and 1.0.
+ *
+ *
+ */
+ public final float coverage(RectangleImmutable r) {
+ return viewport.coverage(r);
+ }
+
+ /**
+ * Returns the union of the given monitor's {@link #getViewport() viewport}.
+ * @param result storage for result, will be returned
+ * @param monitors given list of monitors
+ * @return viewport representing the union of given monitor's viewport.
+ */
+ public static Rectangle unionOfViewports(final Rectangle result, final List monitors) {
+ int x1=Integer.MAX_VALUE, y1=Integer.MAX_VALUE;
+ int x2=Integer.MIN_VALUE, y2=Integer.MIN_VALUE;
+ for(int i=monitors.size()-1; i>=0; i--) {
+ final RectangleImmutable vp = monitors.get(i).getViewport();
+ x1 = Math.min(x1, vp.getX());
+ x2 = Math.max(x2, vp.getX() + vp.getWidth());
+ y1 = Math.min(y1, vp.getY());
+ y2 = Math.max(y2, vp.getY() + vp.getHeight());
+ }
+ result.setX(x1);
+ result.setY(y1);
+ result.setWidth(x2 - x1);
+ result.setHeight(y2 - y1);
+ return result;
+ }
+
+ public final boolean isOriginalMode() {
+ return currentMode.hashCode() == originalMode.hashCode();
+ }
+
+ /**
+ * Returns true if the {@link MonitorMode}
+ * has been changed programmatic via this API only, otherwise false.
+ *
+ * Note: We cannot guarantee that we won't interfere w/ another running
+ * application's screen mode change or vice versa.
+ *
+ */
+ public final boolean isModeChangedByUs() {
+ return modeChanged && !isOriginalMode();
+ }
+
+ /**
+ * Return the current cached {@link MonitorMode} w/o native query.
+ *
+ * If {@link MonitorMode}s are not supported for this
+ * native type {@link com.jogamp.newt.Display#getType()}, it returns one with the current screen size.
+ *
+ * @return current {@link MonitorMode} which is element of the list {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}.
+ */
+ public final MonitorMode getCurrentMode() {
+ return currentMode;
+ }
+
+ /**
+ * Return the current {@link MonitorMode} including a native query.
+ *
+ * If {@link MonitorMode}s are not supported for this
+ * native type {@link com.jogamp.newt.Display#getType()}, it returns one with the current screen size.
+ *
+ * @return current {@link MonitorMode} which is element of the list {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}.
+ */
+ public abstract MonitorMode queryCurrentMode();
+
+ /**
+ * Set the current {@link com.jogamp.newt.MonitorMode}.
+ * @param mode to be made current, must be element of the list {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}.
+ * @return true if successful, otherwise false
+ */
+ public abstract boolean setCurrentMode(MonitorMode mode);
+
+ public String toString() {
+ return "Monitor[Id "+Display.toHexString(nativeId)+", "+sizeMM+" mm, viewport "+viewport+ ", orig "+originalMode+", curr "+currentMode+
+ ", modeChanged "+modeChanged+", modeCount "+supportedModes.size()+"]";
+ }
+}
+
diff --git a/src/newt/classes/com/jogamp/newt/MonitorMode.java b/src/newt/classes/com/jogamp/newt/MonitorMode.java
new file mode 100644
index 000000000..e5b329d47
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/MonitorMode.java
@@ -0,0 +1,346 @@
+/**
+ * Copyright 2013 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 javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.SurfaceSize;
+
+
+/** Immutable MonitorMode Class, consisting of it's read only components:
+ *
+ *
nativeId
+ *
{@link SizeAndRRate}, non rotated surfaceSize and refreshRate
+ *
rotation, measured counter clockwise (CCW)
+ *
+ *
+ * Aquire and filter MonitorMode
+ *
+ *
A List of read only MonitorModes is being returned by {@link com.jogamp.newt.Screen#getMonitorModes()}.
+ *
You may utilize {@link com.jogamp.newt.util.MonitorModeUtil} to filter and select a desired ScreenMode.
+ *
The current ScreenMode can be obtained via {@link com.jogamp.newt.Screen#getCurrentScreenMode()}.
+ *
The initial original ScreenMode (at startup) can be obtained via {@link com.jogamp.newt.Screen#getOriginalScreenMode()}.
Use {@link com.jogamp.newt.Screen#setCurrentScreenMode(com.jogamp.newt.MonitorMode)}
+ * to change the current ScreenMode of all Screen's referenced via the full qualified name (FQN)
+ * {@link com.jogamp.newt.Screen#getFQName()}.
+ *
When the last FQN referenced Screen closes, the original ScreenMode ({@link com.jogamp.newt.Screen#getOriginalScreenMode()})
+ * is restored.
+ *
+ *
+ * Example for changing the ScreenMode:
+ *
+ // determine target refresh rate
+ ScreenMode orig = screen.getOriginalScreenMode();
+ int freq = orig.getOutputMode().getRefreshRate();
+
+ // target resolution
+ Dimension res = new Dimension(800, 600);
+
+ // target rotation
+ int rot = 0;
+
+ // filter available ScreenModes
+ List screenModes = screen.getScreenModes();
+ screenModes = ScreenModeUtil.filterByRate(screenModes, freq); // get the nearest ones
+ screenModes = ScreenModeUtil.filterByRotation(screenModes, rot);
+ screenModes = ScreenModeUtil.filterByResolution(screenModes, res); // get the nearest ones
+ screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
+
+ // pick 1st one ..
+ screen.setCurrentScreenMode((ScreenMode) screenModes.get(0));
+ *
+ *
+ * X11 / AMD just works
+ *
+ * X11 / NVidia difficulties
+ *
+ NVidia RANDR RefreshRate Bug
+ If NVidia's 'DynamicTwinView' is enabled, all refresh rates are
+ unique, ie consequent numbers starting with the default refresh, ie 50, 51, ..
+ The only way to workaround it is to disable 'DynamicTwinView'.
+ Read: http://us.download.nvidia.com/XFree86/Linux-x86/260.19.12/README/configtwinview.html
+
+ Check to see if 'DynamicTwinView' is enable:
+ nvidia-settings -q :0/DynamicTwinview
+
+ To disable it (workaround), add the following option to your xorg.conf device section:
+ Option "DynamicTwinView" "False"
+
+ NVidia RANDR Rotation:
+ To enable it, add the following option to your xorg.conf device section:
+ Option "RandRRotation" "on"
+ *
+ *
+ */
+public class MonitorMode {
+ /**
+ * Immutable surfaceSize and refreshRate Class, consisting of it's read only components:
+ *
+ *
nativeId
+ *
{@link SurfaceSize} surface memory size
+ *
refresh rate
+ *
+ */
+ public static class SizeAndRRate {
+ public final SurfaceSize surfaceSize;
+ public final float refreshRate;
+ public final int flags;
+ public final int hashCode;
+
+ public SizeAndRRate(SurfaceSize surfaceSize, float refreshRate, int flags) {
+ if(null==surfaceSize) {
+ throw new IllegalArgumentException("surfaceSize must be set ("+surfaceSize+")");
+ }
+ this.surfaceSize=surfaceSize;
+ this.refreshRate=refreshRate;
+ this.flags = flags;
+ this.hashCode = getHashCode();
+ }
+
+ private final static String STR_INTERLACE = "Interlace";
+ private final static String STR_DOUBLESCAN = "DoubleScan";
+ private final static String STR_SEP = ", ";
+
+ public static final StringBuffer flags2String(int flags) {
+ final StringBuffer sb = new StringBuffer();
+ boolean sp = false;
+ if( 0 != ( flags & FLAG_INTERLACE ) ) {
+ sb.append(STR_INTERLACE);
+ sp = true;
+ }
+ if( 0 != ( flags & FLAG_DOUBLESCAN ) ) {
+ if( sp ) {
+ sb.append(STR_SEP);
+ }
+ sb.append(STR_DOUBLESCAN);
+ sp = true;
+ }
+ return sb;
+ }
+ public final String toString() {
+ return new String(surfaceSize+" @ "+refreshRate+" Hz, flags ["+flags2String(flags).toString()+"]");
+ }
+
+ /**
+ * Tests equality of two {@link SizeAndRRate} objects
+ * by evaluating equality of it's components:
+ *
+ *
surfaceSize
+ *
refreshRate
+ *
flags
+ *
+ */
+ public final boolean equals(Object obj) {
+ if (this == obj) { return true; }
+ if (obj instanceof SizeAndRRate) {
+ final SizeAndRRate p = (SizeAndRRate)obj;
+ return surfaceSize.equals(p.surfaceSize) &&
+ refreshRate == p.refreshRate &&
+ flags == p.flags ;
+ }
+ return false;
+ }
+
+ /**
+ * Returns a combined hash code of it's elements:
+ *
+ *
surfaceSize
+ *
refreshRate
+ *
flags
+ *
+ */
+ public final int hashCode() {
+ return hashCode;
+ }
+ private final int getHashCode() {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + surfaceSize.hashCode();
+ hash = ((hash << 5) - hash) + (int)(refreshRate*100.0f);
+ hash = ((hash << 5) - hash) + flags;
+ return hash;
+ }
+ }
+
+ /** zero rotation, compared to normal settings */
+ public static final int ROTATE_0 = 0;
+
+ /** 90 degrees CCW rotation */
+ public static final int ROTATE_90 = 90;
+
+ /** 180 degrees CCW rotation */
+ public static final int ROTATE_180 = 180;
+
+ /** 270 degrees CCW rotation */
+ public static final int ROTATE_270 = 270;
+
+ /** Frame is split into two fields. See {@link #getFlags()}. */
+ public static final int FLAG_INTERLACE = 1 << 0;
+
+ /** Lines are doubled. See {@link #getFlags()}. */
+ public static final int FLAG_DOUBLESCAN = 1 << 1;
+
+ /** The immutable native Id of this instance, which may not be unique. */
+ private final int nativeId;
+ private final SizeAndRRate sizeAndRRate;
+ private final int rotation;
+ private final int hashCode;
+
+ public static boolean isRotationValid(int rotation) {
+ return rotation == MonitorMode.ROTATE_0 || rotation == MonitorMode.ROTATE_90 ||
+ rotation == MonitorMode.ROTATE_180 || rotation == MonitorMode.ROTATE_270 ;
+ }
+
+ /**
+ * @param sizeAndRRate the surface size and refresh rate mode
+ * @param rotation the screen rotation, measured counter clockwise (CCW)
+ */
+ public MonitorMode(int nativeId, SizeAndRRate sizeAndRRate, int rotation) {
+ if ( !isRotationValid(rotation) ) {
+ throw new RuntimeException("invalid rotation: "+rotation);
+ }
+ this.nativeId = nativeId;
+ this.sizeAndRRate = sizeAndRRate;
+ this.rotation = rotation;
+ this.hashCode = getHashCode();
+ }
+
+ /**
+ * Creates a user instance w/o {@link #getId() identity} to filter our matching modes w/ identity.
+ *
+ * See {@link com.jogamp.newt.util.MonitorModeUtil} for filter utilities.
+ *
+ * @param surfaceSize
+ * @param refreshRate
+ * @param flags
+ * @param rotation
+ */
+ public MonitorMode(SurfaceSize surfaceSize, float refreshRate, int flags, int rotation) {
+ this(0, new SizeAndRRate(surfaceSize, refreshRate, flags), rotation);
+ }
+
+ /** @return the immutable native Id of this mode, may not be unique, may be 0. */
+ public final int getId() { return nativeId; }
+
+ /** Returns the surfaceSize and refreshRate instance. */
+ public final SizeAndRRate getSizeAndRRate() {
+ return sizeAndRRate;
+ }
+
+ /** Returns the unrotated {@link SurfaceSize} */
+ public final SurfaceSize getSurfaceSize() {
+ return sizeAndRRate.surfaceSize;
+ }
+
+ public final float getRefreshRate() {
+ return sizeAndRRate.refreshRate;
+ }
+
+ /** Returns bitfield w/ flags, i.e. {@link #FLAG_DOUBLESCAN}, {@link #FLAG_INTERLACE}, .. */
+ public final int getFlags() {
+ return sizeAndRRate.flags;
+ }
+
+ /** Returns the CCW rotation of this mode */
+ public final int getRotation() {
+ return rotation;
+ }
+
+ /** Returns the rotated screen width,
+ * derived from getMonitorMode().getSurfaceSize().getResolution()
+ * and getRotation()
+ */
+ public final int getRotatedWidth() {
+ return getRotatedWH(true);
+ }
+
+ /** Returns the rotated screen height,
+ * derived from getMonitorMode().getSurfaceSize().getResolution()
+ * and getRotation()
+ */
+ public final int getRotatedHeight() {
+ return getRotatedWH(false);
+ }
+
+ public final String toString() {
+ return "[Id "+Display.toHexString(nativeId)+", " + sizeAndRRate + ", " + rotation + " degr]";
+ }
+
+ /**
+ * Tests equality of two {@link MonitorMode} objects
+ * by evaluating equality of it's components:
+ *
+ *
nativeId
+ *
sizeAndRRate
+ *
rotation
+ *
+ */
+ public final boolean equals(Object obj) {
+ if (this == obj) { return true; }
+ if (obj instanceof MonitorMode) {
+ MonitorMode sm = (MonitorMode)obj;
+ return sm.nativeId == this.nativeId &&
+ sm.sizeAndRRate.equals(sizeAndRRate) &&
+ sm.rotation == this.rotation ;
+ }
+ return false;
+ }
+
+ /**
+ * Returns a combined hash code of it's elements:
+ *
+ *
nativeId
+ *
sizeAndRRate
+ *
rotation
+ *
+ */
+ public final int hashCode() {
+ return hashCode;
+ }
+ private final int getHashCode() {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + getId();
+ hash = ((hash << 5) - hash) + sizeAndRRate.hashCode();
+ hash = ((hash << 5) - hash) + getRotation();
+ return hash;
+ }
+
+ private final int getRotatedWH(boolean width) {
+ final DimensionImmutable d = sizeAndRRate.surfaceSize.getResolution();
+ final boolean swap = MonitorMode.ROTATE_90 == rotation || MonitorMode.ROTATE_270 == rotation ;
+ if ( ( width && swap ) || ( !width && !swap ) ) {
+ return d.getHeight();
+ }
+ return d.getWidth();
+ }
+}
diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java
index a09748d52..81a62d898 100644
--- a/src/newt/classes/com/jogamp/newt/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/Screen.java
@@ -27,14 +27,19 @@
*/
package com.jogamp.newt;
-import com.jogamp.newt.event.ScreenModeListener;
+import com.jogamp.newt.event.MonitorModeListener;
import jogamp.newt.Debug;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.RectangleImmutable;
+/**
+ * A screen may span multiple {@link MonitorDevice}s representing their combined virtual size.
+ */
public abstract class Screen {
/**
@@ -122,25 +127,30 @@ public abstract class Screen {
public abstract int getIndex();
/**
- * @return the x position of the virtual top-left origin.
+ * @return the x position of the virtual viewport's top-left origin.
*/
public abstract int getX();
/**
- * @return the y position of the virtual top-left origin.
+ * @return the y position of the virtual viewport's top-left origin.
*/
public abstract int getY();
/**
- * @return the rotated virtual width.
+ * @return the rotated virtual viewport's width.
*/
public abstract int getWidth();
/**
- * @return the rotated virtual height.
+ * @return the rotated virtual viewport's height.
*/
public abstract int getHeight();
+ /**
+ * @return the rotated virtual viewport, i.e. origin and size.
+ */
+ public abstract RectangleImmutable getViewport();
+
/**
* @return the associated Display
*/
@@ -152,48 +162,68 @@ public abstract class Screen {
*/
public abstract String getFQName();
- /**
- * @param sml ScreenModeListener to be added for ScreenMode change events
- */
- public abstract void addScreenModeListener(ScreenModeListener sml);
-
- /**
- * @param sml ScreenModeListener to be removed from ScreenMode change events
+ /**
+ * Return a list of all available {@link MonitorMode}s for all {@link MonitorDevice}s.
+ *
+ * If {@link com.jogamp.newt.MonitorMode ScreenMode}s are not supported for this
+ * native type {@link com.jogamp.newt.Display#getType()}, it returns a list of size one with the current screen size.
*/
- public abstract void removeScreenModeListener(ScreenModeListener sml);
+ public abstract List getMonitorModes();
/**
- * Return a list of available {@link com.jogamp.newt.ScreenMode ScreenMode}s.
+ * Return a list of all available {@link MonitorDevice}s.
*
- * If {@link com.jogamp.newt.ScreenMode ScreenMode}s are not supported for this
+ * If {@link com.jogamp.newt.MonitorMode ScreenMode}s are not supported for this
* native type {@link com.jogamp.newt.Display#getType()}, it returns a list of size one with the current screen size.
- *
- * @return a shallow copy of the internal immutable {@link com.jogamp.newt.ScreenMode ScreenMode}s.
*/
- public abstract List getScreenModes();
+ public abstract List getMonitorDevices();
/**
- * Return the original {@link com.jogamp.newt.ScreenMode}, as used at NEWT initialization.
- * @return original ScreenMode which is element of the list {@link #getScreenModes()}.
+ * Returns the {@link MonitorDevice} which {@link MonitorDevice#getViewport() viewport}
+ * {@link MonitorDevice#coverage(RectangleImmutable) covers} the given rectangle the most.
+ *
+ * If no coverage is detected the first {@link MonitorDevice} is returned.
+ *
*/
- public abstract ScreenMode getOriginalScreenMode();
+ public final MonitorDevice getMainMonitor(RectangleImmutable r) {
+ MonitorDevice res = null;
+ float maxCoverage = Float.MIN_VALUE;
+ final List monitors = getMonitorDevices();
+ for(int i=monitors.size()-1; i>=0; i--) {
+ final MonitorDevice monitor = monitors.get(i);
+ final float coverage = monitor.coverage(r);
+ if( coverage > maxCoverage ) {
+ maxCoverage = coverage;
+ res = monitor;
+ }
+ }
+ if( maxCoverage > 0.0f && null != res ) {
+ return res;
+ }
+ return monitors.get(0);
+ }
/**
- * Return the current {@link com.jogamp.newt.ScreenMode}.
+ * Returns the union of all monitor's {@link MonitorDevice#getViewport() viewport}.
*
- * If {@link com.jogamp.newt.ScreenMode ScreenMode}s are not supported for this
- * native type {@link com.jogamp.newt.Display#getType()}, it returns one with the current screen size.
- *
- * @return current ScreenMode which is element of the list {@link #getScreenModes()}.
+ * Should be equal to {@link #getX()}, {@link #getY()}, {@link #getWidth()} and {@link #getHeight()},
+ * however, some native toolkits may choose a different virtual screen area.
+ *
+ * @param result storage for result, will be returned
+ */
+ public final Rectangle unionOfMonitorViewportSize(final Rectangle result) {
+ return MonitorDevice.unionOfViewports(result, getMonitorDevices());
+ }
+
+ /**
+ * @param sml {@link MonitorModeListener} to be added for {@link MonitorEvent}
*/
- public abstract ScreenMode getCurrentScreenMode();
+ public abstract void addMonitorModeListener(MonitorModeListener sml);
/**
- * Set the current {@link com.jogamp.newt.ScreenMode}.
- * @param screenMode to be made current, must be element of the list {@link #getScreenModes()}.
- * @return true if successful, otherwise false
+ * @param sml {@link MonitorModeListener} to be removed from {@link MonitorEvent}
*/
- public abstract boolean setCurrentScreenMode(ScreenMode screenMode);
+ public abstract void removeMonitorModeListener(MonitorModeListener sml);
// Global Screens
protected static ArrayList screenList = new ArrayList();
@@ -236,6 +266,7 @@ public abstract class Screen {
return null;
}
/** Returns the global display collection */
+ @SuppressWarnings("unchecked")
public static Collection getAllScreens() {
ArrayList list;
synchronized(screenList) {
diff --git a/src/newt/classes/com/jogamp/newt/ScreenMode.java b/src/newt/classes/com/jogamp/newt/ScreenMode.java
deleted file mode 100644
index 1f12217bb..000000000
--- a/src/newt/classes/com/jogamp/newt/ScreenMode.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/**
- * 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 javax.media.nativewindow.util.DimensionImmutable;
-
-import com.jogamp.newt.util.MonitorMode;
-
-/** Immutable ScreenMode Class, consisting of it's read only components:
- *
- *
{@link com.jogamp.newt.util.MonitorMode}, non rotated values
- *
rotation, measured counter clockwise (CCW)
- *
- *
- * Aquire and filter ScreenModes
- *
- *
A List of read only ScreenMode's is being returned by {@link com.jogamp.newt.Screen#getScreenModes()}.
- *
You may utilize {@link com.jogamp.newt.util.ScreenModeUtil} to filter and select a desired ScreenMode.
- *
The current ScreenMode can be obtained via {@link com.jogamp.newt.Screen#getCurrentScreenMode()}.
- *
The initial original ScreenMode (at startup) can be obtained via {@link com.jogamp.newt.Screen#getOriginalScreenMode()}.
- *
- *
- *
- * Changing ScreenModes
- *
- *
Use {@link com.jogamp.newt.Screen#setCurrentScreenMode(com.jogamp.newt.ScreenMode)}
- * to change the current ScreenMode of all Screen's referenced via the full qualified name (FQN)
- * {@link com.jogamp.newt.Screen#getFQName()}.
- *
When the last FQN referenced Screen closes, the original ScreenMode ({@link com.jogamp.newt.Screen#getOriginalScreenMode()})
- * is restored.
- *
- *
- * Example for changing the ScreenMode:
- *
- // determine target refresh rate
- ScreenMode orig = screen.getOriginalScreenMode();
- int freq = orig.getMonitorMode().getRefreshRate();
-
- // target resolution
- Dimension res = new Dimension(800, 600);
-
- // target rotation
- int rot = 0;
-
- // filter available ScreenModes
- List screenModes = screen.getScreenModes();
- screenModes = ScreenModeUtil.filterByRate(screenModes, freq); // get the nearest ones
- screenModes = ScreenModeUtil.filterByRotation(screenModes, rot);
- screenModes = ScreenModeUtil.filterByResolution(screenModes, res); // get the nearest ones
- screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes);
-
- // pick 1st one ..
- screen.setCurrentScreenMode((ScreenMode) screenModes.get(0));
- *
- *
- * X11 / AMD just works
- *
- * X11 / NVidia difficulties
- *
- NVidia RANDR RefreshRate Bug
- If NVidia's 'DynamicTwinView' is enabled, all refresh rates are
- unique, ie consequent numbers starting with the default refresh, ie 50, 51, ..
- The only way to workaround it is to disable 'DynamicTwinView'.
- Read: http://us.download.nvidia.com/XFree86/Linux-x86/260.19.12/README/configtwinview.html
-
- Check to see if 'DynamicTwinView' is enable:
- nvidia-settings -q :0/DynamicTwinview
-
- To disable it (workaround), add the following option to your xorg.conf device section:
- Option "DynamicTwinView" "False"
-
- NVidia RANDR Rotation:
- To enable it, add the following option to your xorg.conf device section:
- Option "RandRRotation" "on"
- *
- *
- */
-public class ScreenMode {
- /** zero rotation, compared to normal settings */
- public static final int ROTATE_0 = 0;
-
- /** 90 degrees CCW rotation */
- public static final int ROTATE_90 = 90;
-
- /** 180 degrees CCW rotation */
- public static final int ROTATE_180 = 180;
-
- /** 270 degrees CCW rotation */
- public static final int ROTATE_270 = 270;
-
- MonitorMode monitorMode;
- int rotation;
-
- public static boolean isRotationValid(int rotation) {
- return rotation == ScreenMode.ROTATE_0 || rotation == ScreenMode.ROTATE_90 ||
- rotation == ScreenMode.ROTATE_180 || rotation == ScreenMode.ROTATE_270 ;
- }
-
- /**
- * @param monitorMode the monitor mode
- * @param rotation the screen rotation, measured counter clockwise (CCW)
- */
- public ScreenMode(MonitorMode monitorMode, int rotation) {
- if ( !isRotationValid(rotation) ) {
- throw new RuntimeException("invalid rotation: "+rotation);
- }
- this.monitorMode = monitorMode;
- this.rotation = rotation;
- }
-
- /** Returns the unrotated MonitorMode */
- public final MonitorMode getMonitorMode() {
- return monitorMode;
- }
-
- /** Returns the CCW rotation of this mode */
- public final int getRotation() {
- return rotation;
- }
-
- /** Returns the rotated screen width,
- * derived from getMonitorMode().getSurfaceSize().getResolution()
- * and getRotation()
- */
- public final int getRotatedWidth() {
- return getRotatedWH(true);
- }
-
- /** Returns the rotated screen height,
- * derived from getMonitorMode().getSurfaceSize().getResolution()
- * and getRotation()
- */
- public final int getRotatedHeight() {
- return getRotatedWH(false);
- }
-
- public final String toString() {
- return "[ " + getMonitorMode() + ", " + rotation + " degr ]";
- }
-
- /**
- * Tests equality of two ScreenMode objects
- * by evaluating equality of it's components:
- *
- *
monitorMode
- *
rotation
- *
- *
- */
- public final boolean equals(Object obj) {
- if (this == obj) { return true; }
- if (obj instanceof ScreenMode) {
- ScreenMode sm = (ScreenMode)obj;
- return sm.getMonitorMode().equals(getMonitorMode()) &&
- sm.getRotation() == this.getRotation() ;
- }
- return false;
- }
-
- /**
- * Returns a combined hash code of it's elements:
- *
- *
monitorMode
- *
rotation
- *
- */
- public final int hashCode() {
- // 31 * x == (x << 5) - x
- int hash = 31 + getMonitorMode().hashCode();
- hash = ((hash << 5) - hash) + getRotation();
- return hash;
- }
-
- private final int getRotatedWH(boolean width) {
- final DimensionImmutable d = getMonitorMode().getSurfaceSize().getResolution();
- final boolean swap = ScreenMode.ROTATE_90 == rotation || ScreenMode.ROTATE_270 == rotation ;
- if ( ( width && swap ) || ( !width && !swap ) ) {
- return d.getHeight();
- }
- return d.getWidth();
- }
-}
diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java
index ab1eef308..0bebf330a 100644
--- a/src/newt/classes/com/jogamp/newt/Window.java
+++ b/src/newt/classes/com/jogamp/newt/Window.java
@@ -28,6 +28,8 @@
package com.jogamp.newt;
+import java.util.List;
+
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.event.KeyListener;
@@ -41,6 +43,7 @@ import javax.media.nativewindow.CapabilitiesChooser;
import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.WindowClosingProtocol;
+import javax.media.nativewindow.util.RectangleImmutable;
/**
* Specifying NEWT's Window functionality:
@@ -80,10 +83,19 @@ public interface Window extends NativeWindow, WindowClosingProtocol {
boolean isNativeValid();
/**
- * @return The associated Screen
+ * @return The associated {@link Screen}
*/
Screen getScreen();
+ /**
+ * Returns the {@link MonitorDevice} which {@link MonitorDevice#getViewport() viewport}
+ * {@link MonitorDevice#coverage(RectangleImmutable) covers} this window the most.
+ *
+ * If no coverage is detected the first {@link MonitorDevice} is returned.
+ *
+ */
+ MonitorDevice getMainMonitor();
+
/**
* Set the CapabilitiesChooser to help determine the native visual type.
*
@@ -344,8 +356,32 @@ public interface Window extends NativeWindow, WindowClosingProtocol {
ReparentOperation reparentWindow(NativeWindow newParent, boolean forceDestroyCreate);
+ /**
+ * Enable or disable fullscreen mode for this window.
+ *
+ * Fullscreen mode is established on the {@link #getMainMonitor() main monitor}.
+ *
+ * @param fullscreen enable or disable fullscreen mode
+ * @return success
+ * @see #setFullscreen(List)
+ * @see #isFullscreen()
+ */
boolean setFullscreen(boolean fullscreen);
+ /**
+ * Enable fullscreen mode for this window spanning across the given {@link MonitorDevice}s
+ * or across all {@link MonitorDevice}s.
+ *
+ * Disable fullscreen via {@link #setFullscreen(boolean)}.
+ *
+ * @param monitors if null fullscreen will be spanned across all {@link MonitorDevice}s,
+ * otherwise across the given list of {@link MonitorDevice}.
+ * @return success
+ * @see #setFullscreen(boolean)
+ * @see #isFullscreen()
+ */
+ boolean setFullscreen(List monitors);
+
boolean isFullscreen();
static interface FocusRunnable {
diff --git a/src/newt/classes/com/jogamp/newt/event/MonitorEvent.java b/src/newt/classes/com/jogamp/newt/event/MonitorEvent.java
new file mode 100644
index 000000000..c47936a7a
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/event/MonitorEvent.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright 2013 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.event;
+
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+
+@SuppressWarnings("serial")
+public class MonitorEvent extends OutputEvent {
+ public static final short EVENT_MONITOR_MODE_CHANGE_NOTIFY = 600;
+ public static final short EVENT_MONITOR_MODE_CHANGED = 601;
+
+ private final MonitorMode mode;
+
+ public MonitorEvent (short eventType, MonitorDevice source, long when, MonitorMode mode) {
+ super(eventType, source, when);
+ this.mode = mode;
+ }
+
+ /** Returns the {@link #getSource() source}, which is a {@link MonitorDevice}. */
+ public final MonitorDevice getMonitor() { return (MonitorDevice)source; }
+
+ public final MonitorMode getMode() { return mode; }
+
+ public static String getEventTypeString(short type) {
+ switch(type) {
+ case EVENT_MONITOR_MODE_CHANGE_NOTIFY: return "EVENT_MONITOR_MODE_CHANGE_NOTIFY";
+ case EVENT_MONITOR_MODE_CHANGED: return "EVENT_MONITOR_MODE_CHANGED";
+ default: return "unknown (" + type + ")";
+ }
+ }
+
+ public final String toString() {
+ return toString(null).toString();
+ }
+
+ public final StringBuilder toString(StringBuilder sb) {
+ if(null == sb) {
+ sb = new StringBuilder();
+ }
+ sb.append("MonitorEvent[").append(getEventTypeString(getEventType())).append(", source ").append(source)
+ .append(", mode ").append(mode).append(", ");
+ return super.toString(sb).append("]");
+ }
+}
diff --git a/src/newt/classes/com/jogamp/newt/event/MonitorModeListener.java b/src/newt/classes/com/jogamp/newt/event/MonitorModeListener.java
new file mode 100644
index 000000000..11e23def1
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/event/MonitorModeListener.java
@@ -0,0 +1,37 @@
+/**
+ * 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.event;
+
+public interface MonitorModeListener {
+ /** called before the monitor mode will be changed */
+ void monitorModeChangeNotify(MonitorEvent me);
+
+ /** called after the monitor mode has been changed */
+ void monitorModeChanged(MonitorEvent me, boolean success);
+}
diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
index ea96f634f..c1bc791d8 100644
--- a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
+++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java
@@ -41,9 +41,10 @@ package com.jogamp.newt.event;
*
* Event type registry:
*
- *
WindowEvent 100..10x
- *
MouseEvent 200..20x
- *
KeyEvent 300..30x
+ *
WindowEvent 100..10x
+ *
MouseEvent 200..20x
+ *
KeyEvent 300..30x
+ *
MonitorEvent 600..60x
*
*/
@SuppressWarnings("serial")
diff --git a/src/newt/classes/com/jogamp/newt/event/OutputEvent.java b/src/newt/classes/com/jogamp/newt/event/OutputEvent.java
new file mode 100644
index 000000000..86fa95877
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/event/OutputEvent.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2013 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.event;
+
+@SuppressWarnings("serial")
+public abstract class OutputEvent extends NEWTEvent
+{
+ protected OutputEvent(short eventType, Object source, long when) {
+ super(eventType, source, when);
+ }
+
+ /**
+ public String toString() {
+ return toString(null).toString();
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ if(null == sb) {
+ sb = new StringBuilder();
+ }
+ sb.append("OutputEvent[");
+ super.toString(sb).append("]");
+ return sb;
+ } */
+}
diff --git a/src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java b/src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java
deleted file mode 100644
index 7bca23cfe..000000000
--- a/src/newt/classes/com/jogamp/newt/event/ScreenModeListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.event;
-
-import com.jogamp.newt.ScreenMode;
-
-public interface ScreenModeListener {
- /** called before the screen mode will be changed */
- void screenModeChangeNotify(ScreenMode sm);
-
- /** called after the screen mode has been changed */
- void screenModeChanged(ScreenMode sm, boolean success);
-}
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index de62747be..1500d48e6 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -34,6 +34,8 @@
package com.jogamp.newt.opengl;
+import java.util.List;
+
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.CapabilitiesChooser;
import javax.media.nativewindow.CapabilitiesImmutable;
@@ -64,6 +66,7 @@ import jogamp.opengl.GLDrawableImpl;
import com.jogamp.common.GlueGenVersion;
import com.jogamp.common.util.VersionUtil;
import com.jogamp.common.util.locks.RecursiveLock;
+import com.jogamp.newt.MonitorDevice;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
import com.jogamp.newt.Window;
@@ -224,6 +227,11 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind
return window.getScreen();
}
+ @Override
+ public final MonitorDevice getMainMonitor() {
+ return window.getMainMonitor();
+ }
+
@Override
public final void setTitle(String title) {
window.setTitle(title);
@@ -341,6 +349,11 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind
public final boolean setFullscreen(boolean fullscreen) {
return window.setFullscreen(fullscreen);
}
+
+ @Override
+ public boolean setFullscreen(List monitors) {
+ return window.setFullscreen(monitors);
+ }
@Override
public final boolean isFullscreen() {
diff --git a/src/newt/classes/com/jogamp/newt/util/MonitorMode.java b/src/newt/classes/com/jogamp/newt/util/MonitorMode.java
deleted file mode 100644
index 8104f207a..000000000
--- a/src/newt/classes/com/jogamp/newt/util/MonitorMode.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * 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.util;
-
-import javax.media.nativewindow.util.*;
-
-/** Immutable MonitorMode Class, consisting of it's read only components:
- *
{@link javax.media.nativewindow.util.DimensionImmutable} size in [mm]
- *
refresh rate
- *
- */
-public class MonitorMode {
- SurfaceSize surfaceSize;
- DimensionImmutable screenSizeMM; // in [mm]
- int refreshRate;
-
- public MonitorMode(SurfaceSize surfaceSize, DimensionImmutable screenSizeMM, int refreshRate) {
- // Don't validate screenSizeMM and refreshRate, since they may not be supported by the OS
- if(null==surfaceSize) {
- throw new IllegalArgumentException("surfaceSize must be set ("+surfaceSize+")");
- }
- this.surfaceSize=surfaceSize;
- this.screenSizeMM=screenSizeMM;
- this.refreshRate=refreshRate;
- }
-
- public final SurfaceSize getSurfaceSize() {
- return surfaceSize;
- }
-
- public final DimensionImmutable getScreenSizeMM() {
- return screenSizeMM;
- }
-
- public final int getRefreshRate() {
- return refreshRate;
- }
-
- public final String toString() {
- return new String("[ "+surfaceSize+" x "+refreshRate+" Hz, "+screenSizeMM+" mm ]");
- }
-
- /**
- * Checks whether two size objects are equal. Two instances
- * of MonitorMode are equal if the three components
- * surfaceSize and refreshRate
- * are equal. screenSizeMM is kept out intentional to reduce the requirements for finding the current mode.
- * @return true if the two dimensions are equal;
- * otherwise false.
- */
- public final boolean equals(Object obj) {
- if (this == obj) { return true; }
- if (obj instanceof MonitorMode) {
- MonitorMode p = (MonitorMode)obj;
- return getSurfaceSize().equals(p.getSurfaceSize()) &&
- /* getScreenSizeMM().equals(p.getScreenSizeMM()) && */
- getRefreshRate() == p.getRefreshRate() ;
- }
- return false;
- }
-
- /**
- * returns a hash code over surfaceSize and refreshRate.
- * screenSizeMM is kept out intentional to reduce the requirements for finding the current mode.
- */
- public final int hashCode() {
- // 31 * x == (x << 5) - x
- int hash = 31 + getSurfaceSize().hashCode();
- /* hash = ((hash << 5) - hash) + getScreenSizeMM().hashCode(); */
- hash = ((hash << 5) - hash) + getRefreshRate();
- return hash;
- }
-}
-
diff --git a/src/newt/classes/com/jogamp/newt/util/MonitorModeUtil.java b/src/newt/classes/com/jogamp/newt/util/MonitorModeUtil.java
new file mode 100644
index 000000000..16ffe754f
--- /dev/null
+++ b/src/newt/classes/com/jogamp/newt/util/MonitorModeUtil.java
@@ -0,0 +1,247 @@
+/**
+ * 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.util;
+
+import com.jogamp.newt.MonitorMode;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.SurfaceSize;
+
+/**
+ * Convenient {@link com.jogamp.newt.MonitorMode} utility methods,
+ * filters etc.
+ */
+public class MonitorModeUtil {
+
+ public static int getIndex(List monitorModes, MonitorMode search) {
+ return monitorModes.indexOf(search);
+ }
+
+ public static int getIndexByHashCode(List monitorModes, MonitorMode search) {
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; i monitorModes, MonitorMode.SizeAndRRate sizeAndRate, int modeId, int rotation) {
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; i filterBySurfaceSize(List monitorModes, SurfaceSize surfaceSize) {
+ final List out = new ArrayList();
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; null!=monitorModes && i filterByRotation(List monitorModes, int rotation) {
+ final List out = new ArrayList();
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; null!=monitorModes && i filterByBpp(List monitorModes, int bitsPerPixel) {
+ final List out = new ArrayList();
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; null!=monitorModes && i filterByFlags(List monitorModes, int flags) {
+ final List out = new ArrayList();
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; null!=monitorModes && i filterByResolution(List monitorModes, DimensionImmutable resolution) {
+ final List out = new ArrayList();
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ final int resolution_sq = resolution.getHeight()*resolution.getWidth();
+ int mode_dsq=Integer.MAX_VALUE, mode_dsq_idx=0;
+
+ for (int i=0; null!=monitorModes && i filterByRate(List monitorModes, float refreshRate) {
+ final List out = new ArrayList();
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ float mode_dr = Float.MAX_VALUE;
+ int mode_dr_idx = -1;
+ for (int i=0; null!=monitorModes && i getHighestAvailableBpp(List monitorModes) {
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ int highest = -1;
+ for (int i=0; null!=monitorModes && i < monitorModes.size(); i++) {
+ final MonitorMode mode = monitorModes.get(i);
+ final int bpp = mode.getSurfaceSize().getBitsPerPixel();
+ if (bpp > highest) {
+ highest = bpp;
+ }
+ }
+ return filterByBpp(monitorModes, highest);
+ }
+ return new ArrayList();
+ }
+
+ /**
+ *
+ * @param monitorModes
+ * @return modes with highest available refresh rate. May return zero sized list for non.
+ */
+ public static List getHighestAvailableRate(List monitorModes) {
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ float highest = -1;
+ for (int i=0; null!=monitorModes && i < monitorModes.size(); i++) {
+ final MonitorMode mode = monitorModes.get(i);
+ final float rate = mode.getRefreshRate();
+ if (rate > highest) {
+ highest = rate;
+ }
+ }
+ return filterByRate(monitorModes, highest);
+ }
+ return new ArrayList();
+ }
+
+}
diff --git a/src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java b/src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java
deleted file mode 100644
index 93797c5fb..000000000
--- a/src/newt/classes/com/jogamp/newt/util/ScreenModeUtil.java
+++ /dev/null
@@ -1,341 +0,0 @@
-/**
- * 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.util;
-
-import com.jogamp.common.util.ArrayHashSet;
-import com.jogamp.newt.ScreenMode;
-import java.util.ArrayList;
-import java.util.List;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.DimensionImmutable;
-import javax.media.nativewindow.util.SurfaceSize;
-
-/**
- * Convenient {@link com.jogamp.newt.ScreenMode} utility methods,
- * filters etc.
- */
-public class ScreenModeUtil {
- /** WARNING: must be synchronized with ScreenMode.h, native implementation
- * 2: width and height
- */
- public static final int NUM_RESOLUTION_PROPERTIES = 2;
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation
- * 1: bpp
- */
- public static final int NUM_SURFACE_SIZE_PROPERTIES = 1;
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation
- * 3: ScreenSizeMM[width, height], refresh-rate
- */
- public static final int NUM_MONITOR_MODE_PROPERTIES = 3;
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation
- * 1: rotation, native_mode_id
- */
- public static final int NUM_SCREEN_MODE_PROPERTIES = 1;
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation
- * count + all the above
- */
- public static final int NUM_SCREEN_MODE_PROPERTIES_ALL = 8;
-
- public static int getIndex(List screenModes, ScreenMode search) {
- return screenModes.indexOf(search);
- }
-
- public static int getIndexByHashCode(List screenModes, ScreenMode search) {
- for (int i=0; null!=screenModes && i filterByResolution(List screenModes, DimensionImmutable resolution) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- List out = new ArrayList();
- int resolution_sq = resolution.getHeight()*resolution.getWidth();
- int sm_dsq=resolution_sq, sm_dsq_idx=0;
-
- for (int i=0; null!=screenModes && i0) {
- return out;
- }
- // nearest ..
- resolution = screenModes.get(sm_dsq_idx).getMonitorMode().getSurfaceSize().getResolution();
- return filterByResolution(screenModes, resolution);
- }
-
- public static List filterBySurfaceSize(List screenModes, SurfaceSize surfaceSize) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- List out = new ArrayList();
- for (int i=0; null!=screenModes && i0 ? out : null;
- }
-
- public static List filterByRotation(List screenModes, int rotation) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- List out = new ArrayList();
- for (int i=0; null!=screenModes && i0 ? out : null;
- }
-
- public static List filterByBpp(List screenModes, int bitsPerPixel) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- List out = new ArrayList();
- for (int i=0; null!=screenModes && i0 ? out : null;
- }
-
- /**
- *
- * @param screenModes
- * @param refreshRate
- * @return modes with nearest refreshRate, or matching ones
- */
- public static List filterByRate(List screenModes, int refreshRate) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- int sm_dr = refreshRate;
- int sm_dr_idx = -1;
- List out = new ArrayList();
- for (int i=0; null!=screenModes && i0) {
- return out;
- }
- refreshRate = screenModes.get(sm_dr_idx).getMonitorMode().getRefreshRate();
- return filterByRate(screenModes, refreshRate);
- }
-
- public static List getHighestAvailableBpp(List screenModes) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- int highest = -1;
- for (int i=0; null!=screenModes && i < screenModes.size(); i++) {
- ScreenMode sm = screenModes.get(i);
- int bpp = sm.getMonitorMode().getSurfaceSize().getBitsPerPixel();
- if (bpp > highest) {
- highest = bpp;
- }
- }
- return filterByBpp(screenModes, highest);
- }
-
- public static List getHighestAvailableRate(List screenModes) {
- if(null==screenModes || screenModes.size()==0) {
- return null;
- }
- int highest = -1;
- for (int i=0; null!=screenModes && i < screenModes.size(); i++) {
- ScreenMode sm = screenModes.get(i);
- int rate = sm.getMonitorMode().getRefreshRate();
- if (rate > highest) {
- highest = rate;
- }
- }
- return filterByRate(screenModes, highest);
- }
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation */
- public static DimensionImmutable streamInResolution(int[] resolutionProperties, int offset) {
- Dimension resolution = new Dimension(resolutionProperties[offset++], resolutionProperties[offset++]);
- return resolution;
- }
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation */
- public static SurfaceSize streamInSurfaceSize(DimensionImmutable resolution, int[] sizeProperties, int offset) {
- SurfaceSize surfaceSize = new SurfaceSize(resolution, sizeProperties[offset++]);
- return surfaceSize;
- }
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation */
- public static MonitorMode streamInMonitorMode(SurfaceSize surfaceSize, DimensionImmutable screenSizeMM, int[] monitorProperties, int offset) {
- int refreshRate = monitorProperties[offset++];
- return new MonitorMode(surfaceSize, screenSizeMM, refreshRate);
- }
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation */
- public static ScreenMode streamInScreenMode(MonitorMode monitorMode, int[] modeProperties, int offset) {
- int rotation = modeProperties[offset++];
- return new ScreenMode(monitorMode, rotation);
- }
-
- /**
- * WARNING: must be synchronized with ScreenMode.h, native implementation
- *
- * @param modeProperties the input data
- * @param offset the offset to the input data
- * @return ScreenMode element matching the input modeProperties,
- * or null if input could not be processed.
- */
- public static ScreenMode streamIn(int[] modeProperties, int offset) {
- return streamInImpl(null, null, null, null, null, modeProperties, offset);
- }
-
- /**
- * WARNING: must be synchronized with ScreenMode.h, native implementation
- *
- * @param resolutionPool hash array of unique resolutions, no duplicates
- * @param surfaceSizePool hash array of unique SurfaceSize, no duplicates
- * @param monitorModePool hash array of unique MonitorMode, no duplicates
- * @param screenModePool hash array of unique ScreenMode, no duplicates
- * @param modeProperties the input data
- * @param offset the offset to the input data
- * @return index of the identical (old or new) ScreenMode element in screenModePool,
- * matching the input modeProperties, or -1 if input could not be processed.
- */
- public static int streamIn(ArrayHashSet resolutionPool,
- ArrayHashSet surfaceSizePool,
- ArrayHashSet screenSizeMMPool,
- ArrayHashSet monitorModePool,
- ArrayHashSet screenModePool,
- int[] modeProperties, int offset) {
- ScreenMode screenMode = streamInImpl(resolutionPool, surfaceSizePool, screenSizeMMPool, monitorModePool, screenModePool,
- modeProperties, offset);
- return screenModePool.indexOf(screenMode);
- }
-
-
- private static ScreenMode streamInImpl(ArrayHashSet resolutionPool,
- ArrayHashSet surfaceSizePool,
- ArrayHashSet screenSizeMMPool,
- ArrayHashSet monitorModePool,
- ArrayHashSet screenModePool,
- int[] modeProperties, int offset) {
- int count = modeProperties[offset];
- if(NUM_SCREEN_MODE_PROPERTIES_ALL != count) {
- throw new RuntimeException("NUM_SCREEN_MODE_PROPERTIES should be "+NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+count+", len "+(modeProperties.length-offset));
- }
- if(NUM_SCREEN_MODE_PROPERTIES_ALL > modeProperties.length-offset) {
- throw new RuntimeException("properties array too short, should be >= "+NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+(modeProperties.length-offset));
- }
- offset++;
- DimensionImmutable resolution = ScreenModeUtil.streamInResolution(modeProperties, offset);
- offset += ScreenModeUtil.NUM_RESOLUTION_PROPERTIES;
- if(null!=resolutionPool) {
- resolution = resolutionPool.getOrAdd(resolution);
- }
-
- SurfaceSize surfaceSize = ScreenModeUtil.streamInSurfaceSize(resolution, modeProperties, offset);
- offset += ScreenModeUtil.NUM_SURFACE_SIZE_PROPERTIES;
- if(null!=surfaceSizePool) {
- surfaceSize = surfaceSizePool.getOrAdd(surfaceSize);
- }
-
- DimensionImmutable screenSizeMM = ScreenModeUtil.streamInResolution(modeProperties, offset);
- offset += ScreenModeUtil.NUM_RESOLUTION_PROPERTIES;
- if(null!=screenSizeMMPool) {
- screenSizeMM = screenSizeMMPool.getOrAdd(screenSizeMM);
- }
-
- MonitorMode monitorMode = ScreenModeUtil.streamInMonitorMode(surfaceSize, screenSizeMM, modeProperties, offset);
- offset += ScreenModeUtil.NUM_MONITOR_MODE_PROPERTIES - ScreenModeUtil.NUM_RESOLUTION_PROPERTIES;
- if(null!=monitorModePool) {
- monitorMode = monitorModePool.getOrAdd(monitorMode);
- }
-
- ScreenMode screenMode = ScreenModeUtil.streamInScreenMode(monitorMode, modeProperties, offset);
- if(null!=screenModePool) {
- screenMode = screenModePool.getOrAdd(screenMode);
- }
- return screenMode;
- }
-
- /** WARNING: must be synchronized with ScreenMode.h, native implementation */
- public static int[] streamOut (ScreenMode screenMode) {
- int[] data = new int[NUM_SCREEN_MODE_PROPERTIES_ALL];
- int idx=0;
- data[idx++] = NUM_SCREEN_MODE_PROPERTIES_ALL;
- data[idx++] = screenMode.getMonitorMode().getSurfaceSize().getResolution().getWidth();
- data[idx++] = screenMode.getMonitorMode().getSurfaceSize().getResolution().getHeight();
- data[idx++] = screenMode.getMonitorMode().getSurfaceSize().getBitsPerPixel();
- data[idx++] = screenMode.getMonitorMode().getScreenSizeMM().getWidth();
- data[idx++] = screenMode.getMonitorMode().getScreenSizeMM().getHeight();
- data[idx++] = screenMode.getMonitorMode().getRefreshRate();
- data[idx++] = screenMode.getRotation();
- if(NUM_SCREEN_MODE_PROPERTIES_ALL != idx) {
- throw new InternalError("wrong number of attributes: got "+idx+" != should "+NUM_SCREEN_MODE_PROPERTIES_ALL);
- }
- return data;
- }
-
-}
diff --git a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java
new file mode 100644
index 000000000..96daed54a
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java
@@ -0,0 +1,147 @@
+/**
+ * Copyright 2013 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 jogamp.newt;
+
+import javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.Rectangle;
+
+import com.jogamp.common.util.ArrayHashSet;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+import com.jogamp.newt.Screen;
+
+public class MonitorDeviceImpl extends MonitorDevice {
+
+ public MonitorDeviceImpl(ScreenImpl screen, int nativeId, DimensionImmutable sizeMM, Rectangle viewport, MonitorMode currentMode, ArrayHashSet supportedModes) {
+ super(screen, nativeId, sizeMM, viewport, currentMode, supportedModes);
+ }
+
+ @Override
+ public final MonitorMode queryCurrentMode() {
+ final ScreenImpl screenImpl = (ScreenImpl)screen;
+ final ScreenMonitorState sms = screenImpl.getScreenMonitorStatus(true);
+ sms.lock();
+ try {
+ final MonitorMode mm0 = screenImpl.queryCurrentMonitorModeIntern(this);
+ if(null == mm0) {
+ throw new InternalError("getCurrentMonitorModeIntern() == null");
+ }
+ MonitorMode mmU = supportedModes.get(mm0); // unified instance
+ if( null == mmU ) {
+ // add new mode avoiding exception!
+ mmU = sms.getMonitorModes().getOrAdd(mm0);
+ mmU = supportedModes.getOrAdd(mmU);
+ if( Screen.DEBUG ) {
+ System.err.println("Adding new mode: "+mm0+" -> "+mmU);
+ }
+ }
+ // if mode has changed somehow, update it ..
+ if( getCurrentMode().hashCode() != mmU.hashCode() ) {
+ setCurrentModeValue(mmU);
+ sms.fireScreenModeChanged(this, mmU, true);
+ }
+ return mmU;
+ } finally {
+ sms.unlock();
+ }
+ }
+
+ @Override
+ public final boolean setCurrentMode(MonitorMode mode) {
+ if(Screen.DEBUG) {
+ System.err.println("Screen.setCurrentScreenMode.0: "+this+" -> "+mode);
+ }
+ final ScreenImpl screenImpl = (ScreenImpl)screen;
+ final ScreenMonitorState sms = screenImpl.getScreenMonitorStatus(true);
+ sms.lock();
+ try {
+ final MonitorMode mmC = queryCurrentMode();
+ final MonitorMode mmU = supportedModes.get(mode); // unify via value hash
+ if( null == mmU ) {
+ throw new IllegalArgumentException("Given mode not in set of modes. Current mode "+mode+", "+this);
+ }
+ if( mmU.equals( mmC ) ) {
+ if(Screen.DEBUG) {
+ System.err.println("Screen.setCurrentScreenMode: 0.0 is-current (skip) "+mmU+" == "+mmC);
+ }
+ return true;
+ }
+ final long tStart;
+ if(Screen.DEBUG) {
+ tStart = System.nanoTime();
+ } else {
+ tStart = 0;
+ }
+
+ sms.fireScreenModeChangeNotify(this, mmU);
+ if(Screen.DEBUG) {
+ System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): fireScreenModeChangeNotify() "+mmU);
+ }
+
+ boolean success = screenImpl.setCurrentMonitorModeImpl(this, mmU);
+ if(success) {
+ if(Screen.DEBUG) {
+ System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): setCurrentScreenModeImpl() "+mmU+", success(1): "+success);
+ }
+ } else {
+ // 2nd attempt validate!
+ final MonitorMode queriedCurrent = queryCurrentMode(); // may fireScreenModeChanged(..) if successful and differs!
+ success = queriedCurrent.hashCode() == mmU.hashCode() ;
+ if(Screen.DEBUG) {
+ System.err.println("Screen.setCurrentScreenMode.2: queried "+queriedCurrent);
+ System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): setCurrentScreenModeImpl() "+mmU+", success(2): "+success);
+ }
+ }
+ if( success ) {
+ setCurrentModeValue(mmU);
+ modeChanged = !isOriginalMode();
+ }
+ sms.fireScreenModeChanged(this, mmU, success);
+ if(Screen.DEBUG) {
+ System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): X.X "+this+", success: "+success);
+ }
+ return success;
+ } finally {
+ sms.unlock();
+ }
+ }
+
+ private final void setCurrentModeValue(MonitorMode currentMode) {
+ this.currentMode = currentMode;
+ }
+
+ /* pp */ final void setViewportValue(Rectangle viewport) {
+ this.viewport = viewport;
+ }
+
+ /* pp */ ArrayHashSet getSupportedModesImpl() {
+ return supportedModes;
+ }
+
+}
\ No newline at end of file
diff --git a/src/newt/classes/jogamp/newt/MonitorModeProps.java b/src/newt/classes/jogamp/newt/MonitorModeProps.java
new file mode 100644
index 000000000..820807e15
--- /dev/null
+++ b/src/newt/classes/jogamp/newt/MonitorModeProps.java
@@ -0,0 +1,355 @@
+/**
+ * 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 jogamp.newt;
+
+import com.jogamp.common.util.ArrayHashSet;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.SurfaceSize;
+
+import jogamp.newt.MonitorDeviceImpl;
+import jogamp.newt.ScreenImpl;
+
+/**
+ * Encodes and decodes {@link MonitorMode} and {@link MonitorDevice} properties.
+ */
+public class MonitorModeProps {
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation
+ * 2: width, height
+ */
+ public static final int NUM_RESOLUTION_PROPERTIES = 2;
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation
+ * 1: bpp
+ */
+ public static final int NUM_SURFACE_SIZE_PROPERTIES = 1;
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation
+ * 2: refresh-rate (Hz*100), flags
+ */
+ public static final int NUM_SIZEANDRATE_PROPERTIES = 2;
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation
+ * 2: id, rotation
+ */
+ public static final int NUM_MONITOR_MODE_PROPERTIES = 2;
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation
+ * count + all the above
+ */
+ public static final int NUM_MONITOR_MODE_PROPERTIES_ALL = 8;
+
+ public static final int IDX_MONITOR_MODE_BPP = 1 // count
+ + MonitorModeProps.NUM_RESOLUTION_PROPERTIES
+ ;
+ public static final int IDX_MONITOR_MODE_ROT = 1 // count
+ + MonitorModeProps.NUM_RESOLUTION_PROPERTIES
+ + MonitorModeProps.NUM_SURFACE_SIZE_PROPERTIES
+ + MonitorModeProps.NUM_SIZEANDRATE_PROPERTIES
+ + 1 // id of MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES
+ ;
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation
+ * 10: count + id, ScreenSizeMM[width, height], rotated Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+
+ */
+ public static final int MIN_MONITOR_DEVICE_PROPERTIES = 11;
+
+ public static final int IDX_MONITOR_DEVICE_VIEWPORT = 1 // count
+ + 1 // native mode
+ + MonitorModeProps.NUM_RESOLUTION_PROPERTIES // sizeMM
+ ;
+
+ public static class Cache {
+ public final ArrayHashSet resolutions = new ArrayHashSet();
+ public final ArrayHashSet surfaceSizes = new ArrayHashSet();
+ public final ArrayHashSet sizeAndRates = new ArrayHashSet();
+ public final ArrayHashSet monitorModes = new ArrayHashSet();
+ public final ArrayHashSet monitorDevices = new ArrayHashSet();
+ }
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation */
+ private static DimensionImmutable streamInResolution(int[] resolutionProperties, int offset) {
+ Dimension resolution = new Dimension(resolutionProperties[offset++], resolutionProperties[offset++]);
+ return resolution;
+ }
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation */
+ private static SurfaceSize streamInSurfaceSize(DimensionImmutable resolution, int[] sizeProperties, int offset) {
+ SurfaceSize surfaceSize = new SurfaceSize(resolution, sizeProperties[offset++]);
+ return surfaceSize;
+ }
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation */
+ private static MonitorMode.SizeAndRRate streamInSizeAndRRate(SurfaceSize surfaceSize, int[] sizeAndRRateProperties, int offset) {
+ final float refreshRate = sizeAndRRateProperties[offset++]/100.0f;
+ final int flags = sizeAndRRateProperties[offset++];
+ return new MonitorMode.SizeAndRRate(surfaceSize, refreshRate, flags);
+ }
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation */
+ private static MonitorMode streamInMonitorMode0(MonitorMode.SizeAndRRate sizeAndRate, int[] modeProperties, int offset) {
+ final int id = modeProperties[offset++];
+ final int rotation = modeProperties[offset++];
+ return new MonitorMode(id, sizeAndRate, rotation);
+ }
+
+ /**
+ * WARNING: must be synchronized with ScreenMode.h, native implementation
+ *
+ * @param mode_idx if not null and cache is given, returns the index of resulting {@link MonitorMode} within {@link Cache#monitorModes}.
+ * @param cache optional hash arrays of unique {@link MonitorMode} components and {@link MonitorDevice}s, allowing to avoid duplicates
+ * @param modeProperties the input data
+ * @param offset the offset to the input data
+ * @return {@link MonitorMode} of the identical (old or new) element in {@link Cache#monitorModes},
+ * matching the input modeProperties, or null if input could not be processed.
+ */
+ public static MonitorMode streamInMonitorMode(int[] mode_idx, Cache cache,
+ int[] modeProperties, int offset) {
+ final int count = modeProperties[offset];
+ if(NUM_MONITOR_MODE_PROPERTIES_ALL != count) {
+ throw new RuntimeException("property count should be "+NUM_MONITOR_MODE_PROPERTIES_ALL+", but is "+count+", len "+(modeProperties.length-offset));
+ }
+ if(NUM_MONITOR_MODE_PROPERTIES_ALL > modeProperties.length-offset) {
+ throw new RuntimeException("properties array too short, should be >= "+NUM_MONITOR_MODE_PROPERTIES_ALL+", is "+(modeProperties.length-offset));
+ }
+ offset++;
+ DimensionImmutable resolution = MonitorModeProps.streamInResolution(modeProperties, offset);
+ offset += MonitorModeProps.NUM_RESOLUTION_PROPERTIES;
+ if(null!=cache) {
+ resolution = cache.resolutions.getOrAdd(resolution);
+ }
+
+ SurfaceSize surfaceSize = MonitorModeProps.streamInSurfaceSize(resolution, modeProperties, offset);
+ offset += MonitorModeProps.NUM_SURFACE_SIZE_PROPERTIES;
+ if(null!=cache) {
+ surfaceSize = cache.surfaceSizes.getOrAdd(surfaceSize);
+ }
+
+ MonitorMode.SizeAndRRate sizeAndRate = MonitorModeProps.streamInSizeAndRRate(surfaceSize, modeProperties, offset);
+ offset += MonitorModeProps.NUM_SIZEANDRATE_PROPERTIES;
+ if(null!=cache) {
+ sizeAndRate = cache.sizeAndRates.getOrAdd(sizeAndRate);
+ }
+
+ MonitorMode monitorMode = MonitorModeProps.streamInMonitorMode0(sizeAndRate, modeProperties, offset);
+ if(null!=cache) {
+ monitorMode = cache.monitorModes.getOrAdd(monitorMode);
+ }
+ if( null != mode_idx && null!=cache) {
+ int _modeIdx = cache.monitorModes.indexOf(monitorMode);
+ if( 0 > _modeIdx ) {
+ throw new InternalError("Invalid index of current unified mode "+monitorMode);
+ }
+ mode_idx[0] = _modeIdx;
+ }
+ return monitorMode;
+ }
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation */
+ public static int[] streamOutMonitorMode (MonitorMode monitorMode) {
+ int[] data = new int[NUM_MONITOR_MODE_PROPERTIES_ALL];
+ int idx=0;
+ data[idx++] = NUM_MONITOR_MODE_PROPERTIES_ALL;
+ data[idx++] = monitorMode.getSurfaceSize().getResolution().getWidth();
+ data[idx++] = monitorMode.getSurfaceSize().getResolution().getHeight();
+ data[idx++] = monitorMode.getSurfaceSize().getBitsPerPixel();
+ data[idx++] = (int)(monitorMode.getRefreshRate()*100.0f); // Hz*100
+ data[idx++] = monitorMode.getFlags();
+ data[idx++] = monitorMode.getId();
+ data[idx++] = monitorMode.getRotation();
+ if(NUM_MONITOR_MODE_PROPERTIES_ALL != idx) {
+ throw new InternalError("wrong number of attributes: got "+idx+" != should "+NUM_MONITOR_MODE_PROPERTIES_ALL);
+ }
+ return data;
+ }
+
+ /**
+ * WARNING: must be synchronized with ScreenMode.h, native implementation
+ *
+ * Note: This variant only works for impl. w/ a unique mode key pair modeId, rotation.
+ *
+ * @param mode_idx if not null, returns the index of resulting {@link MonitorDevice} within {@link Cache#monitorDevices}.
+ * @param cache hash arrays of unique {@link MonitorMode} components and {@link MonitorDevice}s, allowing to avoid duplicates
+ * @param modeProperties the input data
+ * @param offset the offset to the input data
+ * @return {@link MonitorDevice} of the identical (old or new) element in {@link Cache#monitorDevices},
+ * matching the input modeProperties, or null if input could not be processed.
+ */
+ public static MonitorDevice streamInMonitorDevice(int[] monitor_idx, Cache cache, ScreenImpl screen, int[] monitorProperties, int offset) {
+ // min 11: count, id, ScreenSizeMM[width, height], Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+
+ final int count = monitorProperties[offset];
+ if(MIN_MONITOR_DEVICE_PROPERTIES > count) {
+ throw new RuntimeException("property count should be >= "+MIN_MONITOR_DEVICE_PROPERTIES+", but is "+count+", len "+(monitorProperties.length-offset));
+ }
+ if(MIN_MONITOR_DEVICE_PROPERTIES > monitorProperties.length-offset) {
+ throw new RuntimeException("properties array too short (min), should be >= "+MIN_MONITOR_DEVICE_PROPERTIES+", is "+(monitorProperties.length-offset));
+ }
+ if(count > monitorProperties.length-offset) {
+ throw new RuntimeException("properties array too short (count), should be >= "+count+", is "+(monitorProperties.length-offset));
+ }
+ final int limit = offset + count;
+ offset++;
+ final List allMonitorModes = cache.monitorModes.getData();
+ final int id = monitorProperties[offset++];
+ final DimensionImmutable sizeMM = streamInResolution(monitorProperties, offset); offset+=NUM_RESOLUTION_PROPERTIES;
+ final Rectangle viewport = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]);
+ final MonitorMode currentMode;
+ {
+ final int modeId = monitorProperties[offset++];
+ final int rotation = monitorProperties[offset++];
+ currentMode = getByNativeIdAndRotation(allMonitorModes, modeId, rotation);
+ }
+ final ArrayHashSet supportedModes = new ArrayHashSet();
+ while( offset < limit ) {
+ final int modeId = monitorProperties[offset++];
+ for (int i=0; i _monitorIdx ) {
+ throw new InternalError("Invalid index of current unified mode "+monitorDevice);
+ }
+ monitor_idx[0] = _monitorIdx;
+ }
+ return monitorDevice;
+ }
+ private static MonitorMode getByNativeIdAndRotation(List monitorModes, int modeId, int rotation) {
+ if( null!=monitorModes && monitorModes.size()>0 ) {
+ for (int i=0; i
+ * This variant expects count to be {@link MIN_MONITOR_DEVICE_PROPERTIES} - 1 - {@link NUM_MONITOR_MODE_PROPERTIES},
+ * due to lack of supported mode and current mode.
+ *
+ *
+ * @param mode_idx if not null, returns the index of resulting {@link MonitorDevice} within {@link Cache#monitorDevices}.
+ * @param cache hash arrays of unique {@link MonitorMode} components and {@link MonitorDevice}s, allowing to avoid duplicates
+ * @param supportedModes pre-assembled list of supported {@link MonitorMode}s from cache.
+ * @param currentMode pre-fetched current {@link MonitorMode}s from cache.
+ * @param modeProperties the input data minus supported modes!
+ * @param offset the offset to the input data
+ * @return {@link MonitorDevice} of the identical (old or new) element in {@link Cache#monitorDevices},
+ * matching the input modeProperties, or null if input could not be processed.
+ */
+ public static MonitorDevice streamInMonitorDevice(int[] monitor_idx, Cache cache, ScreenImpl screen, ArrayHashSet supportedModes, MonitorMode currentMode, int[] monitorProperties, int offset) {
+ // min 11: count, id, ScreenSizeMM[width, height], Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+
+ final int count = monitorProperties[offset];
+ if(MIN_MONITOR_DEVICE_PROPERTIES - 1 - NUM_MONITOR_MODE_PROPERTIES != count) {
+ throw new RuntimeException("property count should be == "+(MIN_MONITOR_DEVICE_PROPERTIES-1-NUM_MONITOR_MODE_PROPERTIES)+", but is "+count+", len "+(monitorProperties.length-offset));
+ }
+ if(MIN_MONITOR_DEVICE_PROPERTIES - 1 - NUM_MONITOR_MODE_PROPERTIES > monitorProperties.length-offset) {
+ throw new RuntimeException("properties array too short (min), should be >= "+(MIN_MONITOR_DEVICE_PROPERTIES-1-NUM_MONITOR_MODE_PROPERTIES)+", is "+(monitorProperties.length-offset));
+ }
+ if(count > monitorProperties.length-offset) {
+ throw new RuntimeException("properties array too short (count), should be >= "+count+", is "+(monitorProperties.length-offset));
+ }
+ offset++;
+ final int id = monitorProperties[offset++];
+ final DimensionImmutable sizeMM = streamInResolution(monitorProperties, offset); offset+=NUM_RESOLUTION_PROPERTIES;
+ final Rectangle viewport = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]);
+ MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, sizeMM, viewport, currentMode, supportedModes);
+ if(null!=cache) {
+ monitorDevice = cache.monitorDevices.getOrAdd(monitorDevice);
+ }
+ if( null != monitor_idx ) {
+ int _monitorIdx = cache.monitorDevices.indexOf(monitorDevice);
+ if( 0 > _monitorIdx ) {
+ throw new InternalError("Invalid index of current unified mode "+monitorDevice);
+ }
+ monitor_idx[0] = _monitorIdx;
+ }
+ return monitorDevice;
+ }
+
+ /** WARNING: must be synchronized with ScreenMode.h, native implementation */
+ public static int[] streamOutMonitorDevice (MonitorDevice monitorDevice) {
+ // min 11: count, id, ScreenSizeMM[width, height], Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+
+ int supportedModeCount = monitorDevice.getSupportedModes().size();
+ if( 0 == supportedModeCount ) {
+ throw new RuntimeException("no supported modes: "+monitorDevice);
+ }
+ int[] data = new int[MIN_MONITOR_DEVICE_PROPERTIES + supportedModeCount - 1];
+ int idx=0;
+ data[idx++] = data.length;
+ data[idx++] = monitorDevice.getId();
+ data[idx++] = monitorDevice.getSizeMM().getWidth();
+ data[idx++] = monitorDevice.getSizeMM().getHeight();
+ data[idx++] = monitorDevice.getViewport().getX();
+ data[idx++] = monitorDevice.getViewport().getY();
+ data[idx++] = monitorDevice.getViewport().getWidth();
+ data[idx++] = monitorDevice.getViewport().getHeight();
+ data[idx++] = monitorDevice.getCurrentMode().getId();
+ data[idx++] = monitorDevice.getCurrentMode().getRotation();
+ final List supportedModes = monitorDevice.getSupportedModes();
+ for(int i=0; i monitors) {
+ return false; // nop
+ }
+
+
protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) {
sizeChanged(false, width, height, false);
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) ) {
diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java
index 1282e5dc5..4d20fdb83 100644
--- a/src/newt/classes/jogamp/newt/ScreenImpl.java
+++ b/src/newt/classes/jogamp/newt/ScreenImpl.java
@@ -43,22 +43,19 @@ import java.util.List;
import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.DimensionImmutable;
-import javax.media.nativewindow.util.Point;
-import javax.media.nativewindow.util.SurfaceSize;
-
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.RectangleImmutable;
import com.jogamp.common.util.ArrayHashSet;
-import com.jogamp.common.util.IntIntHashMap;
import com.jogamp.newt.Display;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
-import com.jogamp.newt.ScreenMode;
-import com.jogamp.newt.event.ScreenModeListener;
-import com.jogamp.newt.util.MonitorMode;
-import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.newt.event.MonitorEvent;
+import com.jogamp.newt.event.MonitorModeListener;
-public abstract class ScreenImpl extends Screen implements ScreenModeListener {
+public abstract class ScreenImpl extends Screen implements MonitorModeListener {
protected static final boolean DEBUG_TEST_SCREENMODE_DISABLED = Debug.isPropertyDefined("newt.test.Screen.disableScreenMode", true);
public static final int default_sm_bpp = 32;
@@ -73,11 +70,11 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
protected int hashCode;
protected AbstractGraphicsScreen aScreen;
protected int refCount; // number of Screen references by Window
- protected Point vOrigin = new Point(0, 0); // virtual top-left origin
- protected Dimension vSize = new Dimension(0, 0); // virtual rotated screen size
+ protected Rectangle vOriginSize = new Rectangle(0, 0, 0, 0); // virtual rotated screen origin and size
protected static Dimension usrSize = null; // property values: newt.ws.swidth and newt.ws.sheight
protected static volatile boolean usrSizeQueried = false;
- private ArrayList referencedScreenModeListener = new ArrayList();
+ private ArrayList referencedScreenModeListener = new ArrayList();
+
private long tCreated; // creationTime
static {
@@ -160,10 +157,12 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
return true;
}
+ @Override
public int hashCode() {
return hashCode;
}
+ @Override
public synchronized final void createNative()
throws NativeWindowException
{
@@ -182,8 +181,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
throw new NativeWindowException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen");
}
- initScreenModeStatus();
- updateVirtualScreenOriginAndSize();
+ initScreenMonitorState();
if(DEBUG) {
System.err.println("Screen.createNative() END ("+DisplayImpl.getThreadName()+", "+this+"), total "+ (System.nanoTime()-tCreated)/1e6 +"ms");
}
@@ -191,10 +189,11 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
screensActive++;
}
}
- ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName());
+ ScreenMonitorState sms = ScreenMonitorState.getScreenMonitorState(this.getFQName());
sms.addListener(this);
}
+ @Override
public synchronized final void destroy() {
releaseScreenModeStatus();
@@ -213,6 +212,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
display.removeReference();
}
+ @Override
public synchronized final int addReference() throws NativeWindowException {
if(DEBUG) {
System.err.println("Screen.addReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount+1));
@@ -227,6 +227,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
return ++refCount;
}
+ @Override
public synchronized final int removeReference() {
if(DEBUG) {
System.err.println("Screen.removeReference() ("+DisplayImpl.getThreadName()+"): "+refCount+" -> "+(refCount-1));
@@ -240,6 +241,7 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
return refCount;
}
+ @Override
public synchronized final int getReferenceCount() {
return refCount;
}
@@ -259,14 +261,20 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
/**
* Stores the virtual origin and virtual rotated screen size.
*
- * This method is called after the ScreenMode has been set,
+ * This method is called after the ScreenMode has been set or changed,
* hence you may utilize it.
- *
- * @param virtualOrigin the store for the virtual origin
- * @param virtualSize the store for the virtual rotated size
+ *
+ *
+ * Default implementation uses the union of all monitor's viewport,
+ * calculated via {@link #unionOfMonitorViewportSize()}.
+ *
+ * @param vOriginSize storage for result
*/
- protected abstract void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize);
+ protected void calcVirtualScreenOriginAndSize(final Rectangle vOriginSize) {
+ unionOfMonitorViewportSize(vOriginSize);
+ }
+ @Override
public final String getFQName() {
return fqname;
}
@@ -275,258 +283,227 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
* Updates the rotated virtual ScreenSize using the native impl.
*/
protected void updateVirtualScreenOriginAndSize() {
- getVirtualScreenOriginAndSize(vOrigin, vSize);
- if(DEBUG) {
- System.err.println("Detected virtual screen origin "+vOrigin+", size "+vSize);
+ if(null != usrSize ) {
+ vOriginSize.setX(0);
+ vOriginSize.setY(0);
+ vOriginSize.setWidth(usrSize.getWidth());
+ vOriginSize.setHeight(usrSize.getHeight());
+ if(DEBUG) {
+ System.err.println("User virtual screen viewport "+vOriginSize);
+ }
+ } else {
+ calcVirtualScreenOriginAndSize(vOriginSize);
+ if(DEBUG) {
+ System.err.println("Detected virtual screen viewport "+vOriginSize);
+ }
}
}
+ @Override
public final Display getDisplay() {
return display;
}
+ @Override
public final int getIndex() {
return screen_idx;
}
+ @Override
public final AbstractGraphicsScreen getGraphicsScreen() {
return aScreen;
}
+ @Override
public synchronized final boolean isNativeValid() {
return null != aScreen;
}
- public int getX() { return vOrigin.getX(); }
- public int getY() { return vOrigin.getY(); }
-
- public final int getWidth() {
- return (null != usrSize) ? usrSize.getWidth() : vSize.getWidth();
- }
-
- public final int getHeight() {
- return (null != usrSize) ? usrSize.getHeight() : vSize.getHeight();
- }
+ @Override
+ public final int getX() { return vOriginSize.getX(); }
+ @Override
+ public final int getY() { return vOriginSize.getY(); }
+ @Override
+ public final int getWidth() { return vOriginSize.getWidth(); }
+ @Override
+ public final int getHeight() { return vOriginSize.getHeight(); }
+ @Override
+ public final RectangleImmutable getViewport() { return vOriginSize; }
@Override
public String toString() {
- return "NEWT-Screen["+getFQName()+", idx "+screen_idx+", refCount "+refCount+", "+getWidth()+"x"+getHeight()+", "+aScreen+", "+display+"]";
+ return "NEWT-Screen["+getFQName()+", idx "+screen_idx+", refCount "+refCount+", vsize "+vOriginSize+", "+aScreen+", "+display+
+ ", monitors: "+getMonitorDevices()+"]";
}
- public final List getScreenModes() {
- ArrayHashSet screenModes = getScreenModesOrig();
- if(null != screenModes && 0 < screenModes.size()) {
- return screenModes.toArrayList();
- }
- return null;
+ //
+ // MonitorDevice and MonitorMode
+ //
+
+ /**
+ * To be implemented by the native specification.
+ * Is called within a thread safe environment.
+ * Is called only to collect the {@link MonitorMode}s and {@link MonitorDevice}s, usually at startup setting up modes.
+ *
+ * WARNING: must be synchronized with
+ *
+ *
{@link MonitorModeProps#NUM_SCREEN_MODE_PROPERTIES} and
+ * @param cache memory pool caching the result
+ */
+ protected abstract void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache);
+
+ protected Rectangle getNativeMonitorDeviceViewportImpl(MonitorDevice monitor) { return null; }
+
+ /**
+ * To be implemented by the native specification.
+ * Is called within a thread safe environment.
+ *
+ * Implementation shall not unify the result w/ monitor's supported modes or a locally
+ * saved {@link MonitorModeProps.Cache}, since caller will perform such tasks.
+ *
+ */
+ protected abstract MonitorMode queryCurrentMonitorModeImpl(MonitorDevice monitor);
+
+ /**
+ * To be implemented by the native specification.
+ * Is called within a thread safe environment.
+ */
+ protected abstract boolean setCurrentMonitorModeImpl(MonitorDevice monitor, MonitorMode mode);
+
+ @Override
+ public final List getMonitorModes() {
+ final ScreenMonitorState sms = getScreenMonitorStatus(false);
+ return null != sms ? sms.getMonitorModes().getData() : null;
+ }
+
+ @Override
+ public final List getMonitorDevices() {
+ final ScreenMonitorState sms = getScreenMonitorStatus(false);
+ return null != sms ? sms.getMonitorDevices().getData() : null;
}
- private final ScreenModeStatus getScreenModeStatus(boolean throwException) {
+ final ScreenMonitorState getScreenMonitorStatus(boolean throwException) {
final String key = this.getFQName();
- final ScreenModeStatus res = ScreenModeStatus.getScreenModeStatus(key);
+ final ScreenMonitorState res = ScreenMonitorState.getScreenMonitorState(key);
if(null == res & throwException) {
- throw new InternalError("ScreenModeStatus.getScreenModeStatus("+key+") == null");
+ throw new InternalError("ScreenMonitorStatus.getScreenModeStatus("+key+") == null");
}
return res;
}
- public ScreenMode getOriginalScreenMode() {
- final ScreenModeStatus sms = getScreenModeStatus(false);
- return ( null != sms ) ? sms.getOriginalScreenMode() : null ;
- }
-
- public ScreenMode getCurrentScreenMode() {
- ScreenMode smU = null;
- final ScreenModeStatus sms = getScreenModeStatus(true);
- final ScreenMode sm0 = getCurrentScreenModeIntern();
- if(null == sm0) {
- throw new InternalError("getCurrentScreenModeImpl() == null");
+ @Override
+ public void monitorModeChangeNotify(MonitorEvent me) {
+ if(DEBUG) {
+ System.err.println("monitorModeChangeNotify: "+me);
}
- sms.lock();
- try {
- smU = sms.getScreenModes().getOrAdd(sm0); // unified instance, maybe new
-
- // if mode has changed somehow, update it ..
- if( sms.getCurrentScreenMode().hashCode() != smU.hashCode() ) {
- sms.fireScreenModeChanged(smU, true);
- }
- } finally {
- sms.unlock();
+ for(int i=0; i monitors = getMonitorDevices();
+ for(int i=monitors.size()-1; i>=0; i--) {
+ final MonitorDeviceImpl monitor = (MonitorDeviceImpl) monitors.get(i);
+ final Rectangle newViewport = getNativeMonitorDeviceViewportImpl(monitor);
+ if( DEBUG ) {
+ System.err.println("Screen.updateMonitorViewport["+i+"]: "+monitor.getViewport()+" -> "+newViewport);
}
-
- sms.fireScreenModeChangeNotify(smU);
- if(DEBUG) {
- System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): fireScreenModeChangeNotify() "+smU);
+ if( null != newViewport ) {
+ monitor.setViewportValue(newViewport);
}
-
- success = setCurrentScreenModeImpl(smU);
- if(success) {
- if(DEBUG) {
- System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): setCurrentScreenModeImpl() "+smU+", success(1): "+success);
- }
- } else {
- // 2nd attempt validate!
- final ScreenMode queriedCurrent = getCurrentScreenMode(); // may fireScreenModeChanged(..) if successful and differs!
- final ScreenMode smsCurrent = sms.getCurrentScreenMode();
- success = smsCurrent.hashCode() == smU.hashCode() && queriedCurrent.hashCode() == smU.hashCode() ;
- if(DEBUG) {
- System.err.println("Screen.setCurrentScreenMode.2: queried "+queriedCurrent);
- System.err.println("Screen.setCurrentScreenMode.2: SMS "+smsCurrent);
- System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): setCurrentScreenModeImpl() "+smU+", success(2): "+success);
- }
- }
- sms.fireScreenModeChanged(smU, success);
- if(DEBUG) {
- System.err.println("Screen.setCurrentScreenMode ("+(System.nanoTime()-tStart)/1e6+"ms): X.X "+smU+", success: "+success);
- }
- } finally {
- sms.unlock();
- }
- return success;
+ }
}
-
- public void screenModeChangeNotify(ScreenMode sm) {
- for(int i=0; i getScreenModesOrig() {
- ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName());
- if(null!=sms) {
- return sms.getScreenModes();
- }
- return null;
- }
-
- /** ScreenModeStatus bridge to native implementation */
- protected final IntIntHashMap getScreenModesIdx2NativeIdx() {
- ScreenModeStatus sms = ScreenModeStatus.getScreenModeStatus(this.getFQName());
- if(null!=sms) {
- return sms.getScreenModesIdx2NativeIdx();
- }
- return null;
- }
-
- /**
- * To be implemented by the native specification.
- * Is called within a thread safe environment.
- * Is called only to collect the ScreenModes, usually at startup setting up modes.
- *
- * WARNING: must be synchronized with {@link com.jogamp.newt.util.ScreenModeUtil#NUM_SCREEN_MODE_PROPERTIES},
- * ie {@link com.jogamp.newt.util.ScreenModeUtil#streamIn(com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, int[], int)}
- *
- * Note: Additional 1st element is native mode id.
- */
- protected int[] getScreenModeFirstImpl() {
- return null;
- }
-
- /**
- * To be implemented by the native specification.
- * Is called within a thread safe environment.
- * Is called only to collect the ScreenModes, usually at startup setting up modes.
- *
- * WARNING: must be synchronized with {@link com.jogamp.newt.util.ScreenModeUtil#NUM_SCREEN_MODE_PROPERTIES},
- * ie {@link com.jogamp.newt.util.ScreenModeUtil#streamIn(com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, com.jogamp.common.util.ArrayHashSet, int[], int)}
- *
- * Note: Additional 1st element is native mode id.
- */
- protected int[] getScreenModeNextImpl() {
- return null;
+
+ private final MonitorMode getVirtualMonitorMode(int modeId) {
+ final int[] props = new int[MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL];
+ int i = 0;
+ props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
+ props[i++] = getWidth(); // width
+ props[i++] = getHeight(); // height
+ props[i++] = default_sm_bpp;
+ props[i++] = default_sm_rate * 100;
+ props[i++] = 0; // flags
+ props[i++] = modeId;
+ props[i++] = default_sm_rotation;
+ if( MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL != i ) {
+ throw new InternalError("XX");
+ }
+ return MonitorModeProps.streamInMonitorMode(null, null, props, 0);
}
-
- /**
- * To be implemented by the native specification.
- * Is called within a thread safe environment.
- */
- protected ScreenMode getCurrentScreenModeImpl() {
- return null;
+
+ private final MonitorDevice getVirtualMonitorDevice(int monitorId, MonitorMode currentMode) {
+ int[] props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES];
+ int i = 0;
+ props[i++] = MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES;
+ props[i++] = monitorId;
+ props[i++] = default_sm_widthmm;
+ props[i++] = default_sm_heightmm;
+ props[i++] = 0; // rotated viewport x
+ props[i++] = 0; // rotated viewport y
+ props[i++] = currentMode.getRotatedWidth(); // rotated viewport width
+ props[i++] = currentMode.getRotatedHeight(); // rotated viewport height
+ props[i++] = currentMode.getId(); // current mode id
+ props[i++] = currentMode.getRotation();
+ props[i++] = currentMode.getId(); // supported mode id #1
+ if( MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES != i ) {
+ throw new InternalError("XX");
+ }
+ return MonitorModeProps.streamInMonitorDevice(null, null, this, props, 0);
}
/**
- * Utilizes {@link #getCurrentScreenModeImpl()}, if the latter returns null it uses
+ * Utilizes {@link #getCurrentMonitorModeImpl()}, if the latter returns null it uses
* the current screen size and dummy values.
*/
- protected ScreenMode getCurrentScreenModeIntern() {
- ScreenMode res;
+ protected final MonitorMode queryCurrentMonitorModeIntern(MonitorDevice monitor) {
+ MonitorMode res;
if(DEBUG_TEST_SCREENMODE_DISABLED) {
res = null;
} else {
- res = getCurrentScreenModeImpl();
+ res = queryCurrentMonitorModeImpl(monitor);
}
if(null == res) {
if( 0>=getWidth() || 0>=getHeight() ) {
updateVirtualScreenOriginAndSize();
}
- int[] props = new int[ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL];
- int i = 0;
- props[i++] = 0; // set later for verification of iterator
- props[i++] = getWidth(); // width
- props[i++] = getHeight(); // height
- props[i++] = default_sm_bpp;
- props[i++] = default_sm_widthmm;
- props[i++] = default_sm_heightmm;
- props[i++] = default_sm_rate;
- props[i++] = default_sm_rotation;
- props[i - ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL] = i; // count
- res = ScreenModeUtil.streamIn(props, 0);
+ res = getVirtualMonitorMode(monitor.getCurrentMode().getId());
}
return res;
}
- /**
- * To be implemented by the native specification.
- * Is called within a thread safe environment.
- */
- protected boolean setCurrentScreenModeImpl(ScreenMode screenMode) {
- return false;
- }
-
- private ScreenModeStatus initScreenModeStatus() {
+ private final ScreenMonitorState initScreenMonitorState() {
long t0;
if(DEBUG) {
t0 = System.nanoTime();
@@ -535,138 +512,139 @@ public abstract class ScreenImpl extends Screen implements ScreenModeListener {
t0 = 0;
}
- ScreenModeStatus sms;
- ScreenModeStatus.lockScreenModeStatus();
+ boolean vScrnSizeUpdated = false;
+ ScreenMonitorState sms;
+ ScreenMonitorState.lockScreenMonitorState();
try {
- sms = ScreenModeStatus.getScreenModeStatus(this.getFQName());
- if(null==sms) {
- IntIntHashMap screenModesIdx2NativeIdx = new IntIntHashMap();
- final ScreenMode currentSM = getCurrentScreenModeIntern();
- if(null == currentSM) {
- throw new InternalError("getCurrentScreenModeImpl() == null");
+ sms = ScreenMonitorState.getScreenMonitorState(this.getFQName());
+ if(null==sms) {
+ final MonitorModeProps.Cache cache = new MonitorModeProps.Cache();
+ if( 0 >= collectNativeMonitorModes(cache) ) {
+ updateVirtualScreenOriginAndSize();
+ vScrnSizeUpdated = true;
+ final MonitorMode mode = getVirtualMonitorMode(0);
+ cache.monitorModes.getOrAdd(mode);
+ final MonitorDevice monitor = getVirtualMonitorDevice(0, mode);
+ cache.monitorDevices.getOrAdd(monitor);
}
-
- ArrayHashSet screenModes = collectNativeScreenModes(screenModesIdx2NativeIdx);
- screenModes.getOrAdd(currentSM);
if(DEBUG) {
int i=0;
- for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) {
- System.err.println(i+": "+iter.next());
+ for(Iterator iMode=cache.monitorModes.iterator(); iMode.hasNext(); i++) {
+ System.err.println("All["+i+"]: "+iMode.next());
+ }
+ i=0;
+ for(Iterator iMonitor=cache.monitorDevices.iterator(); iMonitor.hasNext(); i++) {
+ final MonitorDevice crt = iMonitor.next();
+ System.err.println("["+i+"]: "+crt);
+ int j=0;
+ for(Iterator iMode=crt.getSupportedModes().iterator(); iMode.hasNext(); j++) {
+ System.err.println("["+i+"]["+j+"]: "+iMode.next());
+ }
}
}
-
- sms = new ScreenModeStatus(screenModes, screenModesIdx2NativeIdx);
- ScreenMode originalScreenMode0 = screenModes.get(currentSM); // unify via value hash
- if(null == originalScreenMode0) {
- throw new RuntimeException(currentSM+" could not be hashed from ScreenMode list");
- }
- sms.setOriginalScreenMode(originalScreenMode0);
- ScreenModeStatus.mapScreenModeStatus(this.getFQName(), sms);
+ sms = new ScreenMonitorState(cache.monitorDevices, cache.monitorModes);
+ ScreenMonitorState.mapScreenMonitorState(this.getFQName(), sms);
}
} finally {
- ScreenModeStatus.unlockScreenModeStatus();
+ ScreenMonitorState.unlockScreenMonitorState();
}
if(DEBUG) {
System.err.println("Screen.initScreenModeStatus() END dt "+ (System.nanoTime()-t0)/1e6 +"ms");
}
+ if( !vScrnSizeUpdated ) {
+ updateVirtualScreenOriginAndSize();
+ }
+
return sms;
}
- /** ignores bpp < 15 */
- private ArrayHashSet collectNativeScreenModes(IntIntHashMap screenModesIdx2NativeId) {
- ArrayHashSet resolutionPool = new ArrayHashSet();
- ArrayHashSet surfaceSizePool = new ArrayHashSet();
- ArrayHashSet screenSizeMMPool = new ArrayHashSet();
- ArrayHashSet monitorModePool = new ArrayHashSet();
- ArrayHashSet screenModePool = new ArrayHashSet();
-
- int[] smProps = null;
- int num = 0;
- final int idxBpp = 1 // native mode
- + 1 // count
- + ScreenModeUtil.NUM_RESOLUTION_PROPERTIES
- + ScreenModeUtil.NUM_SURFACE_SIZE_PROPERTIES
- - 1 ; // index 0 based
- do {
- if(DEBUG_TEST_SCREENMODE_DISABLED) {
- smProps = null;
- } else if(0 == num) {
- smProps = getScreenModeFirstImpl();
- } else {
- smProps = getScreenModeNextImpl();
- }
- if(null != smProps && 0 < smProps.length && smProps[idxBpp] >= 15) {
- int nativeId = smProps[0];
- int screenModeIdx = ScreenModeUtil.streamIn(resolutionPool, surfaceSizePool, screenSizeMMPool,
- monitorModePool, screenModePool, smProps, 1);
- if(DEBUG) {
- System.err.println("ScreenImpl.collectNativeScreenModes: #"+num+": idx: "+nativeId+" native -> "+screenModeIdx+" newt");
+ /**
+ * Returns the number of successful collected {@link MonitorDevice}s.
+ *
+ * Collects {@link MonitorDevice}s and {@link MonitorMode}s within the given cache.
+ *
- * At least we only return true if the owner, ie. the Screen,
- * has changed the screen mode and if the original screen mode
- * is not current the current one.
- *
- * @return
- */
- public final boolean isOriginalModeChangedByOwner() {
- lock();
- try {
- return screenModeChangedByOwner && !isCurrentModeOriginalMode();
- } finally {
- unlock();
- }
- }
-
- protected final boolean isCurrentModeOriginalMode() {
- if(null != currentScreenMode && null != originalScreenMode) {
- return currentScreenMode.hashCode() == originalScreenMode.hashCode();
- }
- return true;
- }
-
- protected final ArrayHashSet getScreenModes() {
- return screenModes;
- }
-
- protected final IntIntHashMap getScreenModesIdx2NativeIdx() {
- return screenModesIdx2NativeIdx;
- }
-
- protected final int addListener(ScreenModeListener l) {
- lock();
- try {
- listener.add(l);
- if(DEBUG) {
- System.err.println("ScreenModeStatus.addListener (size: "+listener.size()+"): "+l);
- }
- return listener.size();
- } finally {
- unlock();
- }
- }
-
- protected final int removeListener(ScreenModeListener l) {
- lock();
- try {
- if(!listener.remove(l)) {
- throw new RuntimeException("ScreenModeListener "+l+" not contained");
- }
- if(DEBUG) {
- System.err.println("ScreenModeStatus.removeListener (size: "+listener.size()+"): "+l);
- }
- return listener.size();
- } finally {
- unlock();
- }
- }
-
- protected final void fireScreenModeChangeNotify(ScreenMode desiredScreenMode) {
- lock();
- try {
- for(int i=0; i allMonitors;
+ private final ArrayHashSet allMonitorModes;
+ private ArrayList listener = new ArrayList();
+
+ private static HashMap screenFQN2ScreenMonitorState = new HashMap();
+ private static RecursiveLock screen2ScreenMonitorState = LockFactory.createRecursiveLock();
+
+ protected static void mapScreenMonitorState(String screenFQN, ScreenMonitorState sms) {
+ screen2ScreenMonitorState.lock();
+ try {
+ ScreenMonitorState _sms = screenFQN2ScreenMonitorState.get(screenFQN);
+ if( null != _sms ) {
+ throw new RuntimeException("ScreenMonitorState "+_sms+" already mapped to "+screenFQN);
+ }
+ screenFQN2ScreenMonitorState.put(screenFQN, sms);
+ if(DEBUG) {
+ System.err.println("ScreenMonitorState.map "+screenFQN+" -> "+sms);
+ }
+ } finally {
+ screen2ScreenMonitorState.unlock();
+ }
+ }
+
+ /**
+ * @param screen the prev user
+ * @return true if mapping is empty, ie no more usage of the mapped ScreenMonitorState
+ */
+ protected static void unmapScreenMonitorState(String screenFQN) {
+ screen2ScreenMonitorState.lock();
+ try {
+ unmapScreenMonitorStateUnlocked(screenFQN);
+ } finally {
+ screen2ScreenMonitorState.unlock();
+ }
+ }
+ protected static void unmapScreenMonitorStateUnlocked(String screenFQN) {
+ ScreenMonitorState sms = screenFQN2ScreenMonitorState.remove(screenFQN);
+ if(DEBUG) {
+ System.err.println("ScreenMonitorState.unmap "+screenFQN+" -> "+sms);
+ }
+ }
+
+ protected static ScreenMonitorState getScreenMonitorState(String screenFQN) {
+ screen2ScreenMonitorState.lock();
+ try {
+ return getScreenMonitorStateUnlocked(screenFQN);
+ } finally {
+ screen2ScreenMonitorState.unlock();
+ }
+ }
+ protected static ScreenMonitorState getScreenMonitorStateUnlocked(String screenFQN) {
+ return screenFQN2ScreenMonitorState.get(screenFQN);
+ }
+
+ protected static void lockScreenMonitorState() {
+ screen2ScreenMonitorState.lock();
+ }
+
+ protected static void unlockScreenMonitorState() {
+ screen2ScreenMonitorState.unlock();
+ }
+
+ public ScreenMonitorState(ArrayHashSet allMonitors,
+ ArrayHashSet allMonitorModes) {
+ this.allMonitors = allMonitors;
+ this.allMonitorModes = allMonitorModes;
+ }
+
+ protected ArrayHashSet getMonitorDevices() {
+ return allMonitors;
+ }
+
+ protected ArrayHashSet getMonitorModes() {
+ return allMonitorModes;
+ }
+
+ protected final int addListener(MonitorModeListener l) {
+ lock();
+ try {
+ listener.add(l);
+ if(DEBUG) {
+ System.err.println("ScreenMonitorState.addListener (size: "+listener.size()+"): "+l);
+ }
+ return listener.size();
+ } finally {
+ unlock();
+ }
+ }
+
+ protected final int removeListener(MonitorModeListener l) {
+ lock();
+ try {
+ if(!listener.remove(l)) {
+ throw new RuntimeException("ScreenModeListener "+l+" not contained");
+ }
+ if(DEBUG) {
+ System.err.println("ScreenMonitorState.removeListener (size: "+listener.size()+"): "+l);
+ }
+ return listener.size();
+ } finally {
+ unlock();
+ }
+ }
+
+ protected final MonitorDevice getMonitor(MonitorDevice monitor) {
+ return allMonitors.get(monitor);
+ }
+
+ protected final void validateMonitor(MonitorDevice monitor) {
+ final MonitorDevice md = allMonitors.get(monitor);
+ if( null == md ) {
+ throw new InternalError("Monitor unknown: "+monitor);
+ }
+ }
+
+ protected final void fireScreenModeChangeNotify(MonitorDevice monitor, MonitorMode desiredMode) {
+ lock();
+ try {
+ validateMonitor(monitor);
+ final MonitorEvent me = new MonitorEvent(MonitorEvent.EVENT_MONITOR_MODE_CHANGE_NOTIFY, monitor, System.currentTimeMillis(), desiredMode);
+ for(int i=0; i default
- private boolean fullscreen = false, brokenFocusChange = false;
+ private boolean fullscreen = false, brokenFocusChange = false;
+ private List fullscreenMonitors = null;
+ private boolean fullscreenUseMainMonitor = true;
private boolean autoPosition = true; // default: true (allow WM to choose top-level position, if not set by user)
private int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen client-area size/pos w/o insets
@@ -294,19 +298,40 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
screenReferenceAdded = true;
}
if(canCreateNativeImpl()) {
+ final int wX, wY;
+ final boolean usePosition;
+ if( autoPosition ) {
+ wX = 0;
+ wY = 0;
+ usePosition = false;
+ } else {
+ wX = getX();
+ wY = getY();
+ usePosition = true;
+ }
+ final long t0 = System.currentTimeMillis();
createNativeImpl();
- screen.addScreenModeListener(screenModeListenerImpl);
+ screen.addMonitorModeListener(screenModeListenerImpl);
setTitleImpl(title);
setPointerVisibleImpl(pointerVisible);
confinePointerImpl(pointerConfined);
setKeyboardVisible(keyboardVisible);
- if(waitForVisible(true, false)) {
+ final long remainingV = waitForVisible(true, false);
+ if( 0 <= remainingV ) {
if(isFullscreen()) {
synchronized(fullScreenAction) {
fullscreen = false; // trigger a state change
- fullScreenAction.init(true);
+ fullScreenAction.init(true, fullscreenUseMainMonitor, fullscreenMonitors);
+ fullscreenMonitors = null; // release references ASAP
+ fullscreenUseMainMonitor = true;
fullScreenAction.run();
}
+ } else {
+ // Wait until position is reached within tolerances, either auto-position or custom position.
+ waitForPosition(usePosition, wX, wY, Window.TIMEOUT_NATIVEWINDOW);
+ }
+ if (DEBUG_IMPLEMENTATION) {
+ System.err.println("Window.createNative(): elapsed "+(System.currentTimeMillis()-t0)+" ms");
}
postParentlockFocus = true;
}
@@ -463,8 +488,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
public static final int FLAG_HAS_PARENT = 1 << 8;
public static final int FLAG_IS_UNDECORATED = 1 << 9;
public static final int FLAG_IS_FULLSCREEN = 1 << 10;
- public static final int FLAG_IS_ALWAYSONTOP = 1 << 11;
- public static final int FLAG_IS_VISIBLE = 1 << 12;
+ public static final int FLAG_IS_FULLSCREEN_SPAN = 1 << 11;
+ public static final int FLAG_IS_ALWAYSONTOP = 1 << 12;
+ public static final int FLAG_IS_VISIBLE = 1 << 13;
/**
* The native implementation should invoke the referenced java state callbacks
@@ -509,6 +535,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
sb.append("FS_");
sb.append(0 != ( FLAG_IS_FULLSCREEN & flags));
+ sb.append("_span_");
+ sb.append(0 != ( FLAG_IS_FULLSCREEN_SPAN & flags));
sb.append(", ");
if( 0 != ( FLAG_CHANGE_DECORATION & flags) ) {
@@ -718,6 +746,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return screen;
}
+ @Override
+ public final MonitorDevice getMainMonitor() {
+ return screen.getMainMonitor(new Rectangle(getX(), getY(), getWidth(), getHeight()));
+ }
+
protected final void setVisibleImpl(boolean visible, int x, int y, int width, int height) {
reconfigureWindowImpl(x, y, width, height, getReconfigureFlags(FLAG_CHANGE_VISIBILITY, visible));
}
@@ -904,7 +937,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
if( isNativeValid() ) {
- screen.removeScreenModeListener(screenModeListenerImpl);
+ screen.removeMonitorModeListener(screenModeListenerImpl);
closeNativeImpl();
final AbstractGraphicsDevice cfgADevice = config.getScreen().getDevice();
if( cfgADevice != screen.getDisplay().getGraphicsDevice() ) { // don't pull display's device
@@ -929,6 +962,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
setWindowHandle(0);
visible = false;
fullscreen = false;
+ fullscreenMonitors = null;
+ fullscreenUseMainMonitor = true;
hasFocus = false;
parentWindowHandle = 0;
@@ -1212,7 +1247,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
display.dispatchMessagesNative(); // status up2date
if(wasVisible) {
setVisibleImpl(true, x, y, width, height);
- ok = WindowImpl.this.waitForVisible(true, false);
+ ok = 0 <= WindowImpl.this.waitForVisible(true, false);
if(ok) {
ok = WindowImpl.this.waitForSize(width, height, false, TIMEOUT_NATIVEWINDOW);
}
@@ -1735,6 +1770,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
if(isNativeValid()) {
// this.x/this.y will be set by sizeChanged, triggered by windowing event system
reconfigureWindowImpl(x, y, getWidth(), getHeight(), getReconfigureFlags(0, isVisible()));
+
+ // Wait until custom position is reached within tolerances
+ waitForPosition(true, x, y, Window.TIMEOUT_NATIVEWINDOW);
} else {
definePosition(x, y); // set pos for createNative(..)
}
@@ -1758,13 +1796,25 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
private class FullScreenAction implements Runnable {
boolean fullscreen;
+ List monitors;
+ boolean useMainMonitor;
- private boolean init(boolean fullscreen) {
+ private boolean init(boolean fullscreen, boolean useMainMonitor, List monitors) {
if(isNativeValid()) {
this.fullscreen = fullscreen;
- return isFullscreen() != fullscreen;
+ if( isFullscreen() != fullscreen ) {
+ this.monitors = monitors;
+ this.useMainMonitor = useMainMonitor;
+ return true;
+ } else {
+ this.monitors = null;
+ this.useMainMonitor = true;
+ return false;
+ }
} else {
WindowImpl.this.fullscreen = fullscreen; // set current state for createNative(..)
+ WindowImpl.this.fullscreenMonitors = monitors;
+ WindowImpl.this.fullscreenUseMainMonitor = useMainMonitor;
return false;
}
}
@@ -1777,19 +1827,32 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// set current state
WindowImpl.this.fullscreen = fullscreen;
- final ScreenMode sm = screen.getCurrentScreenMode();
int x,y,w,h;
+ final RectangleImmutable viewport;
+ final int fs_span_flag;
if(fullscreen) {
+ if( null == monitors ) {
+ if( useMainMonitor ) {
+ monitors = new ArrayList();
+ monitors.add( getMainMonitor() );
+ } else {
+ monitors = getScreen().getMonitorDevices();
+ }
+ }
+ fs_span_flag = monitors.size() > 1 ? FLAG_IS_FULLSCREEN_SPAN : 0 ;
+ viewport = MonitorDevice.unionOfViewports(new Rectangle(), monitors);
nfs_x = getX();
nfs_y = getY();
nfs_width = getWidth();
nfs_height = getHeight();
- x = screen.getX();
- y = screen.getY();
- w = sm.getRotatedWidth();
- h = sm.getRotatedHeight();
+ x = viewport.getX();
+ y = viewport.getY();
+ w = viewport.getWidth();
+ h = viewport.getHeight();
} else {
+ fs_span_flag = 0;
+ viewport = null;
x = nfs_x;
y = nfs_y;
w = nfs_width;
@@ -1809,9 +1872,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
}
+ monitors = null; // clear references ASAP
+ useMainMonitor = true;
if(DEBUG_IMPLEMENTATION) {
System.err.println("Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+
- ", virtl-size: "+screen.getWidth()+"x"+screen.getHeight()+", SM "+sm.getRotatedWidth()+"x"+sm.getRotatedHeight());
+ ", virtl-size: "+screen.getWidth()+"x"+screen.getHeight()+", monitorsViewport "+viewport);
}
DisplayImpl display = (DisplayImpl) screen.getDisplay();
@@ -1831,7 +1896,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
try {
reconfigureWindowImpl(x, y, w, h,
getReconfigureFlags( ( ( null != parentWindowLocked ) ? FLAG_CHANGE_PARENTING : 0 ) |
- FLAG_CHANGE_FULLSCREEN | FLAG_CHANGE_DECORATION, wasVisible) );
+ fs_span_flag | FLAG_CHANGE_FULLSCREEN | FLAG_CHANGE_DECORATION, wasVisible) );
} finally {
if(null!=parentWindowLocked) {
parentWindowLocked.unlockSurface();
@@ -1860,8 +1925,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
@Override
public boolean setFullscreen(boolean fullscreen) {
+ return setFullscreenImpl(fullscreen, true, null);
+ }
+
+ @Override
+ public boolean setFullscreen(List monitors) {
+ return setFullscreenImpl(true, false, monitors);
+ }
+
+ private boolean setFullscreenImpl(boolean fullscreen, boolean useMainMonitor, List monitors) {
synchronized(fullScreenAction) {
- if( fullScreenAction.init(fullscreen) ) {
+ if( fullScreenAction.init(fullscreen, useMainMonitor, monitors) ) {
if(fullScreenAction.fsOn() && isOffscreenInstance(WindowImpl.this, parentWindow)) {
// enable fullscreen on offscreen instance
if(null != parentWindow) {
@@ -1887,13 +1961,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
return this.fullscreen;
}
}
-
- private class ScreenModeListenerImpl implements ScreenModeListener {
+
+ private class ScreenModeListenerImpl implements MonitorModeListener {
boolean animatorPaused = false;
- public void screenModeChangeNotify(ScreenMode sm) {
+ public void monitorModeChangeNotify(MonitorEvent me) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.screenModeChangeNotify: "+sm);
+ System.err.println("Window.screenModeChangeNotify: "+me);
}
if(null!=lifecycleHook) {
@@ -1901,9 +1975,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- public void screenModeChanged(ScreenMode sm, boolean success) {
+ public void monitorModeChanged(MonitorEvent me, boolean success) {
if(DEBUG_IMPLEMENTATION) {
- System.err.println("Window.screenModeChanged: "+sm+", success: "+success);
+ System.err.println("Window.screenModeChanged: "+me+", success: "+success);
}
if(success) {
@@ -1911,10 +1985,19 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// Didn't pass above notify method. probably detected screen change after it happened.
animatorPaused = lifecycleHook.pauseRenderingAction();
}
- DimensionImmutable screenSize = sm.getMonitorMode().getSurfaceSize().getResolution();
- if ( getHeight() > screenSize.getHeight() ||
- getWidth() > screenSize.getWidth() ) {
- setSize(screenSize.getWidth(), screenSize.getHeight());
+ if( !fullscreen ) {
+ // FIXME: Need to take all covered monitors into account
+ final MonitorDevice mainMonitor = getMainMonitor();
+ final MonitorDevice eventMonitor = me.getMonitor();
+ if( mainMonitor == eventMonitor ) {
+ final RectangleImmutable rect = new Rectangle(getX(), getY(), getWidth(), getHeight());
+ final RectangleImmutable viewport = mainMonitor.getViewport();
+ final RectangleImmutable isect = viewport.intersection(rect);
+ if ( getHeight() > isect.getHeight() ||
+ getWidth() > isect.getWidth() ) {
+ setSize(isect.getWidth(), isect.getHeight());
+ }
+ }
}
}
@@ -2563,14 +2646,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
}
}
- private boolean waitForVisible(boolean visible, boolean failFast) {
+ /** Returns -1 if failed, otherwise remaining time until {@link #TIMEOUT_NATIVEWINDOW}, maybe zero. */
+ private long waitForVisible(boolean visible, boolean failFast) {
return waitForVisible(visible, failFast, TIMEOUT_NATIVEWINDOW);
}
- private boolean waitForVisible(boolean visible, boolean failFast, long timeOut) {
+ /** Returns -1 if failed, otherwise remaining time until timeOut, maybe zero. */
+ private long waitForVisible(boolean visible, boolean failFast, long timeOut) {
final DisplayImpl display = (DisplayImpl) screen.getDisplay();
display.dispatchMessagesNative(); // status up2date
- for(long sleep = timeOut; 0
+ * Since WM may not obey our positional request exactly, we allow a tolerance of 2 times insets[left/top], or 64 pixels, whatever is greater.
+ *
+ */
+ private boolean waitForPosition(boolean useCustomPosition, int x, int y, long timeOut) {
+ final DisplayImpl display = (DisplayImpl) screen.getDisplay();
+ final int maxDX, maxDY;
+ {
+ final InsetsImmutable insets = getInsets();
+ maxDX = Math.max(64, insets.getLeftWidth() * 2);
+ maxDY = Math.max(64, insets.getTopHeight() * 2);
+ }
+ long remaining = timeOut;
+ boolean ok;
+ do {
+ if( useCustomPosition ) {
+ ok = Math.abs(x - getX()) <= maxDX && Math.abs(y - getY()) <= maxDY ;
+ } else {
+ ok = !autoPosition;
+ }
+ if( !ok ) {
+ try { Thread.sleep(10); } catch (InterruptedException ie) {}
+ display.dispatchMessagesNative(); // status up2date
+ remaining-=10;
+ }
+ } while ( 0getX() || 0>getY()) {
diff --git a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java
index 6b1283a00..8e584fc58 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/ScreenDriver.java
@@ -35,12 +35,15 @@ package jogamp.newt.driver.awt;
import java.awt.DisplayMode;
+import jogamp.newt.MonitorModeProps.Cache;
import jogamp.newt.ScreenImpl;
import javax.media.nativewindow.util.Dimension;
import javax.media.nativewindow.util.Point;
import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
public class ScreenDriver extends ScreenImpl {
public ScreenDriver() {
@@ -68,14 +71,19 @@ public class ScreenDriver extends ScreenImpl {
return idx; // pass through ...
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode();
- if(null != mode) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(mode.getWidth());
- virtualSize.setHeight(mode.getHeight());
- }
+ @Override
+ protected void collectNativeMonitorModesAndDevicesImpl(Cache cache) {
+ final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode();
+ }
+
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(MonitorDevice monitor) {
+ return null;
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(MonitorDevice monitor, MonitorMode mode) {
+ return false;
}
}
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java
index deb2a534b..afaedffe3 100644
--- a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java
@@ -35,8 +35,13 @@
package jogamp.newt.driver.bcm.egl;
import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+
+import jogamp.newt.MonitorModeProps;
+import jogamp.newt.ScreenImpl;
+
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
public class ScreenDriver extends jogamp.newt.ScreenImpl {
@@ -58,11 +63,48 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl {
return 0; // only one screen available
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(fixedWidth); // FIXME
- virtualSize.setHeight(fixedHeight); // FIXME
+ @Override
+ protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) {
+ int[] props = new int[ MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL ];
+ int i = 0;
+ props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
+ props[i++] = fixedWidth; // FIXME
+ props[i++] = fixedHeight; // FIXME
+ props[i++] = ScreenImpl.default_sm_bpp; // FIXME
+ props[i++] = ScreenImpl.default_sm_rate * 100; // FIXME
+ props[i++] = 0; // flags
+ props[i++] = 0; // mode_idx
+ props[i++] = 0; // rotation
+ final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
+
+ props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES];
+ i = 0;
+ props[i++] = props.length;
+ props[i++] = 0; // crt_idx
+ props[i++] = ScreenImpl.default_sm_widthmm; // FIXME
+ props[i++] = ScreenImpl.default_sm_heightmm; // FIXME
+ props[i++] = 0; // rotated viewport x
+ props[i++] = 0; // rotated viewport y
+ props[i++] = fixedWidth; // FIXME rotated viewport width
+ props[i++] = fixedHeight; // FIXME rotated viewport height
+ MonitorModeProps.streamInMonitorDevice(null, cache, this, cache.monitorModes, currentMode, props, 0);
+ }
+
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) {
+ return monitor.getSupportedModes().get(0);
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) {
+ return false;
+ }
+
+ protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) {
+ vOriginSize.setX(0);
+ vOriginSize.setY(0);
+ vOriginSize.setWidth(fixedWidth); // FIXME
+ vOriginSize.setHeight(fixedHeight); // FIXME
}
//----------------------------------------------------------------------
diff --git a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java
index 787d1a1b4..f7973def8 100644
--- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/ScreenDriver.java
@@ -29,9 +29,12 @@
package jogamp.newt.driver.bcm.vc.iv;
import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+
+import jogamp.newt.MonitorModeProps;
import jogamp.newt.ScreenImpl;
public class ScreenDriver extends ScreenImpl {
@@ -53,13 +56,52 @@ public class ScreenDriver extends ScreenImpl {
return 0; // only one screen available
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(cachedWidth);
- virtualSize.setHeight(cachedHeight);
+ @Override
+ protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) {
+ int[] props = new int[ MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL ];
+ int i = 0;
+ props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
+ props[i++] = cachedWidth; // width
+ props[i++] = cachedHeight; // height
+ props[i++] = ScreenImpl.default_sm_bpp; // FIXME
+ props[i++] = ScreenImpl.default_sm_rate * 100; // FIXME
+ props[i++] = 0; // flags
+ props[i++] = 0; // mode_idx
+ props[i++] = 0; // rotation
+ final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
+
+ props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES];
+ i = 0;
+ props[i++] = props.length;
+ props[i++] = 0; // crt_idx
+ props[i++] = ScreenImpl.default_sm_widthmm; // FIXME
+ props[i++] = ScreenImpl.default_sm_heightmm; // FIXME
+ props[i++] = 0; // rotated viewport x
+ props[i++] = 0; // rotated viewport y
+ props[i++] = cachedWidth; // rotated viewport width
+ props[i++] = cachedWidth; // rotated viewport height
+ MonitorModeProps.streamInMonitorDevice(null, cache, this, cache.monitorModes, currentMode, props, 0);
+ }
+
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) {
+ return monitor.getSupportedModes().get(0);
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) {
+ return false;
+ }
+
+ @Override
+ protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) {
+ vOriginSize.setX(0);
+ vOriginSize.setY(0);
+ vOriginSize.setWidth(cachedWidth);
+ vOriginSize.setHeight(cachedHeight);
}
+ /** Called from {@link #initNative()}. */
protected void setScreenSize(int width, int height) {
cachedWidth = width;
cachedHeight = height;
diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java
index 8eed14dde..4c47eb0d8 100644
--- a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java
@@ -36,8 +36,13 @@ package jogamp.newt.driver.intel.gdl;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+
+import jogamp.newt.MonitorModeProps;
+import jogamp.newt.ScreenImpl;
+
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
public class ScreenDriver extends jogamp.newt.ScreenImpl {
@@ -60,11 +65,48 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl {
return 0; // only one screen available
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(cachedWidth);
- virtualSize.setHeight(cachedHeight);
+ @Override
+ protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) {
+ int[] props = new int[ MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL ];
+ int i = 0;
+ props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
+ props[i++] = cachedWidth; // width
+ props[i++] = cachedHeight; // height
+ props[i++] = ScreenImpl.default_sm_bpp; // FIXME
+ props[i++] = ScreenImpl.default_sm_rate * 100; // FIXME
+ props[i++] = 0; // flags
+ props[i++] = 0; // mode_idx
+ props[i++] = 0; // rotation
+ final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
+
+ props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES];
+ i = 0;
+ props[i++] = props.length;
+ props[i++] = 0; // crt_idx
+ props[i++] = ScreenImpl.default_sm_widthmm; // FIXME
+ props[i++] = ScreenImpl.default_sm_heightmm; // FIXME
+ props[i++] = 0; // rotated viewport x
+ props[i++] = 0; // rotated viewport y
+ props[i++] = cachedWidth; // rotated viewport width
+ props[i++] = cachedWidth; // rotated viewport height
+ MonitorModeProps.streamInMonitorDevice(null, cache, this, cache.monitorModes, currentMode, props, 0);
+ }
+
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) {
+ return monitor.getSupportedModes().get(0);
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) {
+ return false;
+ }
+
+ protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) {
+ vOriginSize.setX(0);
+ vOriginSize.setY(0);
+ vOriginSize.setWidth(cachedWidth);
+ vOriginSize.setHeight(cachedHeight);
}
//----------------------------------------------------------------------
diff --git a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java
index 656bcf5c9..dc87c3c08 100644
--- a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java
@@ -35,9 +35,12 @@
package jogamp.newt.driver.kd;
import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+
+import jogamp.newt.MonitorModeProps;
import jogamp.newt.ScreenImpl;
public class ScreenDriver extends ScreenImpl {
@@ -58,11 +61,48 @@ public class ScreenDriver extends ScreenImpl {
return 0; // only one screen available
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(cachedWidth);
- virtualSize.setHeight(cachedHeight);
+ @Override
+ protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) {
+ int[] props = new int[ MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL ];
+ int i = 0;
+ props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL;
+ props[i++] = cachedWidth; // width
+ props[i++] = cachedHeight; // height
+ props[i++] = ScreenImpl.default_sm_bpp; // FIXME
+ props[i++] = ScreenImpl.default_sm_rate * 100; // FIXME
+ props[i++] = 0; // flags
+ props[i++] = 0; // mode_idx
+ props[i++] = 0; // rotation
+ final MonitorMode currentMode = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
+
+ props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES - 1 - MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES];
+ i = 0;
+ props[i++] = props.length;
+ props[i++] = 0; // crt_idx
+ props[i++] = ScreenImpl.default_sm_widthmm; // FIXME
+ props[i++] = ScreenImpl.default_sm_heightmm; // FIXME
+ props[i++] = 0; // rotated viewport x
+ props[i++] = 0; // rotated viewport y
+ props[i++] = cachedWidth; // rotated viewport width
+ props[i++] = cachedWidth; // rotated viewport height
+ MonitorModeProps.streamInMonitorDevice(null, cache, this, cache.monitorModes, currentMode, props, 0);
+ }
+
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) {
+ return monitor.getSupportedModes().get(0);
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) {
+ return false;
+ }
+
+ protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) {
+ vOriginSize.setX(0);
+ vOriginSize.setY(0);
+ vOriginSize.setWidth(cachedWidth);
+ vOriginSize.setHeight(cachedHeight);
}
protected void sizeChanged(int w, int h) {
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java
index 24e60ba0a..a3bb26731 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java
@@ -34,28 +34,19 @@
package jogamp.newt.driver.macosx;
-import java.util.List;
-
import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.DimensionImmutable;
-import javax.media.nativewindow.util.Point;
+import jogamp.newt.MonitorModeProps;
import jogamp.newt.ScreenImpl;
-import com.jogamp.common.util.IntObjectHashMap;
-import com.jogamp.newt.ScreenMode;
-import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.common.util.ArrayHashSet;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
public class ScreenDriver extends ScreenImpl {
- // caching native CGDisplayScreenSize() results, since it's ridiculous slow (~6 ms each call)
- private static IntObjectHashMap/**/ scrnIdx2Dimension;
-
static {
DisplayDriver.initSingleton();
- scrnIdx2Dimension = new IntObjectHashMap();
- scrnIdx2Dimension.setKeyNotFoundValue(null);
}
public ScreenDriver() {
@@ -67,77 +58,67 @@ public class ScreenDriver extends ScreenImpl {
protected void closeNativeImpl() { }
- private static native int getWidthImpl0(int scrn_idx);
- private static native int getHeightImpl0(int scrn_idx);
-
- private int[] getScreenModeIdx(int idx) {
- // caching native CGDisplayScreenSize() results, since it's ridiculous slow (~6 ms each call)
- DimensionImmutable dim = (DimensionImmutable) scrnIdx2Dimension.get(screen_idx);
- if(null == dim) {
- int[] res = getScreenSizeMM0(screen_idx);
- if(null == res || 0 == res.length) {
- return null;
- }
- dim = new Dimension(res[0], res[1]);
- scrnIdx2Dimension.put(screen_idx, dim);
- }
-
- int[] modeProps = getScreenMode0(screen_idx, idx, dim.getWidth(), dim.getHeight());
- if (null == modeProps || 0 == modeProps.length) {
- return null;
+ private MonitorMode getMonitorModeImpl(MonitorModeProps.Cache cache, int crt_idx, int mode_idx) {
+ final int[] modeProps = getMonitorMode0(crt_idx, mode_idx);
+ final MonitorMode res;
+ if (null == modeProps || 0 >= modeProps.length) {
+ res = null;
+ } else {
+ res = MonitorModeProps.streamInMonitorMode(null, cache, modeProps, 0);
}
- if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) {
- throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length);
- }
- return modeProps;
+ return res;
}
-
- private int nativeModeIdx;
- protected int[] getScreenModeFirstImpl() {
- nativeModeIdx = 0;
- return getScreenModeNextImpl();
- }
-
- protected int[] getScreenModeNextImpl() {
- int[] modeProps = getScreenModeIdx(nativeModeIdx);
- if (null != modeProps && 0 < modeProps.length) {
- nativeModeIdx++;
- return modeProps;
- }
- return null;
+ @Override
+ protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) {
+ int crtIdx = 0;
+ int modeIdx = 0;
+ ArrayHashSet supportedModes = new ArrayHashSet();
+ do {
+ final MonitorMode mode = getMonitorModeImpl(cache, crtIdx, modeIdx);
+ if( null != mode ) {
+ supportedModes.getOrAdd(mode);
+ // next mode on same monitor
+ modeIdx++;
+ } else if( 0 < modeIdx ) {
+ // end of monitor modes - got at least one mode
+ final MonitorMode currentMode = getMonitorModeImpl(cache, crtIdx, -1);
+ if ( null == currentMode ) {
+ throw new InternalError("Could not gather current mode of device "+crtIdx+", but gathered "+modeIdx+" modes");
+ }
+ final int[] monitorProps = getMonitorProps0(crtIdx);
+ if ( null == monitorProps ) {
+ throw new InternalError("Could not gather device "+crtIdx+", but gathered "+modeIdx+" modes");
+ }
+ // merge monitor-props + supported modes
+ MonitorModeProps.streamInMonitorDevice(null, cache, this, supportedModes, currentMode, monitorProps, 0);
+
+ // next monitor, 1st mode
+ supportedModes= new ArrayHashSet();
+ crtIdx++;
+ modeIdx=0;
+ } else {
+ // end of monitor
+ break;
+ }
+ } while ( true );
}
- protected ScreenMode getCurrentScreenModeImpl() {
- int[] modeProps = getScreenModeIdx(-1);
- if (null != modeProps && 0 < modeProps.length) {
- return ScreenModeUtil.streamIn(modeProps, 0);
- }
- return null;
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(MonitorDevice monitor) {
+ return getMonitorModeImpl(null, monitor.getId(), -1);
}
- protected boolean setCurrentScreenModeImpl(final ScreenMode screenMode) {
- final List screenModes = this.getScreenModesOrig();
- final int screenModeIdx = screenModes.indexOf(screenMode);
- if(0>screenModeIdx) {
- throw new RuntimeException("ScreenMode not element of ScreenMode list: "+screenMode);
- }
- final int nativeModeIdx = getScreenModesIdx2NativeIdx().get(screenModeIdx);
- return setScreenMode0(screen_idx, nativeModeIdx);
+ @Override
+ protected boolean setCurrentMonitorModeImpl(MonitorDevice monitor, MonitorMode mode) {
+ return setMonitorMode0(monitor.getId(), mode.getId(), mode.getRotation());
}
protected int validateScreenIndex(int idx) {
- return idx;
+ return 0; // big-desktop w/ multiple monitor attached, only one screen available
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(0);
- virtualOrigin.setY(0);
- virtualSize.setWidth(getWidthImpl0(screen_idx));
- virtualSize.setHeight(getHeightImpl0(screen_idx));
- }
-
- private native int[] getScreenSizeMM0(int screen_idx);
- private native int[] getScreenMode0(int screen_index, int mode_index, int widthMM, int heightMM);
- private native boolean setScreenMode0(int screen_index, int mode_idx);
+ private native int[] getMonitorProps0(int crt_idx);
+ private native int[] getMonitorMode0(int crt_index, int mode_idx);
+ private native boolean setMonitorMode0(int crt_index, int nativeId, int rot);
}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
index bb72350e3..6370782df 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
@@ -478,7 +478,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
if( 0 != surfaceHandle ) {
throw new NativeWindowException("Internal Error - create w/o window, but has Newt NSView");
}
- surfaceHandle = createView0(pS.getX(), pS.getY(), width, height, fullscreen, getScreen().getIndex());
+ surfaceHandle = createView0(pS.getX(), pS.getY(), width, height, fullscreen);
if( 0 == surfaceHandle ) {
throw new NativeWindowException("Could not create native view "+Thread.currentThread().getName()+" "+this);
}
@@ -487,7 +487,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
final long newWin = createWindow0( pS.getX(), pS.getY(), width, height, fullscreen,
( isUndecorated() || offscreenInstance ) ? NSBorderlessWindowMask :
NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
- NSBackingStoreBuffered, getScreen().getIndex(), surfaceHandle);
+ NSBackingStoreBuffered, surfaceHandle);
if ( newWin == 0 ) {
throw new NativeWindowException("Could not create native window "+Thread.currentThread().getName()+" "+this);
}
@@ -497,9 +497,8 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
// Non blocking initialization on main-thread!
OSXUtil.RunOnMainThread(false, new Runnable() {
public void run() {
- initWindow0( parentWin, newWin,
- pS.getX(), pS.getY(), width, height,
- isOpaque, fullscreen, visible && !offscreenInstance, getScreen().getIndex(), surfaceHandle);
+ initWindow0( parentWin, newWin, pS.getX(), pS.getY(), width, height,
+ isOpaque, fullscreen, visible && !offscreenInstance, surfaceHandle);
if( offscreenInstance ) {
orderOut0(0!=parentWin ? parentWin : newWin);
} else {
@@ -514,11 +513,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
protected static native boolean initIDs0();
- private native long createView0(int x, int y, int w, int h, boolean fullscreen, int screen_idx);
- private native long createWindow0(int x, int y, int w, int h, boolean fullscreen, int windowStyle, int backingStoreType, int screen_idx, long view);
+ private native long createView0(int x, int y, int w, int h, boolean fullscreen);
+ private native long createWindow0(int x, int y, int w, int h, boolean fullscreen, int windowStyle, int backingStoreType, long view);
/** Must be called on Main-Thread */
private native void initWindow0(long parentWindow, long window, int x, int y, int w, int h,
- boolean opaque, boolean fullscreen, boolean visible, int screen_idx, long view);
+ boolean opaque, boolean fullscreen, boolean visible, long view);
private native boolean lockSurface0(long window, long view);
private native boolean unlockSurface0(long window, long view);
/** Must be called on Main-Thread */
diff --git a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
index 948b29460..342829691 100644
--- a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java
@@ -34,91 +34,143 @@
package jogamp.newt.driver.windows;
import javax.media.nativewindow.DefaultGraphicsScreen;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.Point;
+import javax.media.nativewindow.util.Rectangle;
+import jogamp.newt.MonitorModeProps;
import jogamp.newt.ScreenImpl;
-import com.jogamp.newt.ScreenMode;
-import com.jogamp.newt.util.ScreenModeUtil;
+import com.jogamp.common.util.ArrayHashSet;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
+import com.jogamp.newt.Screen;
public class ScreenDriver extends ScreenImpl {
static {
DisplayDriver.initSingleton();
+ if( Screen.DEBUG ) {
+ dumpMonitorInfo0();
+ }
}
public ScreenDriver() {
}
+ @Override
protected void createNativeImpl() {
aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), screen_idx);
}
+ @Override
protected void closeNativeImpl() {
}
- private int[] getScreenModeIdx(int idx) {
- int[] modeProps = getScreenMode0(screen_idx, idx);
- if (null == modeProps || 0 == modeProps.length) {
+ private final String getAdapterName(int crt_idx) {
+ return getAdapterName0(crt_idx);
+ }
+ private final String getActiveMonitorName(String adapterName, int monitor_idx) {
+ return getActiveMonitorName0(adapterName, monitor_idx);
+ }
+
+ private final MonitorMode getMonitorModeImpl(MonitorModeProps.Cache cache, String adapterName, int crtModeIdx) {
+ if( null == adapterName ) {
return null;
}
- if(modeProps.length < ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL) {
- throw new RuntimeException("properties array too short, should be >= "+ScreenModeUtil.NUM_SCREEN_MODE_PROPERTIES_ALL+", is "+modeProps.length);
+ final String activeMonitorName = getActiveMonitorName(adapterName, 0);
+ final int[] modeProps = null != activeMonitorName ? getMonitorMode0(adapterName, crtModeIdx) : null;
+ if ( null == modeProps || 0 >= modeProps.length) {
+ return null;
}
- return modeProps;
+ return MonitorModeProps.streamInMonitorMode(null, cache, modeProps, 0);
}
- private int nativeModeIdx;
-
- protected int[] getScreenModeFirstImpl() {
- nativeModeIdx = 0;
- return getScreenModeNextImpl();
- }
-
- protected int[] getScreenModeNextImpl() {
- int[] modeProps = getScreenModeIdx(nativeModeIdx);
- if (null != modeProps && 0 < modeProps.length) {
- nativeModeIdx++;
- return modeProps;
+ @Override
+ protected void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) {
+ int crtIdx = 0;
+ ArrayHashSet supportedModes = new ArrayHashSet();
+ String adapterName = getAdapterName(crtIdx);
+ while( null != adapterName ) {
+ int crtModeIdx = 0;
+ MonitorMode mode;
+ do {
+ mode = getMonitorModeImpl(cache, adapterName, crtModeIdx);
+ if( null != mode ) {
+ supportedModes.getOrAdd(mode);
+ // next mode on same monitor
+ crtModeIdx++;
+ }
+ } while( null != mode);
+ if( 0 < crtModeIdx ) {
+ // has at least one mode -> add device
+ final MonitorMode currentMode = getMonitorModeImpl(cache, adapterName, -1);
+ if ( null != currentMode ) { // enabled
+ final int[] monitorProps = getMonitorDevice0(adapterName, crtIdx);
+ // merge monitor-props + supported modes
+ MonitorModeProps.streamInMonitorDevice(null, cache, this, supportedModes, currentMode, monitorProps, 0);
+
+ // next monitor, 1st mode
+ supportedModes= new ArrayHashSet();
+ }
+ }
+ crtIdx++;
+ adapterName = getAdapterName(crtIdx);
}
- return null;
}
-
- protected ScreenMode getCurrentScreenModeImpl() {
- int[] modeProps = getScreenModeIdx(-1);
- if (null != modeProps && 0 < modeProps.length) {
- return ScreenModeUtil.streamIn(modeProps, 0);
+
+ @Override
+ protected Rectangle getNativeMonitorDeviceViewportImpl(MonitorDevice monitor) {
+ final String adapterName = getAdapterName(monitor.getId());
+ if( null != adapterName ) {
+ final String activeMonitorName = getActiveMonitorName(adapterName, 0);
+ if( null != activeMonitorName ) {
+ final int[] monitorProps = getMonitorDevice0(adapterName, monitor.getId());
+ int offset = MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT;
+ return new Rectangle(monitorProps[offset++], monitorProps[offset++], monitorProps[offset++], monitorProps[offset++]);
+ }
}
return null;
}
- protected boolean setCurrentScreenModeImpl(ScreenMode sm) {
- return setScreenMode0(screen_idx,
- sm.getMonitorMode().getSurfaceSize().getResolution().getWidth(),
- sm.getMonitorMode().getSurfaceSize().getResolution().getHeight(),
- sm.getMonitorMode().getSurfaceSize().getBitsPerPixel(),
- sm.getMonitorMode().getRefreshRate(),
- sm.getRotation());
+ @Override
+ protected MonitorMode queryCurrentMonitorModeImpl(MonitorDevice monitor) {
+ return getMonitorModeImpl(null, getAdapterName(monitor.getId()), -1);
+ }
+
+ @Override
+ protected boolean setCurrentMonitorModeImpl(MonitorDevice monitor, MonitorMode mode) {
+ return setMonitorMode0(monitor.getId(),
+ -1, -1, // no fixed position!
+ mode.getSurfaceSize().getResolution().getWidth(),
+ mode.getSurfaceSize().getResolution().getHeight(),
+ mode.getSurfaceSize().getBitsPerPixel(),
+ (int)mode.getRefreshRate(), // simply cut-off, orig is int
+ mode.getFlags(),
+ mode.getRotation());
}
+ @Override
protected int validateScreenIndex(int idx) {
- return 0; // big-desktop, only one screen available
+ return 0; // big-desktop w/ multiple monitor attached, only one screen available
}
- protected void getVirtualScreenOriginAndSize(Point virtualOrigin, Dimension virtualSize) {
- virtualOrigin.setX(getOriginX0(screen_idx));
- virtualOrigin.setY(getOriginY0(screen_idx));
- virtualSize.setWidth(getWidthImpl0(screen_idx));
- virtualSize.setHeight(getHeightImpl0(screen_idx));
+ @Override
+ protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) {
+ vOriginSize.setX(getVirtualOriginX0());
+ vOriginSize.setY(getVirtualOriginY0());
+ vOriginSize.setWidth(getVirtualWidthImpl0());
+ vOriginSize.setHeight(getVirtualHeightImpl0());
}
// Native calls
- private native int getOriginX0(int screen_idx);
- private native int getOriginY0(int screen_idx);
- private native int getWidthImpl0(int scrn_idx);
- private native int getHeightImpl0(int scrn_idx);
+ private native int getVirtualOriginX0();
+ private native int getVirtualOriginY0();
+ private native int getVirtualWidthImpl0();
+ private native int getVirtualHeightImpl0();
- private native int[] getScreenMode0(int screen_index, int mode_index);
- private native boolean setScreenMode0(int screen_index, int width, int height, int bits, int freq, int rot);
+ private static native void dumpMonitorInfo0();
+ private native String getAdapterName0(int crt_index);
+ private native String getActiveMonitorName0(String adapterName, int crtModeIdx);
+ private native int[] getMonitorMode0(String adapterName, int crtModeIdx);
+ private native int[] getMonitorDevice0(String adapterName, int monitor_index);
+ private native boolean setMonitorMode0(int monitor_index, int x, int y, int width, int height, int bits, int freq, int flags, int rot);
}
diff --git a/src/newt/classes/jogamp/newt/driver/x11/RandR.java b/src/newt/classes/jogamp/newt/driver/x11/RandR.java
index 485d976ec..c569e5fd8 100644
--- a/src/newt/classes/jogamp/newt/driver/x11/RandR.java
+++ b/src/newt/classes/jogamp/newt/driver/x11/RandR.java
@@ -27,13 +27,50 @@
*/
package jogamp.newt.driver.x11;
-import com.jogamp.newt.ScreenMode;
+import java.util.List;
+
+import jogamp.newt.MonitorModeProps;
+
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.MonitorMode;
public interface RandR {
- int[] getScreenModeFirstImpl(final long dpy, final int screen_idx);
- int[] getScreenModeNextImpl(final long dpy, final int screen_idx);
- ScreenMode getCurrentScreenModeImpl(final long dpy, final int screen_idx);
- boolean setCurrentScreenModeImpl(final long dpy, final int screen_idx, final ScreenMode screenMode, final int screenModeIdx, final int resolutionIdx);
+ void dumpInfo(final long dpy, final int screen_idx);
+
+ /**
+ * Encapsulate initial device query allowing caching of internal data structures.
+ * Methods covered:
+ *