diff options
author | Sven Gothel <[email protected]> | 2014-05-26 18:54:27 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-05-26 18:54:27 +0200 |
commit | 56d60b36798fa8dae48bf2aa5e2de6f3178ab0d1 (patch) | |
tree | 4c86190128414205d0b768780e3272e32bd1e81a /src | |
parent | 98ed02cdb7b325d8afde596a5ef04f97be2018d4 (diff) |
Bug 741 HiDPI: Refine Monitor/Screen [virtual] Viewport Definition / Add NEWT Support / Fix JAWT getPixelScale deadlock
- NativeWindow/Surface/NEWT API DOC: Define Coordinate System of Window and Screen
- OSXUtil: Add getPixelScale(..) via Screen index and 'windowOrView'
- JAWTWindow/JAWTUtil.getPixelScale(..): Use pre-fetched AWT GraphicsConfiguration to solve AWT-TreeLock (deadlock)
- [Virtual] Viewport of MonitorDevice and Screen:
- Properly calculate and expose [virtual] viewport in window and pixel units
- OSX Monitor viewports in pixel units are 'reconstructed'
- Window/Viewport to Monitor selection shall be perfomed via window units (unique)
- OSX NEWT Window create/init (native): Use given size and coordinates even in fullscreen mode
Don't override by quering NSScreen coordinates, trust given values.
- Fix test cases, i.e. usage of pixel- and window-units
Diffstat (limited to 'src')
60 files changed, 1550 insertions, 799 deletions
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 65b61d3aa..c8102973f 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -563,7 +563,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing super.addNotify(); awtWindowClosingProtocol.addClosingListener(); { - final int s = JAWTUtil.getPixelScale(this); + final int s = JAWTUtil.getPixelScale(getGraphicsConfiguration()); pixelScale = 0 < s ? s : 1; } if (DEBUG) { diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 24bc8fa51..d4f058201 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -271,7 +271,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, final Rectangle jb = new Rectangle(jawtBounds.getX(), jawtBounds.getY(), jawtBounds.getWidth(), jawtBounds.getHeight()); final int newPixelScale; { - final int s = JAWTUtil.getPixelScale(component); + final int s = JAWTUtil.getPixelScale(config.getAWTGraphicsConfiguration()); newPixelScale = 0 < s ? s : 1; } final boolean changedBounds = !bounds.equals(jb); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java index f8596bc74..8131ee283 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java @@ -32,8 +32,8 @@ package javax.media.nativewindow; * Provides low-level information required for * hardware-accelerated rendering using a surface in a platform-independent manner. * <p> - * All values of this interface are represented in pixel units, - * see {@link NativeWindow}. + * All values of this interface are represented in pixel units, if not stated otherwise. + * See {@link NativeWindow}. * </p> * <p> * A NativeSurface created for a particular on- or offscreen component is diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java index 242f25d43..63a643f3c 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -48,8 +48,18 @@ import javax.media.nativewindow.util.Point; * information such as {@link #getWindowHandle() window-handle}, * {@link #getWindowWidth() window-size} and {@link #getX() window-position}. * <p> - * All values of this interface are represented in window units. - * see {@link NativeSurface}. + * All values of this interface are represented in window units, if not stated otherwise. + * See {@link NativeSurface}. + * </p> + * + * <a name="coordinateSystem"><h5>Coordinate System</h5></a> + * <p> + * <ul> + * <li>Abstract screen space has it's origin in the top-left corner, and may not be at 0/0.</li> + * <li>Window origin is in it's top-left corner, see {@link #getX()} and {@link #getY()}. </li> + * <li>Window client-area excludes {@link #getInsets() insets}, i.e. window decoration.</li> + * <li>Window origin is relative to it's parent window if exist, or the screen position (top-level).</li> + * </ul> * </p> * <p> * A window toolkit such as the AWT may either implement this interface @@ -111,18 +121,36 @@ public interface NativeWindow extends NativeSurface { /** Returns the current x position of this window, relative to it's parent. */ /** - * @return the current x position of the top-left corner - * of the client area relative to it's parent in window units. - * Since the position reflects the client area, it does not include the insets. + * Returns the x position of the top-left corner + * of the client area relative to it's parent in window units. + * <p> + * If no parent exist (top-level window), this coordinate equals the screen coordinate. + * </p> + * <p> + * Since the position reflects the client area, it does not include the insets. + * </p> + * <p> + * See <a href="#coordinateSystem"> Coordinate System</a>. + * </p> * @see #getInsets() + * @see #getLocationOnScreen(Point) */ public int getX(); /** - * @return the current y position of the top-left corner - * of the client area relative to it's parent in window units. - * Since the position reflects the client area, it does not include the insets. + * Returns the current y position of the top-left corner + * of the client area relative to it's parent in window units. + * <p> + * If no parent exist (top-level window), this coordinate equals the screen coordinate. + * </p> + * <p> + * Since the position reflects the client area, it does not include the insets. + * </p> + * <p> + * See <a href="#coordinateSystem"> Coordinate System</a>. + * </p> * @see #getInsets() + * @see #getLocationOnScreen(Point) */ public int getY(); @@ -141,16 +169,23 @@ public interface NativeWindow extends NativeSurface { public int getWindowHeight(); /** - * Returns the current position of the top-left corner - * of the client area in window units. + * Returns the window's top-left client-area position in the screen. + * <p> + * If {@link Point} is not <code>null</code>, it is translated about the resulting screen position + * and returned. + * </p> + * <p> + * See <a href="#coordinateSystem"> Coordinate System</a>. + * </p> * <p> * Since the position reflects the client area, it does not include the insets. * </p> - * @param point if not null, - * {@link javax.media.nativewindow.util.Point#translate(javax.media.nativewindow.util.Point)} - * the passed {@link javax.media.nativewindow.util.Point} by this location on the screen and return it. - * @return either the passed non null translated point by the screen location of this NativeWindow, - * or a new instance with the screen location of this NativeWindow. + * @param point Optional {@link Point} storage. + * If not null, <code>null</code>, it is translated about the resulting screen position + * and returned. + * @see #getX() + * @see #getY() + * @see #getInsets() */ public Point getLocationOnScreen(Point point); diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index 387f40f89..92ec27b69 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -37,7 +37,6 @@ package jogamp.nativewindow.jawt; -import java.awt.Component; import java.awt.EventQueue; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; @@ -560,10 +559,9 @@ public class JAWTUtil { } /** - * Returns the pixel scale factor of the given {@link Component}'s {@link GraphicsDevice}, if supported. + * Returns the pixel scale factor of the given {@link GraphicsConfiguration}'s {@link GraphicsDevice}, if supported. * <p> - * If the component is not yet {@link Component#isDisplayable() displayable}, - * <code>zero</code> is returned. + * If the {@link GraphicsDevice} is <code>null</code>, <code>zero</code> is returned. * </p> * <p> * If the component does not support pixel scaling the default @@ -572,17 +570,21 @@ public class JAWTUtil { * <p> * Note: Currently only supported on OSX since 1.7.0_40 for HiDPI retina displays * </p> - * @param component the {@link Component} instance used to query the pixel scale + * @param gc the {@link GraphicsConfiguration} instance used to query the pixel scale * @return the pixel scale factor */ - public static final int getPixelScale(final Component component) { - final GraphicsConfiguration gc = component.getGraphicsConfiguration(); + public static final int getPixelScale(final GraphicsConfiguration gc) { final GraphicsDevice device = null != gc ? gc.getDevice() : null; + final int ps; if( null == device ) { - return 0; + ps = 0; } else { - return JAWTUtil.getPixelScale(device); + ps = JAWTUtil.getPixelScale(device); } + if( DEBUG ) { + System.err.println("JAWTWindow.updatePixelScale: Fetched "+ps); + } + return ps; } } diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 88ba531d1..31b06d360 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -122,6 +122,14 @@ public class OSXUtil implements ToolkitProperties { return (Insets) GetInsets0(windowOrView); } + public static double GetPixelScale(int screenIndex) { + return GetPixelScale0(screenIndex); + } + + public static double GetPixelScale(long windowOrView) { + return GetPixelScale1(windowOrView); + } + public static long CreateNSWindow(int x, int y, int width, int height) { return CreateNSWindow0(x, y, width, height); } @@ -365,6 +373,8 @@ public class OSXUtil implements ToolkitProperties { private static native boolean isNSWindow0(long object); private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y); private static native Object GetInsets0(long windowOrView); + private static native double GetPixelScale0(int screenIndex); + private static native double GetPixelScale1(long windowOrView); private static native long CreateNSWindow0(int x, int y, int width, int height); private static native void DestroyNSWindow0(long nsWindow); private static native long GetNSView0(long nsWindow); diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 0250bb7d1..2f5a44584 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -215,7 +215,7 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0 view = (NSView*) nsObj; win = [view window]; } else { - NativewindowCommon_throwNewRuntimeException(env, "neither win not view %p\n", nsObj); + NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); } NSRect frameRect = [win frame]; @@ -238,6 +238,75 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetInsets0 /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil + * Method: GetPixelScale0 + * Signature: (I)D + */ +JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale0 + (JNIEnv *env, jclass unused, jint screen_idx) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + CGFloat pixelScale; + NSScreen *screen; + NSArray *screens = [NSScreen screens]; + if( screen_idx<0 || screen_idx>=[screens count] ) { + screen = NULL; + pixelScale = 0.0; + } else { + screen = (NSScreen *) [screens objectAtIndex: screen_idx]; + pixelScale = 1.0; // default +NS_DURING + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling +NS_HANDLER +NS_ENDHANDLER + } + [pool release]; + + return (jdouble)pixelScale; +} + +/* + * Class: Java_jogamp_nativewindow_macosx_OSXUtil + * Method: GetPixelScale1 + * Signature: (J)D + */ +JNIEXPORT jdouble JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetPixelScale1 + (JNIEnv *env, jclass unused, jlong winOrView) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + + NSObject *nsObj = (NSObject*) (intptr_t) winOrView; + NSWindow* win = NULL; + NSView* view = NULL; + NSScreen *screen = NULL; + + if( [nsObj isKindOfClass:[NSWindow class]] ) { + win = (NSWindow*) nsObj; + view = [win contentView]; + screen = [win screen]; + } else if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) { + view = (NSView*) nsObj; + win = [view window]; + screen = [win screen]; + } else { + NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); + } + + CGFloat pixelScale = 1.0; // default +NS_DURING + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling +NS_HANDLER +NS_ENDHANDLER + + [pool release]; + + return (jdouble)pixelScale; +} + +/* + * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: CreateNSWindow0 * Signature: (IIIIZ)J */ diff --git a/src/newt/classes/com/jogamp/newt/MonitorDevice.java b/src/newt/classes/com/jogamp/newt/MonitorDevice.java index af0ce0146..8e5d305dd 100644 --- a/src/newt/classes/com/jogamp/newt/MonitorDevice.java +++ b/src/newt/classes/com/jogamp/newt/MonitorDevice.java @@ -52,6 +52,9 @@ import com.jogamp.common.util.ArrayHashSet; * <li>{@link RectangleImmutable} viewport (rotated)</li> * </ul></li> * </ul> + * <p> + * All values of this interface are represented in pixel units, if not stated otherwise. + * </p> */ public abstract class MonitorDevice { protected final Screen screen; // backref @@ -61,16 +64,18 @@ public abstract class MonitorDevice { protected final ArrayHashSet<MonitorMode> 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 Rectangle viewportPU; // in pixel units + protected Rectangle viewportWU; // in window units - protected MonitorDevice(Screen screen, int nativeId, DimensionImmutable sizeMM, Rectangle viewport, MonitorMode currentMode, ArrayHashSet<MonitorMode> supportedModes) { + protected MonitorDevice(Screen screen, int nativeId, DimensionImmutable sizeMM, Rectangle viewportPU, Rectangle viewportWU, MonitorMode currentMode, ArrayHashSet<MonitorMode> supportedModes) { this.screen = screen; this.nativeId = nativeId; this.sizeMM = sizeMM; this.originalMode = currentMode; this.supportedModes = supportedModes; this.currentMode = currentMode; - this.viewport = viewport; + this.viewportPU = viewportPU; + this.viewportWU = viewportWU; this.modeChanged = false; } @@ -170,11 +175,22 @@ public abstract class MonitorDevice { /** * Returns the {@link RectangleImmutable rectangular} portion - * of the rotated virtual {@link Screen} size in pixel units - * represented by this monitor. + * of the <b>rotated</b> virtual {@link Screen} size in pixel units + * represented by this monitor, i.e. top-left origin and size. + * @see Screen */ public final RectangleImmutable getViewport() { - return viewport; + return viewportPU; + } + + /** + * Returns the {@link RectangleImmutable rectangular} portion + * of the <b>rotated</b> virtual {@link Screen} size in window units + * represented by this monitor, i.e. top-left origin and size. + * @see Screen + */ + public final RectangleImmutable getViewportInWindowUnits() { + return viewportWU; } /** @@ -184,46 +200,45 @@ public abstract class MonitorDevice { * @param y y-coord in pixel units */ public final boolean contains(final int x, final int y) { - return x >= viewport.getX() && - x < viewport.getX() + viewport.getWidth() && - y >= viewport.getY() && - y < viewport.getY() + viewport.getHeight() ; + return x >= viewportPU.getX() && + x < viewportPU.getX() + viewportPU.getWidth() && + y >= viewportPU.getY() && + y < viewportPU.getY() + viewportPU.getHeight() ; } /** - * Returns the coverage of given rectangle in pixel units - * w/ this {@link #getViewport() viewport}, i.e. between <code>0.0</code> and <code>1.0</code>. - * <p> - * Coverage is computed by: - * <pre> - * isect = viewport.intersection(r); - * coverage = area( isect ) / area( viewport ) ; - * </pre> - * </p> - * @param r {@link RectangleImmutable rectangle} in pixel units - */ - public final float coverage(final RectangleImmutable r) { - return viewport.coverage(r); - } - - /** - * Returns the union of the given monitor's {@link #getViewport() viewport} in pixel units. - * @param result storage for result, will be returned + * Calculates the union of the given monitor's {@link #getViewport() viewport} in pixel- and window units. + * @param viewport storage for result in pixel units, maybe null + * @param viewportInWindowUnits storage for result in window units, maybe null * @param monitors given list of monitors - * @return viewport representing the union of given monitor's viewport in pixel units, i.e. result storage for chaining */ - public static Rectangle unionOfViewports(final Rectangle result, final List<MonitorDevice> monitors) { - int x1=Integer.MAX_VALUE, y1=Integer.MAX_VALUE; - int x2=Integer.MIN_VALUE, y2=Integer.MIN_VALUE; + public static void unionOfViewports(final Rectangle viewport, final Rectangle viewportInWindowUnits, final List<MonitorDevice> monitors) { + int x1PU=Integer.MAX_VALUE, y1PU=Integer.MAX_VALUE; + int x2PU=Integer.MIN_VALUE, y2PU=Integer.MIN_VALUE; + int x1WU=Integer.MAX_VALUE, y1WU=Integer.MAX_VALUE; + int x2WU=Integer.MIN_VALUE, y2WU=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()); + if( null != viewport ) { + final RectangleImmutable viewPU = monitors.get(i).getViewport(); + x1PU = Math.min(x1PU, viewPU.getX()); + x2PU = Math.max(x2PU, viewPU.getX() + viewPU.getWidth()); + y1PU = Math.min(y1PU, viewPU.getY()); + y2PU = Math.max(y2PU, viewPU.getY() + viewPU.getHeight()); + } + if( null != viewportInWindowUnits ) { + final RectangleImmutable viewWU = monitors.get(i).getViewportInWindowUnits(); + x1WU = Math.min(x1WU, viewWU.getX()); + x2WU = Math.max(x2WU, viewWU.getX() + viewWU.getWidth()); + y1WU = Math.min(y1WU, viewWU.getY()); + y2WU = Math.max(y2WU, viewWU.getY() + viewWU.getHeight()); + } + } + if( null != viewport ) { + viewport.set(x1PU, y1PU, x2PU - x1PU, y2PU - y1PU); + } + if( null != viewportInWindowUnits ) { + viewportInWindowUnits.set(x1WU, y1WU, x2WU - x1WU, y2WU - y1WU); } - result.set(x1, y1, x2 - x1, y2 - y1); - return result; } public final boolean isOriginalMode() { @@ -247,6 +262,7 @@ public abstract class MonitorDevice { * <p> * The returned {@link MonitorMode} is element of the lists {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}. * </p> + * @see #queryCurrentMode() */ public final MonitorMode getCurrentMode() { return currentMode; @@ -257,6 +273,7 @@ public abstract class MonitorDevice { * <p> * The returned {@link MonitorMode} is element of the lists {@link #getSupportedModes()} and {@link Screen#getMonitorModes()}. * </p> + * @see #getCurrentMode() */ public abstract MonitorMode queryCurrentMode(); @@ -269,7 +286,7 @@ public abstract class MonitorDevice { @Override public String toString() { - return "Monitor[Id "+Display.toHexString(nativeId)+", "+sizeMM+" mm, viewport "+viewport+ ", orig "+originalMode+", curr "+currentMode+ + return "Monitor[Id "+Display.toHexString(nativeId)+", "+sizeMM+" mm, viewport "+viewportPU+ " [pixels], "+viewportWU+" [window], orig "+originalMode+", curr "+currentMode+ ", modeChanged "+modeChanged+", modeCount "+supportedModes.size()+"]"; } } diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java index 919b98b45..cef254634 100644 --- a/src/newt/classes/com/jogamp/newt/Screen.java +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -28,12 +28,14 @@ package com.jogamp.newt; import com.jogamp.newt.event.MonitorModeListener; + import jogamp.newt.Debug; import java.lang.ref.WeakReference; 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; @@ -41,7 +43,18 @@ import javax.media.nativewindow.util.RectangleImmutable; /** * A screen may span multiple {@link MonitorDevice}s representing their combined virtual size. - */ + * <p> + * All values of this interface are represented in pixel units, if not stated otherwise. + * </p> + * + * <a name="coordinateSystem"><h5>Coordinate System</h5></a> + * <p> + * <ul> + * <li>Screen space has it's origin in the top-left corner, and may not be at 0/0.</li> + * <li>{@link #getViewport() Virtual viewport} covers all {@link MonitorDevice}s {@link MonitorDevice#getViewport() viewports} and has it's origin in the top-left corner, and may not be at 0/0.</li> + * </ul> + * </p> +*/ public abstract class Screen { /** @@ -131,11 +144,15 @@ public abstract class Screen { public abstract int getIndex(); /** + * See <a href="#coordinateSystem"> Coordinate System</a>. + * * @return the x position of the virtual viewport's top-left origin in pixel units. */ public abstract int getX(); /** + * See <a href="#coordinateSystem"> Coordinate System</a>. + * * @return the y position of the virtual viewport's top-left origin in pixel units. */ public abstract int getY(); @@ -151,20 +168,20 @@ public abstract class Screen { public abstract int getHeight(); /** - * @return the <b>rotated</b> virtual viewport, i.e. origin and size in pixel units. - * @see #getViewportInWindowUnits(Window) + * See <a href="#coordinateSystem"> Coordinate System</a>. + * + * @return the <b>rotated</b> virtual viewport, i.e. top-left origin and size, in pixel units. + * @see #getViewportInWindowUnits() */ public abstract RectangleImmutable getViewport(); /** - * Returns a newly created {@link Rectangle} containing the <b>rotated</b> virtual viewport - * in window units of the given {@link Window} instance. - * @return rotated viewport values, i.e. origin and size, in pixel units. + * See <a href="#coordinateSystem"> Coordinate System</a>. + * + * @return the <b>rotated</b> virtual viewport, i.e. top-left origin and size, in window units. * @see #getViewport() */ - public final Rectangle getViewportInWindowUnits(final Window win) { - return win.convertToWindowUnits( (Rectangle) getViewport().cloneMutable() ); - } + public abstract RectangleImmutable getViewportInWindowUnits(); /** * @return the associated Display @@ -192,12 +209,12 @@ public abstract class Screen { public abstract List<MonitorDevice> getMonitorDevices(); /** - * Returns the {@link MonitorDevice} with the highest {@link MonitorDevice#getViewport() viewport} - * {@link MonitorDevice#coverage(RectangleImmutable) coverage} of the given rectangle in pixel units. + * Returns the {@link MonitorDevice} with the highest {@link MonitorDevice#getViewportInWindowUnits() viewport} + * {@link RectangleImmutable#coverage(RectangleImmutable) coverage} of the given rectangle in window units. * <p> * If no coverage is detected the first {@link MonitorDevice} is returned. * </p> - * @param r arbitrary rectangle in pixel units + * @param r arbitrary rectangle in window units */ public final MonitorDevice getMainMonitor(final RectangleImmutable r) { MonitorDevice res = null; @@ -205,7 +222,7 @@ public abstract class Screen { final List<MonitorDevice> monitors = getMonitorDevices(); for(int i=monitors.size()-1; i>=0; i--) { final MonitorDevice monitor = monitors.get(i); - final float coverage = monitor.coverage(r); + final float coverage = monitor.getViewportInWindowUnits().coverage(r); if( coverage > maxCoverage ) { maxCoverage = coverage; res = monitor; @@ -218,15 +235,16 @@ public abstract class Screen { } /** - * Returns the union of all monitor's {@link MonitorDevice#getViewport() viewport} in pixel units. + * Calculates the union of all monitor's {@link MonitorDevice#getViewport() viewport} in pixel- and window units. * <p> * Should be equal to {@link #getX()}, {@link #getY()}, {@link #getWidth()} and {@link #getHeight()}, * however, some native toolkits may choose a different virtual screen area. * </p> - * @param result storage for result, will be returned + * @param viewport storage for result in pixel units, maybe null + * @param viewportInWindowUnits storage for result in window units, maybe null */ - public final Rectangle unionOfMonitorViewportSize(final Rectangle result) { - return MonitorDevice.unionOfViewports(result, getMonitorDevices()); + public final void unionOfMonitorViewports(final Rectangle viewport, final Rectangle viewportInWindowUnits) { + MonitorDevice.unionOfViewports(viewport, viewportInWindowUnits, getMonitorDevices()); } /** diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 872d67087..57fcb626d 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -46,7 +46,6 @@ 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.Point; import javax.media.nativewindow.util.Rectangle; import javax.media.nativewindow.util.RectangleImmutable; @@ -65,6 +64,20 @@ import javax.media.nativewindow.util.RectangleImmutable; * window operation to an instance of this interface while providing OpenGL * functionality. * </p> + * <p> + * All values of this interface are represented in window units, if not stated otherwise. + * </p> + * + * <a name="coordinateSystem"><h5>Coordinate System</h5></a> + * <p> + * <ul> + * <li>Screen space has it's origin in the top-left corner, and may not be at 0/0.</li> + * <li>Window origin is in it's top-left corner, see {@link #getX()} and {@link #getY()}. </li> + * <li>Window client-area excludes {@link #getInsets() insets}, i.e. window decoration.</li> + * <li>Window origin is relative to it's parent window if exist, or the screen position (top-level).</li> + * </ul> + * See {@link NativeWindow} and {@link Screen}. + * </p> * <a name="customwindowicons"><h5>Custom Window Icons</h5></a> * <p> * Custom window icons can be defined via system property <code>newt.window.icons</code>, @@ -108,8 +121,8 @@ public interface Window extends NativeWindow, WindowClosingProtocol { Screen getScreen(); /** - * Returns the {@link MonitorDevice} which {@link MonitorDevice#getViewport() viewport} - * {@link MonitorDevice#coverage(RectangleImmutable) covers} this window the most. + * Returns the {@link MonitorDevice} with the highest {@link MonitorDevice#getViewportInWindowUnits() viewport} + * {@link RectangleImmutable#coverage(RectangleImmutable) coverage} of this window. * <p> * If no coverage is detected the first {@link MonitorDevice} is returned. * </p> @@ -242,6 +255,10 @@ public interface Window extends NativeWindow, WindowClosingProtocol { /** * Returns a newly created {@link Rectangle} containing the scaled window origin, {@link #getX()} & {@link #getY()}, * and size, {@link #getSurfaceWidth()} & {@link #getSurfaceHeight()}, in pixel units. + * + * @deprecated The returned position in pixel units might be erroneous in case of multiple monitor setup where a mixed pixel-scale exist, + * since this method currently does not take the monitor viewport and each of it's pixel-scale into account (expensive). + * Either we fix this issue or remove this method at a later time. */ Rectangle getSurfaceBounds(); diff --git a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java index 9e10879c4..e9e41a0ef 100644 --- a/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java +++ b/src/newt/classes/jogamp/newt/MonitorDeviceImpl.java @@ -38,8 +38,8 @@ import com.jogamp.newt.Screen; public class MonitorDeviceImpl extends MonitorDevice { - public MonitorDeviceImpl(ScreenImpl screen, int nativeId, DimensionImmutable sizeMM, Rectangle viewport, MonitorMode currentMode, ArrayHashSet<MonitorMode> supportedModes) { - super(screen, nativeId, sizeMM, viewport, currentMode, supportedModes); + public MonitorDeviceImpl(ScreenImpl screen, int nativeId, DimensionImmutable sizeMM, Rectangle viewportPU, Rectangle viewportWU, MonitorMode currentMode, ArrayHashSet<MonitorMode> supportedModes) { + super(screen, nativeId, sizeMM, viewportPU, viewportWU, currentMode, supportedModes); } @Override @@ -136,11 +136,10 @@ public class MonitorDeviceImpl extends MonitorDevice { this.currentMode = currentMode; } - /* pp */ final void setViewportValue(Rectangle viewport) { - this.viewport = viewport; - } + /* pp */ final Rectangle getMutuableViewportPU() { return viewportPU; } + /* pp */ final Rectangle getMutuableViewportWU() { return viewportWU; } - /* pp */ ArrayHashSet<MonitorMode> getSupportedModesImpl() { + /* pp */ final ArrayHashSet<MonitorMode> getSupportedModesImpl() { return supportedModes; } diff --git a/src/newt/classes/jogamp/newt/MonitorModeProps.java b/src/newt/classes/jogamp/newt/MonitorModeProps.java index 9d8f4919c..55cbf77f3 100644 --- a/src/newt/classes/jogamp/newt/MonitorModeProps.java +++ b/src/newt/classes/jogamp/newt/MonitorModeProps.java @@ -81,9 +81,10 @@ public class MonitorModeProps { ; /** WARNING: must be synchronized with ScreenMode.h, native implementation - * 10: count + id, ScreenSizeMM[width, height], rotated Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+ + * 15: count + id, ScreenSizeMM[width, height], rotated Viewport pixel-units, rotated viewport window-units, currentMonitorModeId, rotation, supportedModeId+ + * Viewport := [x, y, width, height] (4 elements) */ - public static final int MIN_MONITOR_DEVICE_PROPERTIES = 11; + public static final int MIN_MONITOR_DEVICE_PROPERTIES = 15; public static final int IDX_MONITOR_DEVICE_VIEWPORT = 1 // count + 1 // native mode @@ -223,7 +224,8 @@ public class MonitorModeProps { final List<MonitorMode> 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 Rectangle viewportPU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); + final Rectangle viewportWU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); final MonitorMode currentMode; { final int modeId = monitorProperties[offset++]; @@ -240,7 +242,7 @@ public class MonitorModeProps { } } } - MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, sizeMM, viewport, currentMode, supportedModes); + MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, sizeMM, viewportPU, viewportWU, currentMode, supportedModes); if(null!=cache) { monitorDevice = cache.monitorDevices.getOrAdd(monitorDevice); } @@ -296,8 +298,9 @@ public class MonitorModeProps { 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); + final Rectangle viewportPU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); + final Rectangle viewportWU = new Rectangle(monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++], monitorProperties[offset++]); + MonitorDevice monitorDevice = new MonitorDeviceImpl(screen, id, sizeMM, viewportPU, viewportWU, currentMode, supportedModes); if(null!=cache) { monitorDevice = cache.monitorDevices.getOrAdd(monitorDevice); } @@ -328,6 +331,10 @@ public class MonitorModeProps { data[idx++] = monitorDevice.getViewport().getY(); data[idx++] = monitorDevice.getViewport().getWidth(); data[idx++] = monitorDevice.getViewport().getHeight(); + data[idx++] = monitorDevice.getViewportInWindowUnits().getX(); + data[idx++] = monitorDevice.getViewportInWindowUnits().getY(); + data[idx++] = monitorDevice.getViewportInWindowUnits().getWidth(); + data[idx++] = monitorDevice.getViewportInWindowUnits().getHeight(); data[idx++] = monitorDevice.getCurrentMode().getId(); data[idx++] = monitorDevice.getCurrentMode().getRotation(); final List<MonitorMode> supportedModes = monitorDevice.getSupportedModes(); diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index d7e6c641c..949e7fa3b 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -81,10 +81,11 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { protected int hashCode; protected AbstractGraphicsScreen aScreen; protected int refCount; // number of Screen references by Window - protected Rectangle vOriginSize = new Rectangle(0, 0, 0, 0); // virtual rotated screen origin and size + protected Rectangle virtViewportPU = new Rectangle(0, 0, 0, 0); // virtual rotated viewport in pixel units + protected Rectangle virtViewportWU = new Rectangle(0, 0, 0, 0); // virtual rotated viewport in window units protected static Dimension usrSize = null; // property values: newt.ws.swidth and newt.ws.sheight protected static volatile boolean usrSizeQueried = false; - private ArrayList<MonitorModeListener> refMonitorModeListener = new ArrayList<MonitorModeListener>(); + private final ArrayList<MonitorModeListener> refMonitorModeListener = new ArrayList<MonitorModeListener>(); private long tCreated; // creationTime @@ -130,6 +131,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { screen.screen_idx = idx; screen.fqname = display.getFQName()+"-s"+idx; screen.hashCode = screen.fqname.hashCode(); + screen.instantiationFinished(); Screen.addScreen2List(screen); if(DEBUG) { System.err.println("Screen.create() NEW: "+screen+" "+Display.getThreadName()); @@ -141,6 +143,14 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { } } + /** + * Notifies the driver impl. that the instantiation is finished, + * ie. instance created and all fields set. + */ + protected void instantiationFinished() { + // nop + } + @Override public boolean equals(Object obj) { if (obj == null) { @@ -260,19 +270,20 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { protected abstract int validateScreenIndex(int idx); /** - * Stores the virtual origin and virtual <b>rotated</b> screen size. + * Calculates the virtual rotated viewport in pixel- and window units. * <p> * This method is called after the MonitorMode has been set or changed, * hence you may utilize it. * </p> * <p> * Default implementation uses the union of all monitor's viewport, - * calculated via {@link #unionOfMonitorViewportSize()}. + * calculated via {@link #unionOfMonitorViewportSize()}, however driver impl. may chose a different methodology. * </p> - * @param vOriginSize storage for result + * @param viewport storage for result in pixel units + * @param viewportInWindowUnits storage for result in window units */ - protected void calcVirtualScreenOriginAndSize(final Rectangle vOriginSize) { - unionOfMonitorViewportSize(vOriginSize); + protected void calcVirtualScreenOriginAndSize(final Rectangle viewport, final Rectangle viewportInWindowUnits) { + unionOfMonitorViewports(viewport, viewportInWindowUnits); } @Override @@ -281,18 +292,19 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { } /** - * Updates the <b>rotated</b> virtual ScreenSize using the native impl. + * Updates the <b>rotated</b> virtual viewport, may use native impl. */ protected void updateVirtualScreenOriginAndSize() { if(null != usrSize ) { - vOriginSize.set(0, 0, usrSize.getWidth(), usrSize.getHeight()); + virtViewportPU.set(0, 0, usrSize.getWidth(), usrSize.getHeight()); + virtViewportWU.set(0, 0, usrSize.getWidth(), usrSize.getHeight()); if(DEBUG) { - System.err.println("Update user virtual screen viewport @ "+Thread.currentThread().getName()+": "+vOriginSize); + System.err.println("Update user virtual screen viewport @ "+Thread.currentThread().getName()+": "+virtViewportPU); } } else { - calcVirtualScreenOriginAndSize(vOriginSize); + calcVirtualScreenOriginAndSize(virtViewportPU, virtViewportWU); if(DEBUG) { - System.err.println("Updated virtual screen viewport @ "+Thread.currentThread().getName()+": "+vOriginSize); + System.err.println("Updated virtual screen viewport @ "+Thread.currentThread().getName()+": "+virtViewportPU+" [pixel], "+virtViewportWU+" [window]"); } } } @@ -318,19 +330,21 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { } @Override - public final int getX() { return vOriginSize.getX(); } + public final int getX() { return virtViewportPU.getX(); } @Override - public final int getY() { return vOriginSize.getY(); } + public final int getY() { return virtViewportPU.getY(); } @Override - public final int getWidth() { return vOriginSize.getWidth(); } + public final int getWidth() { return virtViewportPU.getWidth(); } @Override - public final int getHeight() { return vOriginSize.getHeight(); } + public final int getHeight() { return virtViewportPU.getHeight(); } @Override - public final RectangleImmutable getViewport() { return vOriginSize; } + public final RectangleImmutable getViewport() { return virtViewportPU; } + @Override + public final RectangleImmutable getViewportInWindowUnits() { return virtViewportWU; } @Override public String toString() { - return "NEWT-Screen["+getFQName()+", idx "+screen_idx+", refCount "+refCount+", vsize "+vOriginSize+", "+aScreen+", "+display+ + return "NEWT-Screen["+getFQName()+", idx "+screen_idx+", refCount "+refCount+", vsize "+virtViewportPU+" [pixels], "+virtViewportWU+" [window], "+aScreen+", "+display+ ", monitors: "+getMonitorDevices()+"]"; } @@ -357,7 +371,10 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { */ protected abstract void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache); - protected Rectangle getNativeMonitorDeviceViewportImpl(MonitorDevice monitor) { return null; } + protected boolean updateNativeMonitorDeviceViewportImpl(final MonitorDevice monitor, + final Rectangle viewportPU, final Rectangle viewportWU) { + return false; + } /** * To be implemented by the native specification.<br> @@ -402,7 +419,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { System.err.println("monitorModeChangeNotify @ "+Thread.currentThread().getName()+": "+me); } for(int i=0; i<refMonitorModeListener.size(); i++) { - ((MonitorModeListener)refMonitorModeListener.get(i)).monitorModeChangeNotify(me); + refMonitorModeListener.get(i).monitorModeChangeNotify(me); } } @@ -410,12 +427,9 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { final List<MonitorDevice> monitors = getMonitorDevices(); for(int i=monitors.size()-1; i>=0; i--) { final MonitorDeviceImpl monitor = (MonitorDeviceImpl) monitors.get(i); - final Rectangle newViewport = getNativeMonitorDeviceViewportImpl(monitor); + final boolean viewportUpdated = updateNativeMonitorDeviceViewportImpl(monitor, monitor.getMutuableViewportPU(), monitor.getMutuableViewportWU()); if( DEBUG ) { - System.err.println("Screen.updateMonitorViewport["+i+"] @ "+Thread.currentThread().getName()+": "+monitor.getViewport()+" -> "+newViewport); - } - if( null != newViewport ) { - monitor.setViewportValue(newViewport); + System.err.println("Screen.updateMonitorViewport["+i+"] @ "+Thread.currentThread().getName()+": updated: "+viewportUpdated+", PU "+monitor.getViewport()+", WU "+monitor.getViewportInWindowUnits()); } } } @@ -430,7 +444,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { System.err.println("monitorModeChangeNotify @ "+Thread.currentThread().getName()+": success "+success+", "+me); } for(int i=0; i<refMonitorModeListener.size(); i++) { - ((MonitorModeListener)refMonitorModeListener.get(i)).monitorModeChanged(me, success); + refMonitorModeListener.get(i).monitorModeChanged(me, success); } } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 6a5fc5de0..08559c14d 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -910,9 +910,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return screen; } + protected void setScreen(ScreenImpl newScreen) { // never null ! + removeScreenReference(); + screen = newScreen; + } + @Override public final MonitorDevice getMainMonitor() { - return screen.getMainMonitor( getSurfaceBounds() ); + return screen.getMainMonitor( getBounds() ); } /** @@ -1072,7 +1077,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer @Override public final void setSurfaceSize(final int pixelWidth, final int pixelHeight) { // FIXME HiDPI: Shortcut, may need to adjust if we change scaling methodology - setSize(pixelWidth * getPixelScaleX(), pixelHeight * getPixelScaleY()); + setSize(pixelWidth / getPixelScaleX(), pixelHeight / getPixelScaleY()); } @Override public final void setTopLevelSize(final int width, final int height) { @@ -1232,11 +1237,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return operation; } - private void setScreen(ScreenImpl newScreen) { // never null ! - removeScreenReference(); - screen = newScreen; - } - @Override public final void run() { if( WindowImpl.this.isFullscreen() ) { @@ -2249,8 +2249,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer int x,y,w,h; - final RectangleImmutable sviewport = screen.getViewportInWindowUnits(WindowImpl.this); - final RectangleImmutable viewport; + final RectangleImmutable sviewport = screen.getViewportInWindowUnits(); // window units + final RectangleImmutable viewport; // window units final int fs_span_flag; final boolean alwaysOnTopChange; if(_fullscreen) { @@ -2262,7 +2262,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer fullscreenMonitors = getScreen().getMonitorDevices(); } } - viewport = convertToWindowUnits(MonitorDevice.unionOfViewports(new Rectangle(), fullscreenMonitors)); + { + final Rectangle viewportInWindowUnits = new Rectangle(); + MonitorDevice.unionOfViewports(null, viewportInWindowUnits, fullscreenMonitors); + viewport = viewportInWindowUnits; + } if( isReconfigureFlagSupported(FLAG_IS_FULLSCREEN_SPAN) && ( fullscreenMonitors.size() > 1 || sviewport.compareTo(viewport) > 0 ) ) { fs_span_flag = FLAG_IS_FULLSCREEN_SPAN; @@ -2620,7 +2624,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // Native MouseEvents pre-processed to be enqueued or consumed directly // - public void sendMouseEvent(final short eventType, final int modifiers, + public final void sendMouseEvent(final short eventType, final int modifiers, final int x, final int y, final short button, final float rotation) { doMouseEvent(false, false, eventType, modifiers, x, y, button, MouseEvent.getRotationXYZ(rotation, modifiers), 1f); } diff --git a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java index 7a571318b..5671a05e4 100644 --- a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java @@ -286,8 +286,7 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { if( isFullscreen() ) { final MonitorDevice mainMonitor = getMainMonitor(); - final RectangleImmutable screenRect = mainMonitor.getViewport(); - final RectangleImmutable winRect = this.convertToWindowUnits((Rectangle)screenRect.cloneMutable()); + final RectangleImmutable winRect = mainMonitor.getViewportInWindowUnits(); definePosition(winRect.getX(), winRect.getY()); defineSize(winRect.getWidth(), winRect.getHeight()); } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java index f7722c91c..5dab64e39 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java @@ -65,7 +65,7 @@ public class AWTCanvas extends Canvas { private AWTGraphicsConfiguration awtConfig; private volatile JAWTWindow jawtWindow=null; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle private CapabilitiesChooser chooser=null; - private CapabilitiesImmutable capabilities; + private final CapabilitiesImmutable capabilities; private boolean displayConfigChanged=false; @@ -152,6 +152,10 @@ public class AWTCanvas extends Canvas { } } + public int getPixelScale() { + final JAWTWindow _jawtWindow = jawtWindow; + return (null != _jawtWindow) ? _jawtWindow.getPixelScale() : 1; + } public NativeWindow getNativeWindow() { final JAWTWindow _jawtWindow = jawtWindow; return (null != _jawtWindow) ? _jawtWindow : null; diff --git a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java index f99476851..1f0ba6f09 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/awt/WindowDriver.java @@ -99,6 +99,17 @@ public class WindowDriver extends WindowImpl { } @Override + protected final int getPixelScaleX() { + final AWTCanvas _awtCanvas = awtCanvas; + return null != _awtCanvas ? _awtCanvas.getPixelScale() : 1; + } + + @Override + protected final int getPixelScaleY() { + return getPixelScaleX(); + } + + @Override protected void createNativeImpl() { if(0!=getParentWindowHandle()) { throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); 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 d3231557f..64bc87a41 100644 --- a/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/egl/ScreenDriver.java @@ -104,8 +104,8 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { } @Override - protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) { - vOriginSize.set(0, 0, fixedWidth, fixedHeight); // FIXME + protected void calcVirtualScreenOriginAndSize(Rectangle viewport, Rectangle viewportInWindowUnits) { + viewport.set(0, 0, fixedWidth, 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 dc2a8459a..e0228c10f 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 @@ -97,8 +97,8 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) { - vOriginSize.set(0, 0, cachedWidth, cachedHeight); + protected void calcVirtualScreenOriginAndSize(Rectangle viewport, Rectangle viewportInWindowUnits) { + viewport.set(0, 0, cachedWidth, cachedHeight); } /** Called from {@link #initNative()}. */ 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 index 1c927acc4..188e5b964 100644 --- a/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/bcm/vc/iv/WindowDriver.java @@ -170,13 +170,13 @@ public class WindowDriver extends WindowImpl { } @Override - public final void sendMouseEvent(final short eventType, final int modifiers, - final int x, final int y, final short button, final float rotation) { + protected final void doMouseEvent(final boolean enqueue, final boolean wait, final short eventType, final int modifiers, + final int x, final int y, final short button, final float[] rotationXYZ, final float rotationScale) { if( MouseEvent.EVENT_MOUSE_MOVED == eventType ) { final DisplayDriver display = (DisplayDriver) getScreen().getDisplay(); display.moveActivePointerIcon(x, y); } - super.sendMouseEvent(eventType, modifiers, x, y, button, rotation); + super.doMouseEvent(enqueue, wait, eventType, modifiers, x, y, button, rotationXYZ, rotationScale); } @Override 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 44802e348..20c60565a 100644 --- a/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/ScreenDriver.java @@ -106,8 +106,8 @@ public class ScreenDriver extends jogamp.newt.ScreenImpl { } @Override - protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) { - vOriginSize.set(0, 0, cachedWidth, cachedHeight); + protected void calcVirtualScreenOriginAndSize(Rectangle viewport, Rectangle viewportInWindowUnits) { + viewport.set(0, 0, cachedWidth, cachedHeight); } //---------------------------------------------------------------------- diff --git a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java index 9ebe2629a..541576250 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/kd/ScreenDriver.java @@ -102,8 +102,8 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) { - vOriginSize.set(0, 0, cachedWidth, cachedHeight); + protected void calcVirtualScreenOriginAndSize(Rectangle viewport, Rectangle viewportInWindowUnits) { + viewport.set(0, 0, cachedWidth, 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 4f3cc691b..5f458e2c9 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/ScreenDriver.java @@ -35,13 +35,16 @@ package jogamp.newt.driver.macosx; import javax.media.nativewindow.DefaultGraphicsScreen; +import javax.media.nativewindow.util.Rectangle; +import jogamp.nativewindow.macosx.OSXUtil; import jogamp.newt.MonitorModeProps; import jogamp.newt.ScreenImpl; import com.jogamp.common.util.ArrayHashSet; import com.jogamp.newt.MonitorDevice; import com.jogamp.newt.MonitorMode; +import com.jogamp.opengl.math.FloatUtil; public class ScreenDriver extends ScreenImpl { @@ -60,7 +63,7 @@ public class ScreenDriver extends ScreenImpl { @Override protected void closeNativeImpl() { } - private MonitorMode getMonitorModeImpl(MonitorModeProps.Cache cache, int crt_idx, int mode_idx) { + private MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final int crt_idx, final int mode_idx) { final int[] modeProps = getMonitorMode0(crt_idx, mode_idx); final MonitorMode res; if (null == modeProps || 0 >= modeProps.length) { @@ -71,56 +74,133 @@ public class ScreenDriver extends ScreenImpl { return res; } - @Override - protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) { - int crtIdx = 0; - int modeIdx = 0; - ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>(); - 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"); + private class CrtProps { + CrtProps() { + count = getMonitorCount0(); + pixelScaleArray = new int[count]; + propsOrigArray = new int[count][]; + propsFixedArray = new int[count][]; + + // + // Gather whole topology of monitors (NSScreens) + // + for(int crtIdx=0; crtIdx<count; crtIdx++) { + final float pixelScaleRaw = (float) OSXUtil.GetPixelScale(crtIdx); + pixelScaleArray[crtIdx] = FloatUtil.isZero(pixelScaleRaw, FloatUtil.EPSILON) ? 1 : (int)pixelScaleRaw; + propsOrigArray[crtIdx] = getMonitorProps0(crtIdx); + if ( null == propsOrigArray[crtIdx] ) { + throw new InternalError("Could not gather device props "+crtIdx+"/"+count); } - final int[] monitorProps = getMonitorProps0(crtIdx); - if ( null == monitorProps ) { - throw new InternalError("Could not gather device "+crtIdx+", but gathered "+modeIdx+" modes"); + // copy orig -> fixed + final int propsLen = propsOrigArray[crtIdx].length; + propsFixedArray[crtIdx] = new int[propsLen]; + System.arraycopy(propsOrigArray[crtIdx], 0, propsFixedArray[crtIdx], 0, propsLen); + } + + // + // Fix scaled viewport w/ pixelScale of each monitorProps, + // i.e. size by its own pixelScale and x/y offset by querying it's neighbors. + // + for(int crtIdx=0; crtIdx<count; crtIdx++) { + final int[] thisMonitorProps = propsFixedArray[crtIdx]; + final int x = thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+0]; + final int y = thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+1]; + final int thisPixelScale = pixelScaleArray[crtIdx]; + thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+2] *= thisPixelScale; // fix width + thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+3] *= thisPixelScale; // fix height + if( 0 != x ) { + // find matching viewport width for x-offset to apply it's pixelSize + for(int i=0; i<count; i++) { + if( i != crtIdx && x == propsOrigArray[i][MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+2] ) { + thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+0] *= pixelScaleArray[i]; + break; + } + } + } + if( 0 != y ) { + // find matching viewport height for y-offset to apply it's pixelSize + for(int i=0; i<count; i++) { + if( i != crtIdx && y == propsOrigArray[i][MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+3] ) { + thisMonitorProps[MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT+1] *= pixelScaleArray[i]; + break; + } + } } - // merge monitor-props + supported modes - MonitorModeProps.streamInMonitorDevice(null, cache, this, supportedModes, currentMode, monitorProps, 0); - - // next monitor, 1st mode - supportedModes= new ArrayHashSet<MonitorMode>(); - crtIdx++; - modeIdx=0; - } else { - // end of monitor - break; } - } while ( true ); + } + final int count; + final int[] pixelScaleArray; + final int[][] propsOrigArray; + final int[][] propsFixedArray; + } + + @Override + protected final void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) { + final CrtProps crtProps = new CrtProps(); + + // + // Collect all monitorModes for all monitorDevices + // + for(int crtIdx=0; crtIdx<crtProps.count; crtIdx++) { + final ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>(); + int modeIdx = 0; + { + // Get all supported modes for this monitorDevice + MonitorMode mode; + while( true ) { + mode = getMonitorModeImpl(cache, crtIdx, modeIdx); + if( null != mode ) { + if( mode.getSurfaceSize().getBitsPerPixel() >= 24 ) { // drop otherwise + supportedModes.getOrAdd(mode); + } + modeIdx++; // next mode on same monitor + } else { + break; // done with modes on this monitor + } + } + } + if( 0 >= modeIdx ) { + throw new InternalError("Could not gather single mode of device "+crtIdx+"/"+crtProps.count); + } + final MonitorMode currentMode = getMonitorModeImpl(cache, crtIdx, -1); + if ( null == currentMode ) { + throw new InternalError("Could not gather current mode of device "+crtIdx+"/"+crtProps.count+", but gathered "+modeIdx+" modes"); + } + // merge monitor-props + supported modes + MonitorModeProps.streamInMonitorDevice(null, cache, this, supportedModes, currentMode, crtProps.propsFixedArray[crtIdx], 0); + } + } + + @Override + protected boolean updateNativeMonitorDeviceViewportImpl(final MonitorDevice monitor, final Rectangle viewportPU, final Rectangle viewportWU) { + final CrtProps crtProps = new CrtProps(); + final int crtIdx = monitor.getId(); + if( 0 > crtIdx || crtIdx >= crtProps.count ) { + throw new IndexOutOfBoundsException("monitor id "+crtIdx+" not withon [0.."+(crtProps.count-1)+"]"); + } + final int[] fixedMonitorProps = crtProps.propsFixedArray[crtIdx]; + int offset = MonitorModeProps.IDX_MONITOR_DEVICE_VIEWPORT; + viewportPU.set(fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++]); + viewportWU.set(fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++], fixedMonitorProps[offset++]); + return true; } @Override - protected MonitorMode queryCurrentMonitorModeImpl(MonitorDevice monitor) { + protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) { return getMonitorModeImpl(null, monitor.getId(), -1); } @Override - protected boolean setCurrentMonitorModeImpl(MonitorDevice monitor, MonitorMode mode) { + protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) { return setMonitorMode0(monitor.getId(), mode.getId(), mode.getRotation()); } @Override - protected int validateScreenIndex(int idx) { + protected int validateScreenIndex(final int idx) { return 0; // big-desktop w/ multiple monitor attached, only one screen available } + private native int getMonitorCount0(); 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 eebf280de..540186f2e 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -46,12 +46,15 @@ import javax.media.nativewindow.util.PointImmutable; import jogamp.nativewindow.macosx.OSXUtil; import jogamp.newt.PointerIconImpl; +import jogamp.newt.ScreenImpl; import jogamp.newt.WindowImpl; import jogamp.newt.driver.DriverClearFocus; import jogamp.newt.driver.DriverUpdatePosition; import com.jogamp.newt.event.InputEvent; import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.MonitorEvent; +import com.jogamp.opengl.math.FloatUtil; public class WindowDriver extends WindowImpl implements MutableSurface, DriverClearFocus, DriverUpdatePosition { @@ -59,7 +62,81 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl DisplayDriver.initSingleton(); } + private int pixelScale; + public WindowDriver() { + pixelScale = 1; + } + + private boolean updatePixelScale(final boolean sendEvent, final boolean defer, final float newPixelScaleRaw) { + final int newPixelScaleSafe = FloatUtil.isZero(newPixelScaleRaw, FloatUtil.EPSILON) ? 1 : (int) newPixelScaleRaw; + final boolean changed = pixelScale != newPixelScaleSafe; + if( DEBUG_IMPLEMENTATION ) { + System.err.println("WindowDriver.updatePixelScale.X: "+pixelScale+" -> "+newPixelScaleSafe+" (raw "+newPixelScaleRaw+") - changed "+changed); + } + if( changed ) { + pixelScale = newPixelScaleSafe; + if( sendEvent ) { + super.sizeChanged(defer, getWindowWidth(), getWindowHeight(), true); + } else { + defineSize(getWindowWidth(), getWindowHeight()); + } + } + return changed; + } + + private boolean updatePixelScaleByScreenIdx(final boolean sendEvent) { + final float newPixelScaleRaw = (float) OSXUtil.GetPixelScale(getScreen().getIndex()); + if( DEBUG_IMPLEMENTATION ) { + System.err.println("WindowDriver.updatePixelScale.1: "+pixelScale+" -> "+newPixelScaleRaw); + } + return updatePixelScale(sendEvent, true /* defer */, newPixelScaleRaw); + } + + private boolean updatePixelScaleByWindowHandle(final boolean sendEvent) { + final long wh = getWindowHandle(); + if( 0 != wh ) { + final float newPixelScaleRaw = (float)OSXUtil.GetPixelScale(wh); + if( DEBUG_IMPLEMENTATION ) { + System.err.println("WindowDriver.updatePixelScale.2: "+pixelScale+" -> "+newPixelScaleRaw); + } + return updatePixelScale(sendEvent, true /* defer */, newPixelScaleRaw); + } else { + return false; + } + } + + /** Called from native code */ + protected void updatePixelScale(final boolean defer, final float newPixelScaleRaw) { + final long handle = getWindowHandle(); + if( 0 != handle ) { + if( DEBUG_IMPLEMENTATION ) { + System.err.println("WindowDriver.updatePixelScale.3: "+pixelScale+" -> "+newPixelScaleRaw); + } + updatePixelScale(true /* sendEvent*/, defer, newPixelScaleRaw); + } + } + + @Override + protected final void instantiationFinished() { + updatePixelScaleByScreenIdx(false /* sendEvent*/); + } + + @Override + protected void setScreen(ScreenImpl newScreen) { // never null ! + super.setScreen(newScreen); + updatePixelScaleByScreenIdx(false /* sendEvent*/); // caller (reparent, ..) will send reshape event + } + + + @Override + protected final int getPixelScaleX() { + return pixelScale; + } + + @Override + protected final int getPixelScaleY() { + return pixelScale; } @Override @@ -210,16 +287,6 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl private boolean useParent(NativeWindow parent) { return null != parent && 0 != parent.getWindowHandle(); } @Override - protected final int getPixelScaleX() { - return 1; // FIXME HiDPI: Use pixelScale - } - - @Override - protected final int getPixelScaleY() { - return 1; // FIXME HiDPI: Use pixelScale - } - - @Override public void updatePosition(int x, int y) { final long handle = getWindowHandle(); if( 0 != handle && !isOffscreenInstance ) { @@ -263,11 +330,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl } @Override - protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, int flags) { + protected boolean reconfigureWindowImpl(int x, int y, final int width, final int height, int flags) { final boolean _isOffscreenInstance = isOffscreenInstance(this, this.getParent()); isOffscreenInstance = 0 != sscSurfaceHandle || _isOffscreenInstance; final PointImmutable pClientLevelOnSreen; if( isOffscreenInstance ) { + x = 0; y = 0; pClientLevelOnSreen = new Point(0, 0); } else { final NativeWindow parent = getParent(); @@ -313,9 +381,9 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl 0 != ( FLAG_CHANGE_PARENTING & flags) || 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) { if(isOffscreenInstance) { - createWindow(true, 0 != getWindowHandle(), pClientLevelOnSreen, 64, 64, false, setVisible, false); + createWindow(true, 0 != getWindowHandle(), pClientLevelOnSreen, x, y, 64, 64, false, setVisible, false); } else { - createWindow(false, 0 != getWindowHandle(), pClientLevelOnSreen, width, height, + createWindow(false, 0 != getWindowHandle(), pClientLevelOnSreen, x, y, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags), setVisible, 0 != ( FLAG_IS_ALWAYSONTOP & flags)); } } else { @@ -329,7 +397,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl } // else offscreen size is realized via recreation // no native event (fullscreen, some reparenting) positionChanged(true, x, y); - sizeChanged(true, width, height, false); + super.sizeChanged(true, width, height, false); } if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && setVisible ) { if( !isOffscreenInstance ) { @@ -439,11 +507,17 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl @Override protected void warpPointerImpl(final int x, final int y) { if( !isOffscreenInstance ) { - warpPointer0(getWindowHandle(), x, y); + warpPointer0(getWindowHandle(), x / getPixelScaleX(), y / getPixelScaleY()); } // else may need offscreen solution ? FIXME } @Override + protected final void doMouseEvent(final boolean enqueue, final boolean wait, final short eventType, final int modifiers, + final int x, final int y, final short button, final float[] rotationXYZ, final float rotationScale) { + super.doMouseEvent(enqueue, wait, eventType, modifiers, x * getPixelScaleX(), y * getPixelScaleY(), button, rotationXYZ, rotationScale); + } + + @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"); } @@ -499,8 +573,8 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl // private void createWindow(final boolean offscreenInstance, final boolean recreate, - final PointImmutable pS, final int width, final int height, - final boolean fullscreen, final boolean visible, final boolean alwaysOnTop) { + final PointImmutable pS, final int x, final int y, + final int width, final int height, final boolean fullscreen, final boolean visible, final boolean alwaysOnTop) { final long parentWinHandle = getParentWindowHandle(); final long preWinHandle = getWindowHandle(); @@ -558,8 +632,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl setTitle0(newWin, getTitle()); setAlwaysOnTop0(getWindowHandle(), alwaysOnTop); } - visibleChanged(true, visible); } } ); + // no native event (fullscreen, some reparenting) + positionChanged(false, x, y); + updatePixelScaleByWindowHandle(false /* sendEvent */); + super.sizeChanged(false, width, height, true); + visibleChanged(false, visible); } catch (Exception ie) { ie.printStackTrace(); } @@ -569,7 +647,8 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl 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 visible, long view); + private native void initWindow0(long parentWindow, long window, int x, int y, int w, int h, + boolean opaque, 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 e789b995f..af265cfd3 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/windows/ScreenDriver.java @@ -65,14 +65,14 @@ public class ScreenDriver extends ScreenImpl { protected void closeNativeImpl() { } - private final String getAdapterName(int crt_idx) { + private final String getAdapterName(final int crt_idx) { return getAdapterName0(crt_idx); } - private final String getActiveMonitorName(String adapterName, int monitor_idx) { + private final String getActiveMonitorName(final String adapterName, final int monitor_idx) { return getActiveMonitorName0(adapterName, monitor_idx); } - private final MonitorMode getMonitorModeImpl(MonitorModeProps.Cache cache, String adapterName, int crtModeIdx) { + private final MonitorMode getMonitorModeImpl(final MonitorModeProps.Cache cache, final String adapterName, final int crtModeIdx) { if( null == adapterName ) { return null; } @@ -85,7 +85,7 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) { + protected void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) { int crtIdx = 0; ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>(); String adapterName = getAdapterName(crtIdx); @@ -118,26 +118,28 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected Rectangle getNativeMonitorDeviceViewportImpl(MonitorDevice monitor) { + protected boolean updateNativeMonitorDeviceViewportImpl(final MonitorDevice monitor, final Rectangle viewportPU, final Rectangle viewportWU) { 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++]); + viewportPU.set(monitorProps[offset++], monitorProps[offset++], monitorProps[offset++], monitorProps[offset++]); + viewportWU.set(monitorProps[offset++], monitorProps[offset++], monitorProps[offset++], monitorProps[offset++]); + return true; } } - return null; + return false; } @Override - protected MonitorMode queryCurrentMonitorModeImpl(MonitorDevice monitor) { + protected MonitorMode queryCurrentMonitorModeImpl(final MonitorDevice monitor) { return getMonitorModeImpl(null, getAdapterName(monitor.getId()), -1); } @Override - protected boolean setCurrentMonitorModeImpl(MonitorDevice monitor, MonitorMode mode) { + protected boolean setCurrentMonitorModeImpl(final MonitorDevice monitor, final MonitorMode mode) { return setMonitorMode0(monitor.getId(), -1, -1, // no fixed position! mode.getSurfaceSize().getResolution().getWidth(), @@ -149,13 +151,13 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected int validateScreenIndex(int idx) { + protected int validateScreenIndex(final int idx) { return 0; // big-desktop w/ multiple monitor attached, only one screen available } @Override - protected void calcVirtualScreenOriginAndSize(Rectangle vOriginSize) { - vOriginSize.set(getVirtualOriginX0(), getVirtualOriginY0(), getVirtualWidthImpl0(), getVirtualHeightImpl0()); + protected void calcVirtualScreenOriginAndSize(final Rectangle viewport, Rectangle viewportInWindowUnits) { + viewport.set(getVirtualOriginX0(), getVirtualOriginY0(), getVirtualWidthImpl0(), getVirtualHeightImpl0()); } // Native calls diff --git a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java index bef7f60ec..2d7c6509d 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java @@ -111,7 +111,7 @@ public class ScreenDriver extends ScreenImpl { private RandR rAndR; @Override - protected final void collectNativeMonitorModesAndDevicesImpl(MonitorModeProps.Cache cache) { + protected final void collectNativeMonitorModesAndDevicesImpl(final MonitorModeProps.Cache cache) { if( null == rAndR ) { return; } final AbstractGraphicsDevice device = getDisplay().getGraphicsDevice(); device.lock(); @@ -165,12 +165,14 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected Rectangle getNativeMonitorDeviceViewportImpl(MonitorDevice monitor) { + protected boolean updateNativeMonitorDeviceViewportImpl(final MonitorDevice monitor, final Rectangle viewportPU, final Rectangle viewportWU) { final AbstractGraphicsDevice device = getDisplay().getGraphicsDevice(); device.lock(); try { int[] viewportProps = rAndR.getMonitorDeviceViewport(device.getHandle(), this, monitor.getId()); - return new Rectangle(viewportProps[0], viewportProps[1], viewportProps[2], viewportProps[3]); + viewportPU.set(viewportProps[0], viewportProps[1], viewportProps[2], viewportProps[3]); + viewportWU.set(viewportProps[0], viewportProps[1], viewportProps[2], viewportProps[3]); // equal window-units and pixel-units + return true; } finally { device.unlock(); } @@ -207,7 +209,7 @@ public class ScreenDriver extends ScreenImpl { return done; } - private DisplayImpl.DisplayRunnable<Boolean> xineramaEnabledQueryWithTemp = new DisplayImpl.DisplayRunnable<Boolean>() { + private final DisplayImpl.DisplayRunnable<Boolean> xineramaEnabledQueryWithTemp = new DisplayImpl.DisplayRunnable<Boolean>() { @Override public Boolean run(long dpy) { return new Boolean(X11Util.XineramaIsEnabled(dpy)); @@ -225,8 +227,8 @@ public class ScreenDriver extends ScreenImpl { } @Override - protected void calcVirtualScreenOriginAndSize(final Rectangle vOriginSize) { - final RectangleImmutable ov = (RectangleImmutable) getViewport().cloneMutable(); + protected void calcVirtualScreenOriginAndSize(final Rectangle viewport, Rectangle viewportInWindowUnits) { + final RectangleImmutable ov = DEBUG ? (RectangleImmutable) getViewport().cloneMutable() : null; /** if( null != rAndR && rAndR.getVersion().compareTo(RandR.version130) >= 0 && getMonitorDevices().size()>0 ) { super.calcVirtualScreenOriginAndSize(vOriginSize); @@ -242,11 +244,11 @@ public class ScreenDriver extends ScreenImpl { runWithLockedDisplayDevice( new DisplayImpl.DisplayRunnable<Object>() { @Override public Object run(long dpy) { - vOriginSize.set(0, 0, getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx)); + viewport.set(0, 0, getWidth0(dpy, screen_idx), getHeight0(dpy, screen_idx)); return null; } } ); if( DEBUG ) { - System.err.println("X11Screen.calcVirtualScreenOriginAndSize: Querying X11: "+ov+" -> "+vOriginSize); + System.err.println("X11Screen.calcVirtualScreenOriginAndSize: Querying X11: "+ov+" -> "+viewport); } } } @@ -254,11 +256,11 @@ public class ScreenDriver extends ScreenImpl { //---------------------------------------------------------------------- // Internals only // - private final <T> T runWithLockedDisplayDevice(DisplayRunnable<T> action) { + private final <T> T runWithLockedDisplayDevice(final DisplayRunnable<T> action) { return display.runWithLockedDisplayDevice(action); } - private final <T> T runWithTempDisplayHandle(DisplayRunnable<T> action) { + private final <T> T runWithTempDisplayHandle(final DisplayRunnable<T> action) { final long displayHandle = X11Util.openDisplay(display.getName()); if(0 == displayHandle) { throw new RuntimeException("null device"); @@ -272,7 +274,7 @@ public class ScreenDriver extends ScreenImpl { return res; } - private final <T> T runWithOptTempDisplayHandle(DisplayRunnable<T> action) { + private final <T> T runWithOptTempDisplayHandle(final DisplayRunnable<T> action) { if( null != rAndR && rAndR.getVersion().compareTo(RandR.version130) >= 0 ) { return display.runWithLockedDisplayDevice(action); } else { diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 25ea47c47..80e70216e 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -366,7 +366,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_DisplayDriver_destroyPoint [pool release]; } -static NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx, BOOL cap) { +NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx, BOOL cap) { NSArray *screens = [NSScreen screens]; if( screen_idx<0 || screen_idx>=[screens count] ) { if( cap ) { @@ -378,7 +378,7 @@ static NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx, BOOL cap) { return (NSScreen *) [screens objectAtIndex: screen_idx]; } -static NSScreen * NewtScreen_getNSScreenByCoord(int x, int y) { +NSScreen * NewtScreen_getNSScreenByCoord(int x, int y) { NSArray *screens = [NSScreen screens]; int i; for(i=[screens count]-1; i>=0; i--) { @@ -394,7 +394,32 @@ static NSScreen * NewtScreen_getNSScreenByCoord(int x, int y) { return (NSScreen *) [screens objectAtIndex: 0]; } -static CGDirectDisplayID NewtScreen_getCGDirectDisplayIDByNSScreen(NSScreen *screen) { +static void NewtScreen_dump() { +#ifdef VERBOSE_ON + NSArray *screens = [NSScreen screens]; + int i; + for(i=0; i<[screens count]; i++) { + NSScreen * screen = (NSScreen *) [screens objectAtIndex: i]; + NSRect screenFrame = [screen frame]; + NSRect screenVisibleFrame = [screen visibleFrame]; + CGFloat pixelScale = 1.0; // default +NS_DURING + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling +NS_HANDLER +NS_ENDHANDLER + NSWindowDepth depth = [screen depth]; // an (int) value! + DBG_PRINT( "NSScreen #%d (%p): Frame %lf/%lf %lfx%lf (vis %lf/%lf %lfx%lf), scale %lf, depth %d\n", + i, screen, + screenFrame.origin.x, screenFrame.origin.y, screenFrame.size.width, screenFrame.size.height, + screenVisibleFrame.origin.x, screenVisibleFrame.origin.y, screenVisibleFrame.size.width, screenVisibleFrame.size.height, + pixelScale, depth); + } +#endif +} + + +CGDirectDisplayID NewtScreen_getCGDirectDisplayIDByNSScreen(NSScreen *screen) { // Mind: typedef uint32_t CGDirectDisplayID; - however, we assume it's 64bit on 64bit ?! NSDictionary * dict = [screen deviceDescription]; NSNumber * val = (NSNumber *) [dict objectForKey: @"NSScreenNumber"]; @@ -428,6 +453,20 @@ static long GetDictionaryLong(CFDictionaryRef theDict, const void* key) /* * Class: jogamp_newt_driver_macosx_ScreenDriver + * Method: getMonitorCount0 + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonitorCount0 + (JNIEnv *env, jobject obj) +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NSArray *screens = [NSScreen screens]; + [pool release]; + return (jint) [screens count]; +} + +/* + * Class: jogamp_newt_driver_macosx_ScreenDriver * Method: getMonitorProps0 * Signature: (I)[I */ @@ -463,8 +502,16 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit fprintf(stderr, "MacScreen_getMonitorProps0.3: %ld ms\n", td_ms); fflush(NULL); #endif - CGRect bounds = CGDisplayBounds (display); - + CGRect dBounds = CGDisplayBounds (display); // origin top-left +#ifdef VERBOSE_ON + BOOL usesGL = CGDisplayUsesOpenGLAcceleration(display); + NSRect sFrame = [screen frame]; // origin bottom-left + DBG_PRINT( "getMonitorProps0: scrn %d, top-left displayBounds[%d/%d %dx%d], bottom-left screenFrame[%d/%d %dx%d], usesGL %d\n", (int)crt_idx, + (int)dBounds.origin.x, (int)dBounds.origin.y, (int)dBounds.size.width, (int)dBounds.size.height, + (int)sFrame.origin.x, (int)sFrame.origin.y, (int)sFrame.size.width, (int)sFrame.size.height, + (int)usesGL); +#endif + jsize propCount = MIN_MONITOR_DEVICE_PROPERTIES - 1 - NUM_MONITOR_MODE_PROPERTIES; jint prop[ propCount ]; int offset = 0; @@ -472,10 +519,14 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit prop[offset++] = crt_idx; prop[offset++] = (jint) sizeMM.width; prop[offset++] = (jint) sizeMM.height; - prop[offset++] = (jint) bounds.origin.x; // rotated viewport x - prop[offset++] = (jint) bounds.origin.y; // rotated viewport y - prop[offset++] = (jint) bounds.size.width; // rotated viewport width - prop[offset++] = (jint) bounds.size.height; // rotated viewport height + prop[offset++] = (jint) dBounds.origin.x; // rotated viewport x (pixel units, will be fixed in java code) + prop[offset++] = (jint) dBounds.origin.y; // rotated viewport y (pixel units, will be fixed in java code) + prop[offset++] = (jint) dBounds.size.width; // rotated viewport width (pixel units, will be fixed in java code) + prop[offset++] = (jint) dBounds.size.height; // rotated viewport height (pixel units, will be fixed in java code) + prop[offset++] = (jint) dBounds.origin.x; // rotated viewport x (window units, will be fixed in java code) + prop[offset++] = (jint) dBounds.origin.y; // rotated viewport y (window units, will be fixed in java code) + prop[offset++] = (jint) dBounds.size.width; // rotated viewport width (window units, will be fixed in java code) + prop[offset++] = (jint) dBounds.size.height; // rotated viewport height (window units, will be fixed in java code) jintArray properties = (*env)->NewIntArray(env, propCount); if (properties == NULL) { @@ -503,6 +554,13 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit [pool release]; return NULL; } + CGFloat pixelScale = 1.0; // default +NS_DURING + // Available >= 10.7 + pixelScale = [screen backingScaleFactor]; // HiDPI scaling +NS_HANDLER +NS_ENDHANDLER + CGDirectDisplayID display = NewtScreen_getCGDirectDisplayIDByNSScreen(screen); CFArrayRef availableModes = CGDisplayAvailableModes(display); @@ -516,8 +574,8 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit #ifdef VERBOSE_ON if(0 >= mode_idx) { // only for current mode (-1) and first mode (scanning) - DBG_PRINT( "getScreenMode0: scrn %d (%p, %p), mode %d, avail: %d/%d, current rot %d ccw\n", - (int)crt_idx, screen, (void*)(intptr_t)display, (int)mode_idx, (int)numberOfAvailableModes, (int)numberOfAvailableModesRots, currentCCWRot); + DBG_PRINT( "getScreenMode0: scrn %d (s %p, d %p, pscale %lf), mode %d, avail: %d/%d, current rot %d ccw\n", + (int)crt_idx, screen, (void*)(intptr_t)display, pixelScale, (int)mode_idx, (int)numberOfAvailableModes, (int)numberOfAvailableModesRots, currentCCWRot); } #endif @@ -543,6 +601,10 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit int mWidth = CGDDGetModeWidth(mode); int mHeight = CGDDGetModeHeight(mode); + if( -1 == mode_idx ) { + mWidth *= (int)pixelScale; // accomodate HiDPI + mHeight *= (int)pixelScale; // accomodate HiDPI + } // swap width and height, since OSX reflects rotated dimension, we don't if ( 90 == currentCCWRot || 270 == currentCCWRot ) { @@ -564,7 +626,7 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_macosx_ScreenDriver_getMonit prop[propIndex++] = 0; // flags prop[propIndex++] = nativeId; prop[propIndex++] = ccwRot; - + DBG_PRINT( "getScreenMode0: Mode %d/%d (%d): %dx%d, %d bpp, %d / %d Hz, nativeId %d, rot %d ccw\n", (int)mode_idx, (int)numberOfAvailableModesRots, (int)numberOfAvailableModes, (int)prop[1], (int)prop[2], (int)prop[3], @@ -653,6 +715,8 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_initIDs0 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + NewtScreen_dump(); + jclass c; c = (*env)->FindClass(env, ClazzNamePoint); if(NULL==c) { @@ -694,21 +758,13 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_createView0 DBG_PRINT( "createView0 - %p (this), %d/%d %dx%d, fs %d (START)\n", (void*)(intptr_t)jthis, (int)x, (int)y, (int)w, (int)h, (int)fullscreen); - NSScreen *myScreen = NewtScreen_getNSScreenByCoord(x, y); - NSRect rectWin; - - if (fullscreen) { - rectWin = [myScreen frame]; - x = 0; - y = 0; - w = (jint) (rectWin.size.width); - h = (jint) (rectWin.size.height); - } else { - rectWin = NSMakeRect(x, y, w, h); - } - NSRect rectView = NSMakeRect(0, 0, w, h); NewtView *myView = [[NewtView alloc] initWithFrame: rectView] ; +NS_DURING + // Available >= 10.7 + [myView setWantsBestResolutionOpenGLSurface: YES]; // HiDPI scaling: Always desired +NS_HANDLER +NS_ENDHANDLER DBG_PRINT( "createView0.X - new view: %p\n", myView); [pool release]; @@ -735,19 +791,10 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_createWindow (int)styleMask, (int)bufferingType, myView); (void)myView; - NSScreen *myScreen = NewtScreen_getNSScreenByCoord(x, y); - - NSRect rectWin; if (fullscreen) { styleMask = NSBorderlessWindowMask; - rectWin = [myScreen frame]; - x = 0; - y = 0; - w = (jint) (rectWin.size.width); - h = (jint) (rectWin.size.height); - } else { - rectWin = NSMakeRect(x, y, w, h); } + NSRect rectWin = NSMakeRect(x, y, w, h); // Allocate the window NewtMacWindow* myWindow = [[NewtMacWindow alloc] initWithContentRect: rectWin @@ -772,7 +819,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_createWindow * Signature: (JJIIIIZZZJ)V */ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_initWindow0 - (JNIEnv *env, jobject jthis, jlong parent, jlong window, jint x, jint y, jint w, jint h, + (JNIEnv *env, jobject jthis, jlong parent, jlong window, jint x, jint y, jint w, jint h, jboolean opaque, jboolean visible, jlong jview) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; @@ -784,19 +831,6 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_initWindow0 (void*)(intptr_t)jthis, (void*)(intptr_t)parent, myWindow, (int)x, (int)y, (int)w, (int)h, (int) opaque, (int)fullscreen, (int)visible, myView); - NSScreen *myScreen = NewtScreen_getNSScreenByCoord(x, y); - - NSRect rectWin; - if (fullscreen) { - rectWin = [myScreen frame]; - x = 0; - y = 0; - w = (jint) (rectWin.size.width); - h = (jint) (rectWin.size.height); - } else { - rectWin = NSMakeRect(x, y, w, h); - } - [myWindow setReleasedWhenClosed: NO]; // We control NSWindow destruction! [myWindow setPreservesContentDuringLiveResize: NO]; NS_DURING @@ -927,6 +961,7 @@ NS_DURING * Shall have no penalty on modern GPU and is also recommended, see bottom box @ * <https://developer.apple.com/library/mac/documentation/graphicsimaging/Conceptual/QuartzDisplayServicesConceptual/Articles/DisplayCapture.html> * + NSScreen *myScreen = NewtScreen_getNSScreenByCoord(x, y); if ( [myView respondsToSelector:@selector(enterFullScreenMode:withOptions:)] ) { // Available >= 10.5 - Makes the menubar disapear [myView enterFullScreenMode: myScreen withOptions:NULL]; diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h index 8f6362ac2..0f80df2d7 100644 --- a/src/newt/native/NewtMacWindow.h +++ b/src/newt/native/NewtMacWindow.h @@ -49,6 +49,10 @@ // #define DBG_LIFECYCLE 1 +NSScreen * NewtScreen_getNSScreenByIndex(int screen_idx, BOOL cap); +NSScreen * NewtScreen_getNSScreenByCoord(int x, int y); +CGDirectDisplayID NewtScreen_getCGDirectDisplayIDByNSScreen(NSScreen *screen); + @interface NewtView : NSView { jobject javaWindowObject; @@ -129,6 +133,7 @@ - (void) handleFlagsChanged:(int) keyMask keyIndex: (int) keyIdx keyCode: (int) keyCode modifiers: (NSUInteger) mods; - (void) sendKeyEvent: (NSEvent*) event eventType: (jshort) evType; - (void) sendKeyEvent: (jshort) keyCode characters: (NSString*) chars modifiers: (NSUInteger)mods eventType: (jshort) evType; +- (void) viewDidChangeBackingProperties; @end diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m index b4133ac7e..1a70de445 100644 --- a/src/newt/native/NewtMacWindow.m +++ b/src/newt/native/NewtMacWindow.m @@ -174,6 +174,7 @@ static jmethodID requestFocusID = NULL; static jmethodID insetsChangedID = NULL; static jmethodID sizeChangedID = NULL; +static jmethodID updatePixelScaleID = NULL; static jmethodID visibleChangedID = NULL; static jmethodID positionChangedID = NULL; static jmethodID focusChangedID = NULL; @@ -330,8 +331,8 @@ static jmethodID windowRepaintID = NULL; NSRect viewFrame = [self frame]; (*env)->CallVoidMethod(env, javaWindowObject, windowRepaintID, JNI_TRUE, // defer .. - dirtyRect.origin.x, viewFrame.size.height - dirtyRect.origin.y, - dirtyRect.size.width, dirtyRect.size.height); + (int)dirtyRect.origin.x, (int)viewFrame.size.height - (int)dirtyRect.origin.y, + (int)dirtyRect.size.width, (int)dirtyRect.size.height); // detaching thread not required - daemon // NewtCommon_ReleaseJNIEnv(shallBeDetached); @@ -761,6 +762,31 @@ static jmethodID windowRepaintID = NULL; // NewtCommon_ReleaseJNIEnv(shallBeDetached); } +- (void)viewDidChangeBackingProperties +{ + [super viewDidChangeBackingProperties]; + + CGFloat pixelScale = [[self window] backingScaleFactor]; + [[self layer] setContentsScale: pixelScale]; + + if (javaWindowObject == NULL) { + DBG_PRINT("viewDidChangeBackingProperties: null javaWindowObject\n"); + return; + } + int shallBeDetached = 0; + JNIEnv* env = NewtCommon_GetJNIEnv(1 /* asDaemon */, &shallBeDetached); + if(NULL==env) { + DBG_PRINT("viewDidChangeBackingProperties: null JNIEnv\n"); + return; + } + + (*env)->CallVoidMethod(env, javaWindowObject, updatePixelScaleID, JNI_TRUE, (jfloat)pixelScale); // defer + + // detaching thread not required - daemon + // NewtCommon_ReleaseJNIEnv(shallBeDetached); +} + + @end @implementation NewtMacWindow @@ -769,7 +795,8 @@ static jmethodID windowRepaintID = NULL; { enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(ZSIIISF)V"); enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(ZSISCC)V"); - sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); + sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V"); + updatePixelScaleID = (*env)->GetMethodID(env, clazz, "updatePixelScale", "(ZF)V"); visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(ZZ)V"); insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(ZIIII)V"); positionChangedID = (*env)->GetMethodID(env, clazz, "screenPositionChanged", "(ZII)V"); @@ -777,7 +804,7 @@ static jmethodID windowRepaintID = NULL; windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z"); windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(ZIIII)V"); requestFocusID = (*env)->GetMethodID(env, clazz, "requestFocus", "(Z)V"); - if (enqueueMouseEventID && enqueueKeyEventID && sizeChangedID && visibleChangedID && insetsChangedID && + if (enqueueMouseEventID && enqueueKeyEventID && sizeChangedID && updatePixelScaleID && visibleChangedID && insetsChangedID && positionChangedID && focusChangedID && windowDestroyNotifyID && requestFocusID && windowRepaintID) { CKCH_CreateDictionaries(); @@ -824,10 +851,12 @@ static jmethodID windowRepaintID = NULL; // Why is this necessary? Without it we don't get any of the // delegate methods like resizing and window movement. [self setDelegate: self]; + cachedInsets[0] = 0; // l cachedInsets[1] = 0; // r cachedInsets[2] = 0; // t cachedInsets[3] = 0; // b + realized = YES; DBG_PRINT("NewtWindow::create: %p, realized %d, hasPresentationSwitch %d[defaultOptions 0x%X, fullscreenOptions 0x%X], (refcnt %d)\n", res, realized, (int)hasPresentationSwitch, (int)defaultPresentationOptions, (int)fullscreenPresentationOptions, (int)[res retainCount]); @@ -1123,7 +1152,7 @@ static jmethodID windowRepaintID = NULL; NSRect frameRect = [self frame]; NSRect contentRect = [self contentRectForFrameRect: frameRect]; - (*env)->CallVoidMethod(env, javaWindowObject, sizeChangedID, JNI_FALSE, + (*env)->CallVoidMethod(env, javaWindowObject, sizeChangedID, JNI_TRUE, // defer (jint) contentRect.size.width, (jint) contentRect.size.height, JNI_FALSE); } diff --git a/src/newt/native/ScreenMode.h b/src/newt/native/ScreenMode.h index 110f1c493..56c424b11 100644 --- a/src/newt/native/ScreenMode.h +++ b/src/newt/native/ScreenMode.h @@ -40,7 +40,8 @@ #define NUM_MONITOR_MODE_PROPERTIES_ALL 8 /* count + the above */ -#define MIN_MONITOR_DEVICE_PROPERTIES 11 /* count + id, ScreenSizeMM[width, height], rotated Viewport[x, y, width, height], currentMonitorModeId, rotation, supportedModeId+ */ +#define MIN_MONITOR_DEVICE_PROPERTIES 15 /* count + id, ScreenSizeMM[width, height], rotated Viewport pixel-units, rotated Viewport pixel-units, currentMonitorModeId, rotation, supportedModeId+ */ + /* Viewport := [x, y, width, height] (4 elements) */ #define FLAG_INTERLACE ( 1 << 0 ) #define FLAG_DOUBLESCAN ( 1 << 1 ) diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index c20e156c1..70d0c6f83 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1859,10 +1859,14 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_windows_ScreenDriver_getMoni prop[propIndex++] = monitor_idx; prop[propIndex++] = widthmm; prop[propIndex++] = heightmm; - prop[propIndex++] = dm.dmPosition.x; // rotated viewport - prop[propIndex++] = dm.dmPosition.y; // rotated viewport - prop[propIndex++] = dm.dmPelsWidth; // rotated viewport - prop[propIndex++] = dm.dmPelsHeight; // rotated viewport + prop[propIndex++] = dm.dmPosition.x; // rotated viewport pixel units + prop[propIndex++] = dm.dmPosition.y; // rotated viewport pixel units + prop[propIndex++] = dm.dmPelsWidth; // rotated viewport pixel units + prop[propIndex++] = dm.dmPelsHeight; // rotated viewport pixel units + prop[propIndex++] = dm.dmPosition.x; // rotated viewport window units (same) + prop[propIndex++] = dm.dmPosition.y; // rotated viewport window units (same) + prop[propIndex++] = dm.dmPelsWidth; // rotated viewport window units (same) + prop[propIndex++] = dm.dmPelsHeight; // rotated viewport window units (same) jintArray properties = (*env)->NewIntArray(env, propCount); if (properties == NULL) { diff --git a/src/newt/native/X11RandR13.c b/src/newt/native/X11RandR13.c index 92c20e893..4e92a32b4 100644 --- a/src/newt/native/X11RandR13.c +++ b/src/newt/native/X11RandR13.c @@ -426,10 +426,14 @@ JNIEXPORT jintArray JNICALL Java_jogamp_newt_driver_x11_RandR13_getMonitorDevice prop[propIndex++] = crt_idx; prop[propIndex++] = xrrOutputInfo->mm_width; prop[propIndex++] = xrrOutputInfo->mm_height; - prop[propIndex++] = xrrCrtcInfo->x; - prop[propIndex++] = xrrCrtcInfo->y; - prop[propIndex++] = xrrCrtcInfo->width; - prop[propIndex++] = xrrCrtcInfo->height; + prop[propIndex++] = xrrCrtcInfo->x; // rotated viewport pixel units + prop[propIndex++] = xrrCrtcInfo->y; // rotated viewport pixel units + prop[propIndex++] = xrrCrtcInfo->width; // rotated viewport pixel units + prop[propIndex++] = xrrCrtcInfo->height; // rotated viewport pixel units + prop[propIndex++] = xrrCrtcInfo->x; // rotated viewport window units (same) + prop[propIndex++] = xrrCrtcInfo->y; // rotated viewport window units (same) + prop[propIndex++] = xrrCrtcInfo->width; // rotated viewport window units (same) + prop[propIndex++] = xrrCrtcInfo->height; // rotated viewport window units (same) prop[propIndex++] = xrrCrtcInfo->mode; // current mode id prop[propIndex++] = NewtScreen_XRotation2Degree(env, xrrCrtcInfo->rotation); int i; diff --git a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java index 5cbcb7380..54b994d1f 100644 --- a/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java +++ b/src/test/com/jogamp/opengl/test/android/MovieSimpleActivity1.java @@ -172,7 +172,7 @@ public class MovieSimpleActivity1 extends NewtBaseActivity { public boolean run(GLAutoDrawable drawable) { final GLMediaPlayer mPlayerSub; final MovieSimple demoHUD; - final Rectangle windowBounds = scrn.getViewportInWindowUnits(glWindowHUD); + final Rectangle windowBounds = (Rectangle) scrn.getViewportInWindowUnits().cloneMutable(); if(null != mPlayerShared) { if(0 < mPlayerShared.getWidth() && mPlayerShared.getWidth()<scrn.getWidth()/2 && 0 < mPlayerShared.getHeight() && mPlayerShared.getHeight()<scrn.getHeight()/2) { diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo.java index 5c217a7dc..14ff53f10 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo.java @@ -59,6 +59,8 @@ public class GPURegionNewtDemo { static boolean GraphUseWeight = true; public static void main(String[] args) { + int width = 800, height = 400; + int x = 10, y = 10; if( 0 != args.length ) { SceneMSAASamples = 0; GraphMSAASamples = 0; @@ -79,9 +81,23 @@ public class GPURegionNewtDemo { GraphVBAASamples = MiscUtils.atoi(args[i], GraphVBAASamples); } else if(args[i].equals("-gweight")) { GraphUseWeight = true; + } else if(args[i].equals("-width")) { + i++; + width = MiscUtils.atoi(args[i], width); + } else if(args[i].equals("-height")) { + i++; + height = MiscUtils.atoi(args[i], height); + } else if(args[i].equals("-x")) { + i++; + x = MiscUtils.atoi(args[i], x); + } else if(args[i].equals("-y")) { + i++; + y = MiscUtils.atoi(args[i], y); } } } + System.err.println("Desired win size "+width+"x"+height); + System.err.println("Desired win pos "+x+"/"+y); System.err.println("Scene MSAA Samples "+SceneMSAASamples); System.err.println("Graph MSAA Samples"+GraphMSAASamples); System.err.println("Graph VBAA Samples "+GraphVBAASamples); @@ -107,8 +123,8 @@ public class GPURegionNewtDemo { } final GLWindow window = GLWindow.create(caps); - window.setPosition(10, 10); - window.setSurfaceSize(800, 400); + window.setPosition(x, y); + window.setSize(width, height); window.setTitle("GPU Curve Region Newt Demo - graph[vbaa"+GraphVBAASamples+" msaa"+GraphMSAASamples+"], msaa "+SceneMSAASamples); RenderState rs = RenderState.createRenderState(SVertex.factory()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java index 09cf706ce..6a91d005e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo.java @@ -60,6 +60,8 @@ public class GPUTextNewtDemo { static int GraphMSAASamples = 0; public static void main(String[] args) { + int width = 800, height = 400; + int x = 10, y = 10; if( 0 != args.length ) { SceneMSAASamples = 0; GraphMSAASamples = 0; @@ -77,9 +79,23 @@ public class GPUTextNewtDemo { i++; GraphMSAASamples = 0; GraphVBAASamples = MiscUtils.atoi(args[i], GraphVBAASamples); + } else if(args[i].equals("-width")) { + i++; + width = MiscUtils.atoi(args[i], width); + } else if(args[i].equals("-height")) { + i++; + height = MiscUtils.atoi(args[i], height); + } else if(args[i].equals("-x")) { + i++; + x = MiscUtils.atoi(args[i], x); + } else if(args[i].equals("-y")) { + i++; + y = MiscUtils.atoi(args[i], y); } } } + System.err.println("Desired win size "+width+"x"+height); + System.err.println("Desired win pos "+x+"/"+y); System.err.println("Scene MSAA Samples "+SceneMSAASamples); System.err.println("Graph MSAA Samples "+GraphMSAASamples); System.err.println("Graph VBAA Samples "+GraphVBAASamples); @@ -105,8 +121,8 @@ public class GPUTextNewtDemo { } final GLWindow window = GLWindow.create(caps); - window.setPosition(10, 10); - window.setSurfaceSize(800, 400); + window.setPosition(x, y); + window.setSize(width, height); window.setTitle("GPU Text Newt Demo - graph[vbaa"+GraphVBAASamples+" msaa"+GraphMSAASamples+"], msaa "+SceneMSAASamples); RenderState rs = RenderState.createRenderState(SVertex.factory()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java index c26cb467a..9e5ecb648 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo.java @@ -21,7 +21,8 @@ public class GPUUISceneNewtDemo { static boolean GraphMSAAMode = false; public static void main(String[] args) { - int swidth = 800, sheight = 400; + int width = 800, height = 400; + int x = 10, y = 10; if( 0 != args.length ) { for(int i=0; i<args.length; i++) { if(args[i].equals("-smsaa")) { @@ -37,13 +38,21 @@ public class GPUUISceneNewtDemo { GraphVBAAMode = true; } else if(args[i].equals("-width")) { i++; - swidth = MiscUtils.atoi(args[i], swidth); + width = MiscUtils.atoi(args[i], width); } else if(args[i].equals("-height")) { i++; - sheight = MiscUtils.atoi(args[i], sheight); + height = MiscUtils.atoi(args[i], height); + } else if(args[i].equals("-x")) { + i++; + x = MiscUtils.atoi(args[i], x); + } else if(args[i].equals("-y")) { + i++; + y = MiscUtils.atoi(args[i], y); } } } + System.err.println("Desired win size "+width+"x"+height); + System.err.println("Desired win pos "+x+"/"+y); System.err.println("Scene MSAA Samples "+SceneMSAASamples); System.err.println("Graph MSAA Mode "+GraphMSAAMode); System.err.println("Graph VBAA Mode "+GraphVBAAMode); @@ -67,8 +76,8 @@ public class GPUUISceneNewtDemo { } final GLWindow window = GLWindow.create(caps); - window.setPosition(10, 10); - window.setSurfaceSize(swidth, sheight); + window.setPosition(x, y); + window.setSize(width, height); window.setTitle("GraphUI Newt Demo: graph["+Region.getRenderModeString(rmode)+"], msaa "+SceneMSAASamples); final RenderState rs = RenderState.createRenderState(SVertex.factory()); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java index 5fe863527..27a91befc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java @@ -61,7 +61,7 @@ public class UINewtDemo01 { final GLWindow window = GLWindow.create(caps); window.setPosition(10, 10); - window.setSurfaceSize(800, 400); + window.setSize(800, 400); window.setTitle("GPU UI Newt Demo 01"); RenderState rs = RenderState.createRenderState(SVertex.factory()); UIGLListener01 uiGLListener = new UIGLListener01 (0, rs, DEBUG, TRACE); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java index 82fa6422d..8113f34ee 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.jogl.acore; import java.io.IOException; @@ -61,14 +61,14 @@ import com.jogamp.opengl.test.junit.util.UITestCase; /** * Tests using a NEWT {@link Window} for on- and offscreen cases. * <p> - * Each test creates a {@link GLDrawable} using the + * Each test creates a {@link GLDrawable} using the * {@link GLDrawableFactory#createGLDrawable(javax.media.nativewindow.NativeSurface) factory model}. * The {@link GLContext} is derived {@link GLDrawable#createContext(GLContext) from the drawable}. * </p> * <p> * Finally a {@link GLAutoDrawableDelegate} is created with the just created {@link GLDrawable} and {@link GLContext}. - * It is being used to run the {@link GLEventListener}. - * </p> + * It is being used to run the {@link GLEventListener}. + * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { @@ -83,7 +83,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { } return new GLCapabilities(GLProfile.get(profile)); } - + void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { System.out.println("Requested GL Caps: "+reqGLCaps); final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile()); @@ -91,7 +91,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { System.out.println("Expected GL Caps: "+expGLCaps); // // Create native windowing resources .. X11/Win/OSX - // + // final Window window = NewtFactory.createWindow(reqGLCaps); Assert.assertNotNull(window); window.setSize(widthStep*szStep, heightStep*szStep); @@ -99,7 +99,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForVisible(window, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(window, true)); System.out.println("Window: "+window.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = window.getGraphicsConfiguration().getChosenCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -109,13 +109,13 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertTrue(chosenCaps.getRedBits()>5); // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // final GLDrawable drawable = factory.createGLDrawable(window); Assert.assertNotNull(drawable); System.out.println("Drawable Pre-GL(0): "+drawable.getClass().getName()+", "+drawable.getNativeSurface().getClass().getName()); - + // drawable.setRealized(true); Assert.assertTrue(drawable.isRealized()); @@ -123,13 +123,13 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { System.out.println("Window Caps PostGL : "+window.getGraphicsConfiguration().getChosenCapabilities()); System.out.println("Drawable Post-GL(1): "+drawable.getClass().getName()+", "+drawable.getNativeSurface().getClass().getName()); - // Note: FBO Drawable realization happens at 1st context.makeCurrent(), + // Note: FBO Drawable realization happens at 1st context.makeCurrent(), // and hence only then it's caps can _fully_ reflect expectations, // i.e. depth, stencil and MSAA will be valid only after makeCurrent(), // where on-/offscreen state after setRealized(true) // See GLFBODrawable API doc in this regard! - - + + final GLCapabilitiesImmutable chosenGLCaps01 = drawable.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps01); Assert.assertNotNull(chosenGLCaps01); @@ -137,13 +137,13 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps01.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps01.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps01.isBitmap()); - + final GLContext context = drawable.createContext(null); Assert.assertNotNull(context); int res = context.makeCurrent(); Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res); context.release(); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps02 = drawable.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(2): "+chosenGLCaps02); @@ -158,12 +158,12 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps02.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps02.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps02.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); } */ - + final GLAutoDrawableDelegate glad = new GLAutoDrawableDelegate(drawable, context, window, false, null) { @Override protected void destroyImplInLock() { @@ -171,12 +171,12 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { window.destroy(); // destroys the actual window, incl. the device } }; - + window.setWindowDestroyNotifyAction( new Runnable() { public void run() { glad.windowDestroyNotifyOp(); } } ); - + window.addWindowListener(new WindowAdapter() { @Override public void windowRepaint(WindowUpdateEvent e) { @@ -190,38 +190,45 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { }); glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; window.setSize(widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; window.setSize(widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + glad.destroy(); - System.out.println("Fin Drawable: "+drawable); + System.out.println("Fin Drawable: "+drawable); System.out.println("Fin Window: "+window); } @@ -236,7 +243,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -244,14 +251,14 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -269,7 +276,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -278,7 +285,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setFBO(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbufferDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -287,7 +294,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbufferSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -297,7 +304,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenBitmapSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -307,7 +314,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new Gears(1)); } - + @Test public void testES2OnScreenSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -315,14 +322,14 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -340,7 +347,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenFBODblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -349,7 +356,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setFBO(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenPbufferDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -358,7 +365,7 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenPbufferSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -368,19 +375,19 @@ public class TestGLAutoDrawableDelegateOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + /** Not implemented ! @Test public void testES2OffScreenBitmapDblBuf() throws InterruptedException { if(!checkProfile(GLProfile.GLES2)) { return; } - final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); reqGLCaps.setOnscreen(false); reqGLCaps.setBitmap(true); doTest(reqGLCaps, new GearsES2(1)); } */ - + public static void main(String args[]) throws IOException { org.junit.runner.JUnitCore.main(TestGLAutoDrawableDelegateOnOffscrnCapsNEWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java index 888572444..2d231fb6d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.jogl.acore; import java.awt.Dimension; @@ -74,7 +74,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { } return new GLCapabilities(GLProfile.get(profile)); } - + static void setGLCanvasSize(final Frame frame, final GLCanvas glc, final int width, final int height) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { @@ -89,13 +89,13 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + static interface MyGLEventListener extends GLEventListener { void setMakeSnapshot(); } - + void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { if(reqGLCaps.isOnscreen() && JAWTUtil.isOffscreenLayerRequired()) { System.err.println("onscreen layer n/a"); @@ -120,8 +120,8 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { glad.setSize(glc_sz); final Frame frame = new Frame(getSimpleTestName(".")); Assert.assertNotNull(frame); - frame.add(glad); - + frame.add(glad); + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -132,11 +132,11 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { throwable.printStackTrace(); Assume.assumeNoException( throwable ); } - + Assert.assertTrue(AWTRobotUtil.waitForVisible(glad, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(glad, true)); System.out.println("Window: "+glad.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -146,20 +146,20 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { Assert.assertTrue(chosenCaps.getRedBits()>5); glad.display(); // force native context creation - + // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // { final GLDrawable actualDrawable = glad.getDelegatedDrawable(); Assert.assertNotNull(actualDrawable); System.out.println("Drawable Pre-GL(0): "+actualDrawable.getClass().getName()+", "+actualDrawable.getNativeSurface().getClass().getName()); } - + System.out.println("Window Caps PostGL : "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(1): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps); @@ -172,7 +172,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); @@ -184,43 +184,50 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { Assert.assertNotNull(context); Assert.assertTrue(context.isCreated()); } - + System.out.println("Chosen GL Caps(2): "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(2): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; setGLCanvasSize(frame, glad, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; setGLCanvasSize(frame, glad, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -231,7 +238,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } System.out.println("Fin: "+glad); } @@ -246,14 +253,14 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -261,7 +268,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -270,7 +277,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -280,7 +287,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -298,7 +305,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -309,7 +316,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -321,7 +328,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbuffer() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -330,7 +337,7 @@ public class TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + public static void main(String args[]) throws IOException { for(int i=0; i<args.length; i++) { if(args[i].equals("-wait")) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT.java index 4cdbb6fb0..8acec337b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.jogl.acore; import java.io.IOException; @@ -57,8 +57,8 @@ import com.jogamp.opengl.test.junit.util.UITestCase; /** * Tests using a NEWT {@link GLWindow} {@link GLAutoDrawable auto drawable} for on- and offscreen cases. * <p> - * The NEWT {@link GLAutoDrawable} is being used to run the {@link GLEventListener}. - * </p> + * The NEWT {@link GLAutoDrawable} is being used to run the {@link GLEventListener}. + * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { @@ -69,7 +69,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { static interface MyGLEventListener extends GLEventListener { void setMakeSnapshot(); } - + static GLCapabilities getCaps(String profile) { if( !GLProfile.isAvailable(profile) ) { System.err.println("Profile "+profile+" n/a"); @@ -77,7 +77,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { } return new GLCapabilities(GLProfile.get(profile)); } - + void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { System.out.println("Requested GL Caps: "+reqGLCaps); final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile()); @@ -85,7 +85,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { System.out.println("Expected GL Caps: "+expGLCaps); // // Create native windowing resources .. X11/Win/OSX - // + // final GLWindow glad = GLWindow.create(reqGLCaps); Assert.assertNotNull(glad); glad.setSize(widthStep*szStep, heightStep*szStep); @@ -93,7 +93,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForVisible(glad, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(glad, true)); System.out.println("Window: "+glad.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = glad.getGraphicsConfiguration().getChosenCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -103,18 +103,18 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { Assert.assertTrue(chosenCaps.getRedBits()>5); // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // { final GLDrawable actualDrawable = glad.getDelegatedDrawable(); Assert.assertNotNull(actualDrawable); System.out.println("Drawable Pre-GL(0): "+actualDrawable.getClass().getName()+", "+actualDrawable.getNativeSurface().getClass().getName()); } - + System.out.println("Window Caps PostGL : "+glad.getGraphicsConfiguration().getChosenCapabilities()); System.out.println("Drawable Post-GL(1): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps); @@ -127,7 +127,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); @@ -140,41 +140,48 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { Assert.assertNotNull(context); Assert.assertTrue(context.isCreated()); } - + System.out.println("Chosen GL Caps(2): "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(2): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; glad.setSize(widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; glad.setSize(widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + glad.destroy(); System.out.println("Fin: "+glad); } @@ -190,7 +197,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -198,14 +205,14 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -213,7 +220,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -222,7 +229,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -232,7 +239,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -250,7 +257,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -259,7 +266,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setFBO(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -269,7 +276,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -280,7 +287,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -292,7 +299,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbufferDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -301,7 +308,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbufferSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -311,7 +318,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenBitmapSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -321,7 +328,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new Gears(1)); } - + @Test public void testES2OnScreenSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -329,14 +336,14 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); if(null == reqGLCaps) return; doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OnScreenDblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -344,7 +351,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OnScreenDblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -353,7 +360,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OnScreenDblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -363,7 +370,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -381,7 +388,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenFBODblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -390,7 +397,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setFBO(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenFBODblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -400,7 +407,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setStencilBits(1); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenFBODblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -411,7 +418,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenFBODblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -423,7 +430,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setNumSamples(4); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenPbufferDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -432,7 +439,7 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setPBuffer(true); doTest(reqGLCaps, new GearsES2(1)); } - + @Test public void testES2OffScreenPbufferSglBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GLES2); @@ -442,19 +449,19 @@ public class TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT extends UITestCase { reqGLCaps.setDoubleBuffered(false); doTest(reqGLCaps, new GearsES2(1)); } - + /** Not implemented ! @Test public void testES2OffScreenBitmapDblBuf() throws InterruptedException { if(!checkProfile(GLProfile.GLES2)) { return; } - final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + final GLCapabilities reqGLCaps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); reqGLCaps.setOnscreen(false); reqGLCaps.setBitmap(true); doTest(reqGLCaps, new GearsES2(1)); } */ - + public static void main(String args[]) throws IOException { org.junit.runner.JUnitCore.main(TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT.java index 22a515f42..bfdad4427 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.jogl.acore; import java.awt.Component; @@ -63,8 +63,8 @@ import com.jogamp.opengl.test.junit.util.UITestCase; /** * Tests using a NEWT {@link GLWindow} {@link GLAutoDrawable auto drawable} for on- and offscreen cases. * <p> - * The NEWT {@link GLAutoDrawable} is being used to run the {@link GLEventListener}. - * </p> + * The NEWT {@link GLAutoDrawable} is being used to run the {@link GLEventListener}. + * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase { @@ -79,7 +79,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } return new GLCapabilities(GLProfile.get(profile)); } - + static void setComponentSize(final Frame frame, final Component comp, final int width, final int height) { try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { @@ -94,13 +94,13 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + static interface MyGLEventListener extends GLEventListener { void setMakeSnapshot(); } - + void doTest(boolean offscreenLayer, GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { if(!offscreenLayer && JAWTUtil.isOffscreenLayerRequired()) { System.err.println("onscreen layer n/a"); @@ -112,16 +112,16 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } System.out.println("Requested GL Caps: "+reqGLCaps); final GLDrawableFactory factory = GLDrawableFactory.getFactory(reqGLCaps.getGLProfile()); - final AbstractGraphicsDevice device = factory.getDefaultDevice(); + final AbstractGraphicsDevice device = factory.getDefaultDevice(); final GLCapabilitiesImmutable expGLCaps = offscreenLayer ? GLGraphicsConfigurationUtil.fixOffscreenGLCapabilities(reqGLCaps, factory, device) : GLGraphicsConfigurationUtil.fixGLCapabilities(reqGLCaps, factory, device); System.out.println("Expected GL Caps: "+expGLCaps); - + final GLWindow glad = GLWindow.create(reqGLCaps); Assert.assertNotNull(glad); - + final NewtCanvasAWT nca = new NewtCanvasAWT(glad); Assert.assertNotNull(nca); Dimension size0 = new Dimension(widthStep*szStep, heightStep*szStep); @@ -129,11 +129,11 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase nca.setPreferredSize(size0); nca.setMinimumSize(size0); nca.setSize(size0); - + final Frame frame = new Frame(getSimpleTestName(".")); Assert.assertNotNull(frame); - frame.add(nca); - + frame.add(nca); + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -144,11 +144,11 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase throwable.printStackTrace(); Assume.assumeNoException( throwable ); } - + Assert.assertTrue(AWTRobotUtil.waitForVisible(glad, true)); Assert.assertTrue(AWTRobotUtil.waitForRealized(glad, true)); System.out.println("Window: "+glad.getClass().getName()); - + // Check caps of NativeWindow config w/o GL final CapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities(); System.out.println("Window Caps Pre_GL: "+chosenCaps); @@ -158,20 +158,20 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase Assert.assertTrue(chosenCaps.getRedBits()>5); glad.display(); // force native context creation - + // - // Create native OpenGL resources .. XGL/WGL/CGL .. + // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) - // + // { final GLDrawable actualDrawable = glad.getDelegatedDrawable(); Assert.assertNotNull(actualDrawable); System.out.println("Drawable Pre-GL(0): "+actualDrawable.getClass().getName()+", "+actualDrawable.getNativeSurface().getClass().getName()); } - + System.out.println("Window Caps PostGL : "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(1): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + // Check caps of GLDrawable after realization final GLCapabilitiesImmutable chosenGLCaps = glad.getChosenGLCapabilities(); System.out.println("Chosen GL Caps(1): "+chosenGLCaps); @@ -184,7 +184,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase Assert.assertEquals(expGLCaps.isFBO(), chosenGLCaps.isFBO()); Assert.assertEquals(expGLCaps.isPBuffer(), chosenGLCaps.isPBuffer()); Assert.assertEquals(expGLCaps.isBitmap(), chosenGLCaps.isBitmap()); - /** Single/Double buffer cannot be checked since result may vary .. + /** Single/Double buffer cannot be checked since result may vary .. if(chosenGLCaps.isOnscreen() || chosenGLCaps.isFBO()) { // dbl buffer may be disabled w/ offscreen pbuffer and bitmap Assert.assertEquals(expGLCaps.getDoubleBuffered(), chosenGLCaps.getDoubleBuffered()); @@ -196,43 +196,50 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase Assert.assertNotNull(context); Assert.assertTrue(context.isCreated()); } - + System.out.println("Chosen GL Caps(2): "+glad.getChosenGLCapabilities()); System.out.println("Drawable Post-GL(2): "+glad.getClass().getName()+", "+glad.getNativeSurface().getClass().getName()); - + glad.addGLEventListener(demo); - + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); glad.addGLEventListener(snapshotGLEventListener); - + glad.display(); // initial resize/display - + // 1 - szStep = 2 - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + final int[] expSurfaceSize = glad.getNativeSurface().convertToPixelUnits(new int[] { widthStep*szStep, heightStep*szStep }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 2, 3 (resize + display) szStep = 1; setComponentSize(frame, nca, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + // 4, 5 (resize + display) szStep = 4; setComponentSize(frame, nca, widthStep*szStep, heightStep*szStep); - Assert.assertTrue("Size not reached: Expected "+(widthStep*szStep)+"x"+(heightStep*szStep)+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glad, widthStep*szStep, heightStep*szStep)); + expSurfaceSize[0] = widthStep*szStep; + expSurfaceSize[1] = heightStep*szStep; + glad.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glad.getSurfaceWidth()+"x"+glad.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glad, expSurfaceSize[0], expSurfaceSize[1])); glad.display(); snapshotGLEventListener.setMakeSnapshot(); glad.display(); - + Thread.sleep(50); - + try { javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -243,7 +250,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } glad.destroy(); System.out.println("Fin: "+nca); System.out.println("Fin: "+glad); @@ -260,14 +267,14 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase System.err.println(JoglVersion.getDefaultOpenGLInfo(f.getDefaultDevice(), null, true).toString()); } } - + @Test public void testGL2OnScreenDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); if(null == reqGLCaps) return; doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencil() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -275,7 +282,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setStencilBits(1); doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -284,7 +291,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OnScreenDblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -294,7 +301,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(false, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenLayerAutoDblBuf() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -311,7 +318,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setStencilBits(1); doTest(true, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -322,7 +329,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(true, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenFBODblBufStencilMSAA() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -334,7 +341,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setNumSamples(4); doTest(true, reqGLCaps, new GearsES2(1)); } - + @Test public void testGL2OffScreenPbuffer() throws InterruptedException { final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2); @@ -343,7 +350,7 @@ public class TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT extends UITestCase reqGLCaps.setOnscreen(true); // get native NEWT Window, not OffscreenWindow doTest(true, reqGLCaps, new GearsES2(1)); } - + public static void main(String args[]) throws IOException { org.junit.runner.JUnitCore.main(TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java index 93713c783..173df57f6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGPUMemSec01NEWT.java @@ -54,12 +54,12 @@ public class TestGPUMemSec01NEWT extends UITestCase { return "0x"+Integer.toHexString(i); } static String exceptionMsg(String pre, int format, int type, int components, int width, int height, int rl1, int rl4, int rl8) { - return pre + + return pre + ": fmt "+hexString(format)+", type "+hexString(type)+", comps "+components+ ", "+width+"x"+height+ - ", rowlenA1 "+rl1+", rowlenA4 "+rl4+", rowlenA8 "+rl8; + ", rowlenA1 "+rl1+", rowlenA4 "+rl4+", rowlenA8 "+rl8; } - + static NEWTGLContext.WindowContext createCurrentGLOffscreenWindow(GLProfile glp, int width, int height) throws GLException, InterruptedException { final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOffscreenWindow( new GLCapabilities(glp), width, height, true); @@ -68,34 +68,34 @@ public class TestGPUMemSec01NEWT extends UITestCase { // System.err.println("Pre GL Error: 0x"+Integer.toHexString(gl.glGetError())); // System.err.println(winctx.drawable); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + // misc GL setup gl.glClearColor(1, 1, 1, 1); gl.glEnable(GL.GL_DEPTH_TEST); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - gl.glViewport(0, 0, width, height); + gl.glViewport(0, 0, width, height); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - + return winctx; } - + static int readPixelsCheck(GL gl, int format, int type, int components, int width, int height) throws InterruptedException { int expectedExceptions = 0; - - final int rowlenA1 = width * components; - - final int rowlenA4 = ( ( width * components + 3 ) / 4 ) * 4 ; + + final int rowlenA1 = width * components; + + final int rowlenA4 = ( ( width * components + 3 ) / 4 ) * 4 ; Assert.assertTrue(rowlenA4 % 4 == 0); final int rowlenA8 = ( ( width * components + 7 ) / 8 ) * 8 ; Assert.assertTrue(rowlenA8 % 8 == 0); - + GLPixelStorageModes psm = new GLPixelStorageModes(); psm.setPackAlignment(gl, 1); - + Exception ee = null; - + // ok size ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1); @@ -105,11 +105,11 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; } Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 1)", + exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 1)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - - + + // too small -10 ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1-10); @@ -118,16 +118,16 @@ public class TestGPUMemSec01NEWT extends UITestCase { } catch(IndexOutOfBoundsException e) { ee = e; System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (size-10 bytes)", + exceptionMsg("OK Expected IndexOutOfBoundsException (size-10 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); - expectedExceptions++; + expectedExceptions++; } Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (size-10 bytes)", + exceptionMsg("Expected IndexOutOfBoundsException (size-10 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - + // too small size/4 ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1/4); @@ -136,21 +136,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { } catch(IndexOutOfBoundsException e) { ee = e; System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (size/4 bytes)", + exceptionMsg("OK Expected IndexOutOfBoundsException (size/4 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); - expectedExceptions++; + expectedExceptions++; } Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (size/4 bytes)", + exceptionMsg("Expected IndexOutOfBoundsException (size/4 bytes)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; // // Alignment test - // + // psm.setPackAlignment(gl, 4); - + // ok size ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA4); @@ -160,10 +160,10 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; } Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 4)", + exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 4)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - + // too small if rowlenA1%4 > 0 try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1); @@ -173,7 +173,7 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; if(rowlenA1%4>0) { System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 4)", + exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 4)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); expectedExceptions++; @@ -181,17 +181,17 @@ public class TestGPUMemSec01NEWT extends UITestCase { } if(rowlenA1%4>0) { Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (alignment 4)", + exceptionMsg("Expected IndexOutOfBoundsException (alignment 4)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } else { Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 4)", - format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); + exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 4)", + format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } ee = null; - + psm.setPackAlignment(gl, 8); - + // ok size ! try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA8); @@ -201,10 +201,10 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; } Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 8)", + exceptionMsg("Unexpected IndexOutOfBoundsException (size ok, alignment 8)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); ee = null; - + // too small if rowlenA1%8 > 0 try { ByteBuffer bb = Buffers.newDirectByteBuffer(height*rowlenA1); @@ -214,7 +214,7 @@ public class TestGPUMemSec01NEWT extends UITestCase { ee = e; if(rowlenA1%8>0) { System.err.println( - exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 8)", + exceptionMsg("OK Expected IndexOutOfBoundsException (alignment 8)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8)+ ": "+ee.getMessage()); expectedExceptions++; @@ -222,37 +222,37 @@ public class TestGPUMemSec01NEWT extends UITestCase { } if(rowlenA1%8>0) { Assert.assertNotNull( - exceptionMsg("Expected IndexOutOfBoundsException (alignment 8)", + exceptionMsg("Expected IndexOutOfBoundsException (alignment 8)", format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } else { Assert.assertNull( - exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 8)", - format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); + exceptionMsg("Unexpected IndexOutOfBoundsException (alignment 8)", + format, type, components, width, height, rowlenA1, rowlenA4, rowlenA8), ee); } ee = null; - - psm.restore(gl); - - return expectedExceptions; + + psm.restore(gl); + + return expectedExceptions; } - + @Test public void testReadPixelsGL_640x480xRGBAxUB() throws InterruptedException { GLProfile glp = GLProfile.getDefault(); final int width = 640; final int height= 480; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 0 x alignment Assert.assertEquals(2, readPixelsCheck(gl, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 4, width, height)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } @@ -263,21 +263,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { final int wheight= 480; final int rwidth = 99; final int rheight= 100; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 1 x alignment Assert.assertEquals(3, readPixelsCheck(gl, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 4, rwidth, rheight)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + @Test public void testReadPixelsGL2GL3_640x480xRGBxUB() throws InterruptedException { GLProfile glp = GLProfile.getGL2ES2(); @@ -287,21 +287,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { } final int width = 640; final int height= 480; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 0 x alignment Assert.assertEquals(2, readPixelsCheck(gl, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, 3, width, height)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + @Test public void testReadPixelsGL2GL3_99x100xRGBxUB() throws InterruptedException { GLProfile glp = GLProfile.getGL2ES2(); @@ -313,21 +313,21 @@ public class TestGPUMemSec01NEWT extends UITestCase { final int wheight= 480; final int rwidth = 99; final int rheight= 100; - + // preset .. final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL gl = winctx.context.getGL(); - + // 2 x too small - 2 x alignment Assert.assertEquals(4, readPixelsCheck(gl, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, 3, rwidth, rheight)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + @Test public void testReadPixelsGL2GL3_640x480xREDxUB() throws InterruptedException { GLProfile glp = GLProfile.getGL2ES2(); @@ -342,13 +342,13 @@ public class TestGPUMemSec01NEWT extends UITestCase { final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, width, height); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2GL3 gl = winctx.context.getGL().getGL2GL3(); - + // 2 x too small - 0 x alignment Assert.assertEquals(2, readPixelsCheck(gl, GL2ES2.GL_RED, GL.GL_UNSIGNED_BYTE, 1, width, height)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } @@ -368,19 +368,19 @@ public class TestGPUMemSec01NEWT extends UITestCase { final NEWTGLContext.WindowContext winctx = createCurrentGLOffscreenWindow(glp, wwidth, wheight); final GLDrawable drawable = winctx.context.getGLDrawable(); final GL2GL3 gl = winctx.context.getGL().getGL2GL3(); - + // 2 x too small - 2 x alignment Assert.assertEquals(4, readPixelsCheck(gl, GL2ES2.GL_RED, GL.GL_UNSIGNED_BYTE, 1, rwidth, rheight)); - + drawable.swapBuffers(); Thread.sleep(50); - + NEWTGLContext.destroyWindow(winctx); } - + public static void main(String args[]) throws IOException { String tstname = TestGPUMemSec01NEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); - } + } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/ManualHiDPIBufferedImage01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/ManualHiDPIBufferedImage01AWT.java new file mode 100644 index 000000000..0b67cfe46 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/ManualHiDPIBufferedImage01AWT.java @@ -0,0 +1,71 @@ +package com.jogamp.opengl.test.junit.jogl.awt; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.lang.reflect.InvocationTargetException; + +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +/** + * Manual test for BufferedImage behavior w/ OSX HiDPI pixel scale usage. + */ +public class ManualHiDPIBufferedImage01AWT { + + static final int width = 200; + static final int height = 100; + + public static void main(String[] args) throws InterruptedException, InvocationTargetException { + final JFrame frame = new JFrame(); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + final Image image1 = getImage(getCheckBox("High-DPI (no)", false), width, height, 1); + final Image image2 = getImage(getCheckBox("High-DPI (yes)", true), width, height, 2); + System.err.println("Image1: "+image1); + System.err.println("Image2: "+image2); + + @SuppressWarnings("serial") + final Canvas canvas = new Canvas() { + @Override + public void paint(Graphics g) { + super.paint(g); + g.drawImage(image1, 0, 0, width, height, this); + g.drawImage(image2, 0, height + 5, width, height, this); + } + }; + frame.getContentPane().add(getCheckBox("High-DPI (ref)", false), BorderLayout.NORTH); + frame.getContentPane().add(canvas, BorderLayout.CENTER); + + frame.setBounds((1440-400)/2, 100, 400, 400); + frame.validate(); + frame.setVisible(true); + } + }); + } + + static JCheckBox getCheckBox(String text, boolean selected) { + JCheckBox checkBox = new JCheckBox(text); + checkBox.setSelected(selected); + checkBox.setSize(new Dimension(width, height)); + return checkBox; + } + + static Image getImage(JComponent component, int width, int height, int scale) { + final BufferedImage image = new BufferedImage(width*scale, height*scale, BufferedImage.TYPE_INT_ARGB); + final Graphics g = image.getGraphics(); + ((Graphics2D) g).scale(scale, scale); + component.paint(g); + g.dispose(); + + return image; + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java index 116d5d245..42c1234da 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieCube.java @@ -561,7 +561,7 @@ public class MovieCube implements GLEventListener { anim.stop(); } }); - window.setSurfaceSize(width, height); + window.setSize(width, height); window.setVisible(true); System.err.println("Chosen: "+window.getChosenGLCapabilities()); anim.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java index 1997739e3..7b6dd162a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSimple.java @@ -1050,7 +1050,7 @@ public class MovieSimple implements GLEventListener { mss[i].mPlayer.addEventListener(myGLMediaEventListener); windows[i].setTitle("Player "+i); - windows[i].setSurfaceSize(width, height); + windows[i].setSize(width, height); windows[i].setVisible(true); anim.add(windows[i]); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java index 96a120c62..d9839c057 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,17 +20,18 @@ * 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.opengl.test.junit.jogl.demos.es2.awt; import javax.media.opengl.*; import com.jogamp.opengl.util.Animator; + import javax.media.opengl.awt.GLCanvas; import com.jogamp.common.os.Platform; @@ -38,7 +39,6 @@ import com.jogamp.newt.event.awt.AWTKeyAdapter; import com.jogamp.newt.event.awt.AWTWindowAdapter; import com.jogamp.newt.event.TraceKeyAdapter; import com.jogamp.newt.event.TraceWindowAdapter; - import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; import com.jogamp.opengl.test.junit.util.MiscUtils; @@ -53,6 +53,8 @@ import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Frame; import java.awt.TextArea; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -70,12 +72,13 @@ import org.junit.runners.MethodSorters; public class TestGearsES2AWT extends UITestCase { public enum FrameLayout { None, TextOnBottom, BorderCenterSurrounded, DoubleBorderCenterSurrounded }; public enum ResizeBy { Component, Frame }; - - static long duration = 500; // ms - static int width, height; + + static long duration = 500; // ms + static int width = 640, height = 480; + static int xpos = 10, ypos = 10; static FrameLayout frameLayout = FrameLayout.None; static ResizeBy resizeBy = ResizeBy.Component; - + static boolean forceES2 = false; static boolean forceGL3 = false; static boolean mainRun = false; @@ -94,8 +97,6 @@ public class TestGearsES2AWT extends UITestCase { @BeforeClass public static void initClass() { - width = 640; - height = 480; try { EventQueue.invokeAndWait(new Runnable() { public void run() { @@ -125,7 +126,7 @@ public class TestGearsES2AWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } static void setFrameSize(final Frame frame, final boolean frameLayout, final java.awt.Dimension new_sz) { try { @@ -139,9 +140,9 @@ public class TestGearsES2AWT extends UITestCase { } catch( Throwable throwable ) { throwable.printStackTrace(); Assume.assumeNoException( throwable ); - } + } } - + static void setSize(final ResizeBy resizeBy, final Frame frame, final boolean frameLayout, final Component comp, final java.awt.Dimension new_sz) { switch( resizeBy ) { case Component: @@ -150,17 +151,24 @@ public class TestGearsES2AWT extends UITestCase { case Frame: setFrameSize(frame, frameLayout, new_sz); break; - } + } + } + + private void setTitle(final Frame frame, final GLCanvas glc, final GLCapabilitiesImmutable caps) { + final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; + final java.awt.Rectangle b = glc.getBounds(); + frame.setTitle("GLCanvas["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()); } - - protected void runTestGL(GLCapabilities caps, final ResizeBy resizeBy, FrameLayout frameLayout) throws InterruptedException, InvocationTargetException { + + protected void runTestGL(final GLCapabilities caps, final ResizeBy resizeBy, FrameLayout frameLayout) throws InterruptedException, InvocationTargetException { final Frame frame = new Frame("GearsES2 AWT Test"); Assert.assertNotNull(frame); final GLCanvas glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); setSize(resizeBy, frame, false, glCanvas, new Dimension(width, height)); - + frame.setLocation(xpos, ypos); + switch( frameLayout) { case None: frame.add(glCanvas); @@ -174,7 +182,7 @@ public class TestGearsES2AWT extends UITestCase { frame.setLayout(new BorderLayout()); frame.add(ta, BorderLayout.SOUTH); frame.add(glCanvas, BorderLayout.CENTER); - break; + break; case BorderCenterSurrounded: frame.setLayout(new BorderLayout()); frame.add(new Button("NORTH"), BorderLayout.NORTH); @@ -191,7 +199,7 @@ public class TestGearsES2AWT extends UITestCase { c.add(new Button("east"), BorderLayout.EAST); c.add(new Button("west"), BorderLayout.WEST); c.add(glCanvas, BorderLayout.CENTER); - + frame.setLayout(new BorderLayout()); frame.add(new Button("NORTH"), BorderLayout.NORTH); frame.add(new Button("SOUTH"), BorderLayout.SOUTH); @@ -200,11 +208,29 @@ public class TestGearsES2AWT extends UITestCase { frame.add(c, BorderLayout.CENTER); break; } - frame.setTitle("Gears AWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval); + setTitle(frame, glCanvas, caps); + + frame.addComponentListener(new ComponentListener() { + @Override + public void componentResized(ComponentEvent e) { + setTitle(frame, glCanvas, caps); + } + + @Override + public void componentMoved(ComponentEvent e) { + setTitle(frame, glCanvas, caps); + } + + @Override + public void componentShown(ComponentEvent e) { } + + @Override + public void componentHidden(ComponentEvent e) { } + }); final GearsES2 demo = new GearsES2(swapInterval); glCanvas.addGLEventListener(demo); - + final SnapshotGLEventListener snap = new SnapshotGLEventListener(); glCanvas.addGLEventListener(snap); @@ -222,13 +248,13 @@ public class TestGearsES2AWT extends UITestCase { if( ResizeBy.Frame == resizeBy ) { frame.validate(); } else { - frame.pack(); - } + frame.pack(); + } frame.setVisible(true); - }}); + }}); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); - Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); - + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas, true)); + if( useAnimator ) { animator.start(); Assert.assertTrue(animator.isStarted()); @@ -236,19 +262,19 @@ public class TestGearsES2AWT extends UITestCase { Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); animator.setUpdateFPSFrames(60, System.err); } - + System.err.println("canvas pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getSurfaceWidth()+"x"+glCanvas.getSurfaceHeight()); snap.setMakeSnapshot(); - + if( null != rwsize ) { - Thread.sleep(500); // 500ms delay + Thread.sleep(500); // 500ms delay setSize(resizeBy, frame, true, glCanvas, rwsize); System.err.println("window resize pos/siz: "+glCanvas.getX()+"/"+glCanvas.getY()+" "+glCanvas.getSurfaceWidth()+"x"+glCanvas.getSurfaceHeight()); } - + snap.setMakeSnapshot(); - + final long t0 = System.currentTimeMillis(); long t1 = t0; while(!quitAdapter.shouldQuit() && t1 - t0 < duration) { @@ -258,7 +284,7 @@ public class TestGearsES2AWT extends UITestCase { Assert.assertNotNull(frame); Assert.assertNotNull(glCanvas); - + if( useAnimator ) { Assert.assertNotNull(animator); Assert.assertEquals(exclusiveContext ? awtEDT : null, glCanvas.getExclusiveContextThread()); @@ -317,7 +343,7 @@ public class TestGearsES2AWT extends UITestCase { @Test public void test02_GLES2() throws InterruptedException, InvocationTargetException { if(mainRun) return; - + if( !GLProfile.isAvailable(GLProfile.GLES2) ) { System.err.println("GLES2 n/a"); return; @@ -326,11 +352,11 @@ public class TestGearsES2AWT extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); runTestGL(caps, resizeBy, frameLayout); } - + @Test public void test03_GL3() throws InterruptedException, InvocationTargetException { if(mainRun) return; - + if( !GLProfile.isAvailable(GLProfile.GL3) ) { System.err.println("GL3 n/a"); return; @@ -339,16 +365,28 @@ public class TestGearsES2AWT extends UITestCase { final GLCapabilities caps = new GLCapabilities( glp ); runTestGL(caps, resizeBy, frameLayout); } - + public static void main(String args[]) { boolean waitForKey = false; int rw=-1, rh=-1; - + mainRun = true; for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; duration = MiscUtils.atol(args[i], duration); + } else if(args[i].equals("-width")) { + i++; + width = MiscUtils.atoi(args[i], width); + } else if(args[i].equals("-height")) { + i++; + height = MiscUtils.atoi(args[i], height); + } else if(args[i].equals("-x")) { + i++; + xpos = MiscUtils.atoi(args[i], xpos); + } else if(args[i].equals("-y")) { + i++; + ypos = MiscUtils.atoi(args[i], ypos); } else if(args[i].equals("-rwidth")) { i++; rw = MiscUtils.atoi(args[i], rw); @@ -396,7 +434,7 @@ public class TestGearsES2AWT extends UITestCase { if( 0 < rw && 0 < rh ) { rwsize = new Dimension(rw, rh); } - + System.err.println("resize "+rwsize); System.err.println("frameLayout "+frameLayout); System.err.println("resizeBy "+resizeBy); @@ -406,10 +444,10 @@ public class TestGearsES2AWT extends UITestCase { System.err.println("exclusiveContext "+exclusiveContext); System.err.println("useMSAA "+useMSAA); System.err.println("useAnimator "+useAnimator); - + System.err.println("shallUseOffscreenFBOLayer "+shallUseOffscreenFBOLayer); System.err.println("shallUseOffscreenPBufferLayer "+shallUseOffscreenPBufferLayer); - + if(waitForKey) { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.err.println("Press enter to continue"); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java index 55616c15f..29750973a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java @@ -31,9 +31,12 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.awt; import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Dimension; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.lang.reflect.InvocationTargetException; import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLProfile; import javax.media.opengl.awt.GLJPanel; import javax.swing.JFrame; @@ -71,6 +74,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { static boolean useAnimator = true; static boolean manualTest = false; static boolean skipGLOrientationVerticalFlip = false; + static int xpos = 10, ypos = 10; @BeforeClass public static void initClass() { @@ -98,7 +102,13 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } } - protected void runTestGL(GLCapabilities caps) + private void setTitle(final JFrame frame, final GLJPanel glc, final GLCapabilitiesImmutable caps) { + final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; + final java.awt.Rectangle b = glc.getBounds(); + frame.setTitle("GLJPanel["+capsA+"], swapI "+swapInterval+", win: ["+b.x+"/"+b.y+" "+b.width+"x"+b.height+"], pix: "+glc.getSurfaceWidth()+"x"+glc.getSurfaceHeight()); + } + + protected void runTestGL(final GLCapabilities caps) throws AWTException, InterruptedException, InvocationTargetException { final JFrame frame = new JFrame("Swing GLJPanel"); @@ -121,6 +131,26 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } final SnapshotGLEventListener snap = new SnapshotGLEventListener(); glJPanel.addGLEventListener(snap); + setTitle(frame, glJPanel, caps); + frame.setLocation(xpos, ypos); + + frame.addComponentListener(new ComponentListener() { + @Override + public void componentResized(ComponentEvent e) { + setTitle(frame, glJPanel, caps); + } + + @Override + public void componentMoved(ComponentEvent e) { + setTitle(frame, glJPanel, caps); + } + + @Override + public void componentShown(ComponentEvent e) { } + + @Override + public void componentHidden(ComponentEvent e) { } + }); final FPSAnimator animator = useAnimator ? new FPSAnimator(glJPanel, 60) : null; @@ -333,6 +363,12 @@ public class TestGearsES2GLJPanelAWT extends UITestCase { } else if(args[i].equals("-height")) { i++; h = MiscUtils.atoi(args[i], h); + } else if(args[i].equals("-x")) { + i++; + xpos = MiscUtils.atoi(args[i], xpos); + } else if(args[i].equals("-y")) { + i++; + ypos = MiscUtils.atoi(args[i], ypos); } else if(args[i].equals("-rwidth")) { i++; rw = MiscUtils.atoi(args[i], rw); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index a96bb1973..bc6b5e26f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -117,13 +117,16 @@ public class TestGearsES2NEWT extends UITestCase { public static void releaseClass() { } - protected void runTestGL(GLCapabilitiesImmutable caps, boolean undecorated) throws InterruptedException { + private void setTitle(final Window win, final GLCapabilitiesImmutable caps) { + final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl"; + win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceBounds()); + } + protected void runTestGL(final GLCapabilitiesImmutable caps, boolean undecorated) throws InterruptedException { System.err.println("requested: vsync "+swapInterval+", "+caps); Display dpy = NewtFactory.createDisplay(null); Screen screen = NewtFactory.createScreen(dpy, screenIdx); final GLWindow glWindow = GLWindow.create(screen, caps); Assert.assertNotNull(glWindow); - glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval+", size "+wsize+", pos "+wpos); glWindow.setSize(wsize.getWidth(), wsize.getHeight()); if(null != wpos) { glWindow.setPosition(wpos.getX(), wpos.getY()); @@ -133,6 +136,7 @@ public class TestGearsES2NEWT extends UITestCase { glWindow.setFullscreen(fullscreen); glWindow.setPointerVisible(mouseVisible); glWindow.confinePointer(mouseConfined); + setTitle(glWindow, caps); final GearsES2 demo = new GearsES2(swapInterval); demo.setPMVUseBackingArray(pmvUseBackingArray); @@ -174,9 +178,11 @@ public class TestGearsES2NEWT extends UITestCase { glWindow.addWindowListener(new WindowAdapter() { public void windowResized(WindowEvent e) { System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); + setTitle(glWindow, caps); } public void windowMoved(WindowEvent e) { System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()); + setTitle(glWindow, caps); } }); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java index 4b5cd0376..50e128b21 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNewtAWTWrapper.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.jogl.demos.gl2.newt; import javax.media.nativewindow.*; @@ -89,28 +89,35 @@ public class TestGearsNewtAWTWrapper extends UITestCase { if( useAnimator ) { animator.start(); } - + int div = 3; glWindow.setSize(width/div, height/div); glWindow.setVisible(true); if( doResizeTest ) { glWindow.display(); - Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glWindow, width/div, height/div)); + final int[] expSurfaceSize = glWindow.getNativeSurface().convertToPixelUnits(new int[] { width/div, height/div }); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1])); Thread.sleep(600); - + div = 2; glWindow.setSize(width/div, height/div); glWindow.display(); - Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glWindow, width/div, height/div)); + expSurfaceSize[0] = width/div; + expSurfaceSize[1] = height/div; + glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1])); Thread.sleep(600); - + div = 1; glWindow.setSize(width/div, height/div); glWindow.display(); - Assert.assertTrue("Size not reached: Expected "+(width/div)+"x"+(height/div)+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(), - AWTRobotUtil.waitForSize(glWindow, width/div, height/div)); + expSurfaceSize[0] = width/div; + expSurfaceSize[1] = height/div; + glWindow.getNativeSurface().convertToPixelUnits(expSurfaceSize); + Assert.assertTrue("Surface Size not reached: Expected "+expSurfaceSize[0]+"x"+expSurfaceSize[1]+", Is "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight(), + AWTRobotUtil.waitForSize(glWindow, expSurfaceSize[0], expSurfaceSize[1])); Thread.sleep(600); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java index 22154ab58..3bc5159a6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java @@ -34,7 +34,7 @@ import com.jogamp.opengl.test.junit.util.*; import java.lang.reflect.InvocationTargetException; import javax.media.nativewindow.NativeWindowFactory; -import javax.media.nativewindow.util.Rectangle; +import javax.media.nativewindow.util.RectangleImmutable; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLProfile; import javax.media.opengl.GLCapabilities; @@ -271,7 +271,7 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { Assert.assertEquals(true, AWTRobotUtil.waitForRealized(win0, true)); Screen screen = win0.getScreen(); - final Rectangle screenBoundsInWinU = screen.getViewportInWindowUnits(win0); + final RectangleImmutable screenBoundsInWinU = screen.getViewportInWindowUnits(); win0.setPosition(screenBoundsInWinU.getX()-150, 0); win0.addGLEventListener(new GearsES2()); Animator anim = new Animator(win0); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java index 8c679d209..0679563b8 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java @@ -34,7 +34,7 @@ import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; -import javax.media.nativewindow.util.Rectangle; +import javax.media.nativewindow.util.RectangleImmutable; import javax.media.opengl.*; import com.jogamp.newt.*; @@ -241,7 +241,7 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { GLWindow window2 = createWindow(caps, width, height); Assert.assertSame(screen, window2.getScreen()); Assert.assertSame(display, window2.getScreen().getDisplay()); - final Rectangle screenBoundsInWinU = screen.getViewportInWindowUnits(window2); + final RectangleImmutable screenBoundsInWinU = screen.getViewportInWindowUnits(); window2.setPosition(screenBoundsInWinU.getWidth()-width, 0); Assert.assertEquals(0,Display.getActiveDisplayNumber()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java index 6bad27384..2987fd389 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -36,6 +36,7 @@ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import javax.media.nativewindow.util.Rectangle; +import javax.media.nativewindow.util.RectangleImmutable; import javax.media.opengl.*; import com.jogamp.opengl.util.Animator; @@ -187,7 +188,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { GLWindow window2 = createWindow(screen, caps, width-10, height-10, true /* onscreen */, false /* undecorated */, true /* vsync */); Assert.assertNotNull(window2); - final Rectangle screenBoundsInWinU = screen.getViewportInWindowUnits(window2); + final RectangleImmutable screenBoundsInWinU = screen.getViewportInWindowUnits(); window2.setPosition(screenBoundsInWinU.getWidth()-width, 0); Animator animator = new Animator(); @@ -254,7 +255,7 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { Assert.assertNotNull(screen2); GLWindow window2 = createWindow(screen2, caps, width-10, height-10, true /* onscreen */, false /* undecorated */, true /* vsync */); Assert.assertNotNull(window2); - final Rectangle screen2BoundsInWinU = screen2.getViewportInWindowUnits(window2); + final RectangleImmutable screen2BoundsInWinU = screen2.getViewportInWindowUnits(); window2.setPosition(screen2BoundsInWinU.getWidth()-width, 0); Animator animator = new Animator(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java index 464efa5bb..ee71ba93d 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.newt.mm; import java.io.IOException; @@ -47,13 +47,13 @@ import java.util.List; import javax.media.nativewindow.util.Dimension; /** - * Manual testing the ScreenImpl shutdown hook, + * Manual testing the ScreenImpl shutdown hook, * which shall reset the ScreenMode to it's original state * when the application exists (normal or ctrl-c). */ public class ManualScreenMode03aNEWT extends UITestCase { static int waitTime = 7000; // 1 sec - + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { caps.setOnscreen(onscreen); @@ -73,28 +73,27 @@ public class ManualScreenMode03aNEWT extends UITestCase { Screen screen = NewtFactory.createScreen(display, 0); // screen 0 GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); - List<MonitorMode> monitorModes = screen.getMonitorModes(); - if(null==monitorModes) { - // no support .. - System.err.println("Your platform has no ScreenMode change support, sorry"); - return; - } Animator animator = new Animator(window); animator.start(); MonitorDevice monitor = window.getMainMonitor(); + MonitorMode mmCurrent = monitor.queryCurrentMode(); MonitorMode mmOrig = monitor.getOriginalMode(); System.err.println("[0] orig : "+mmOrig); System.err.println("[0] current: "+mmCurrent); - + List<MonitorMode> monitorModes = monitor.getSupportedModes(); + if(null==monitorModes) { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + return; + } monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0); monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601)); monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate()); monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes); - - MonitorMode mm = (MonitorMode) monitorModes.get(0); + MonitorMode mm = monitorModes.get(0); System.err.println("[0] set current: "+mm); monitor.setCurrentMode(mm); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java index 93e005b53..c00f02e7e 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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.opengl.test.junit.newt.mm; import java.io.IOException; @@ -68,11 +68,11 @@ import jogamp.newt.MonitorModeProps; public class TestScreenMode00aNEWT extends UITestCase { static int screenIdx = 0; static int width, height; - + static int waitTimeShort = 4; //1 sec static int waitTimeLong = 6; //6 sec - - + + @BeforeClass public static void initClass() { @@ -88,38 +88,39 @@ public class TestScreenMode00aNEWT extends UITestCase { final DimensionImmutable res = new Dimension(640, 480); final SurfaceSize surfsz = new SurfaceSize(res, 32); final MonitorMode modeOut = new MonitorMode(surfsz, 60.0f, 0, 0); - System.err.println("00 out: "+modeOut); - final MonitorModeProps.Cache cache = new MonitorModeProps.Cache(); + System.err.println("00 out: "+modeOut); + final MonitorModeProps.Cache cache = new MonitorModeProps.Cache(); cache.monitorModes.add(modeOut); { final int[] props = MonitorModeProps.streamOutMonitorMode(modeOut); final MonitorMode modeIn = MonitorModeProps.streamInMonitorMode(null, cache, props, 0); System.err.println("00 in : "+modeIn); - + Assert.assertEquals(modeOut.getSurfaceSize().getResolution(), modeIn.getSurfaceSize().getResolution()); - + Assert.assertEquals(modeOut.getSurfaceSize(), modeIn.getSurfaceSize()); - + Assert.assertEquals(modeOut.hashCode(), modeIn.hashCode()); - - Assert.assertEquals(modeOut, modeIn); + + Assert.assertEquals(modeOut, modeIn); } - + final DimensionImmutable sizeMM = new Dimension(50, 50); final Rectangle viewport = new Rectangle(0, 0, 1920, 1080); final ArrayHashSet<MonitorMode> supportedModes = new ArrayHashSet<MonitorMode>(); supportedModes.add(modeOut); - final MonitorDevice monOut = new MonitorDeviceImpl(null, -1, sizeMM, viewport, modeOut, supportedModes); + final MonitorDevice monOut = new MonitorDeviceImpl(null, -1, sizeMM, viewport, viewport, modeOut, supportedModes); System.err.println("01 out : "+monOut); cache.monitorDevices.add(monOut); { final int[] props = MonitorModeProps.streamOutMonitorDevice(monOut); final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(null, cache, null, props, 0); System.err.println("01 in : "+monIn); - - Assert.assertEquals(monOut.getCurrentMode(), monOut.getOriginalMode()); + + Assert.assertEquals(monOut.getCurrentMode(), monOut.getOriginalMode()); Assert.assertEquals(monOut.getSupportedModes(), monIn.getSupportedModes()); Assert.assertEquals(monOut.getViewport(), monIn.getViewport()); + Assert.assertEquals(monOut.getViewportInWindowUnits(), monIn.getViewportInWindowUnits()); Assert.assertEquals(monOut.getOriginalMode(), monIn.getOriginalMode()); Assert.assertEquals(monOut.getCurrentMode(), monIn.getCurrentMode()); Assert.assertEquals(monOut.hashCode(), monIn.hashCode()); @@ -162,7 +163,7 @@ public class TestScreenMode00aNEWT extends UITestCase { mmPre = mm; } } - + List<MonitorDevice> monitors = screen.getMonitorDevices(); Assert.assertTrue(monitors.size()>0); int j=0; @@ -184,7 +185,7 @@ public class TestScreenMode00aNEWT extends UITestCase { Assert.assertTrue(allMonitorModes.containsAll(modes)); MonitorMode sm_o = monitor.getOriginalMode(); - Assert.assertNotNull(sm_o); + Assert.assertNotNull(sm_o); MonitorMode sm_c = monitor.queryCurrentMode(); System.err.println("[0] orig : "+sm_o); System.err.println("[0] current: "+sm_c); @@ -203,7 +204,7 @@ public class TestScreenMode00aNEWT extends UITestCase { return Integer.parseInt(a); } catch (Exception ex) { throw new RuntimeException(ex); } } - + public static void main(String args[]) throws IOException { for(int i=0; i<args.length; i++) { if(args[i].equals("-screen")) { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java index de856e569..3a5e96880 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,15 +20,16 @@ * 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.opengl.test.junit.newt.mm; import java.io.IOException; + import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -56,6 +57,7 @@ import java.util.List; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.Rectangle; /** * Tests X11 XRandR MonitorMode reset via {@link UITestCase#resetXRandRIfX11()}. @@ -65,10 +67,13 @@ public class TestScreenMode00cNEWT extends UITestCase { static boolean manualTest = false; static GLProfile glp; static int width, height; - + static final int waitTimeShort = 2000; static long duration = waitTimeShort; + static int mm_width = 800; + static int mm_height = 600; + @BeforeClass public static void initClass() { setResetXRandRIfX11AfterClass(); @@ -86,7 +91,7 @@ public class TestScreenMode00cNEWT extends UITestCase { public static void releaseClass() throws InterruptedException { Thread.sleep(waitTimeShort); } - + static Window createWindow(Screen screen, GLCapabilities caps, String name, int x, int y, int width, int height) { Assert.assertNotNull(caps); @@ -107,7 +112,7 @@ public class TestScreenMode00cNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false)); } } - + @Test public void testScreenModeChange01() throws InterruptedException { Thread.sleep(waitTimeShort); @@ -119,7 +124,13 @@ public class TestScreenMode00cNEWT extends UITestCase { final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 Assert.assertNotNull(screen); final Window window0 = createWindow(screen, caps, "win0", 0, 0, width, height); - Assert.assertNotNull(window0); + Assert.assertNotNull(window0); + + Rectangle window0WindowBounds = window0.getBounds(); + Rectangle window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.0: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Window bounds : "+window0SurfaceBounds+" [pixels]"); + System.err.println("Test.0: Screen viewport : "+screen.getViewport()+" [pixels]"); final List<MonitorMode> allMonitorModes = screen.getMonitorModes(); Assert.assertTrue(allMonitorModes.size()>0); @@ -131,7 +142,6 @@ public class TestScreenMode00cNEWT extends UITestCase { } final MonitorDevice monitor = screen.getMonitorDevices().get(0); - List<MonitorMode> monitorModes = monitor.getSupportedModes(); Assert.assertTrue(monitorModes.size()>0); if(monitorModes.size()==1) { @@ -141,7 +151,7 @@ public class TestScreenMode00cNEWT extends UITestCase { return; } Assert.assertTrue(allMonitorModes.containsAll(monitorModes)); - + final MonitorMode mmSet0 = monitor.queryCurrentMode(); Assert.assertNotNull(mmSet0); final MonitorMode mmOrig = monitor.getOriginalMode(); @@ -149,7 +159,7 @@ public class TestScreenMode00cNEWT extends UITestCase { System.err.println("[0] orig : "+mmOrig); System.err.println("[0] current: "+mmSet0); Assert.assertEquals(mmSet0, mmOrig); - + monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc Assert.assertNotNull(monitorModes); @@ -157,13 +167,13 @@ public class TestScreenMode00cNEWT extends UITestCase { monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0); Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); - monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601)); + monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(mm_width+1, mm_height+1)); Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate()); - Assert.assertNotNull(monitorModes); + Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); - + monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes); Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); @@ -171,14 +181,24 @@ public class TestScreenMode00cNEWT extends UITestCase { // set mode { MonitorMode mm = monitorModes.get(0); - System.err.println("[0] set current: "+mm); + System.err.println("[1] set current: "+mm); final boolean smOk = monitor.setCurrentMode(mm); - MonitorMode mmCurrent = monitor.getCurrentMode(); - System.err.println("[0] has current: "+mmCurrent+", changeOK "+smOk); + MonitorMode mmCachedCurrent = monitor.getCurrentMode(); + MonitorMode mmQueriedCurrent = monitor.queryCurrentMode(); + boolean mmCurrentEquals = mmQueriedCurrent.equals(mmCachedCurrent); + System.err.println("[1] changeOK : "+smOk); + System.err.println("[1] has current cached : "+mmCachedCurrent); + System.err.println("[1] has current queried : "+mmQueriedCurrent+", equal "+mmCurrentEquals); + window0WindowBounds = window0.getBounds(); + window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.1: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.1: Window bounds : "+window0SurfaceBounds+" [pixels]"); + System.err.println("Test.1: Screen viewport : "+screen.getViewport()+" [pixels]"); + Assert.assertTrue(monitor.isModeChangedByUs()); - Assert.assertEquals(mm, mmCurrent); - Assert.assertNotSame(mmOrig, mmCurrent); - Assert.assertEquals(mmCurrent, monitor.queryCurrentMode()); + Assert.assertEquals(mm, mmCachedCurrent); + Assert.assertNotSame(mmOrig, mmCachedCurrent); + Assert.assertEquals(mmCachedCurrent, mmQueriedCurrent); Assert.assertTrue(smOk); } @@ -193,13 +213,13 @@ public class TestScreenMode00cNEWT extends UITestCase { UITestCase.resetXRandRIfX11(); System.err.println("XRandR Reset :"+monitor.queryCurrentMode()); validateScreenModeReset0(mmOrig); - + destroyWindow(window0); Thread.sleep(waitTimeShort); validateScreenModeReset(mmOrig); } - + void validateScreenModeReset0(final MonitorMode mmOrig) { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); @@ -208,10 +228,10 @@ public class TestScreenMode00cNEWT extends UITestCase { screen.addReference(); Assert.assertEquals(true,display.isNativeValid()); Assert.assertEquals(true,screen.isNativeValid()); - + final MonitorDevice monitor = screen.getMonitorDevices().get(0); Assert.assertEquals(mmOrig, monitor.queryCurrentMode()); - + screen.removeReference(); } void validateScreenModeReset(final MonitorMode mmOrig) { @@ -224,10 +244,10 @@ public class TestScreenMode00cNEWT extends UITestCase { screen.addReference(); Assert.assertEquals(true,display.isNativeValid()); Assert.assertEquals(true,screen.isNativeValid()); - + final MonitorDevice monitor = screen.getMonitorDevices().get(0); Assert.assertEquals(mmOrig, monitor.getCurrentMode()); - + screen.removeReference(); Assert.assertEquals(false,display.isNativeValid()); Assert.assertEquals(false,screen.isNativeValid()); @@ -239,8 +259,15 @@ public class TestScreenMode00cNEWT extends UITestCase { if(args[i].equals("-time")) { i++; duration = MiscUtils.atol(args[i], duration); + } else if(args[i].equals("-mwidth")) { + i++; + mm_width = MiscUtils.atoi(args[i], mm_width); + } else if(args[i].equals("-mheight")) { + i++; + mm_height = MiscUtils.atoi(args[i], mm_height); } } + System.err.println("Desired mode w/ resolution "+mm_width+"x"+mm_height); String tstname = TestScreenMode00cNEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java index 0f3dbeefc..808571d05 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,15 +20,16 @@ * 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.opengl.test.junit.newt.mm; import java.io.IOException; + import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -49,10 +50,13 @@ import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.util.MonitorModeUtil; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.UITestCase; import java.util.List; + import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.Rectangle; /** * <p> @@ -62,16 +66,19 @@ import javax.media.nativewindow.util.Dimension; * <p> * Documents remedy B) for NV RANDR/GL bug * </p> - * + * * @see TestScreenMode01dNEWT#cleanupGL() */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestScreenMode01aNEWT extends UITestCase { static GLProfile glp; static int width, height; - - static int waitTimeShort = 2000; - static int waitTimeLong = 2000; + + static long waitTimeShort = 2000; + static long duration = 2000; + + static int mm_width = 800; + static int mm_height = 600; @BeforeClass public static void initClass() { @@ -85,7 +92,7 @@ public class TestScreenMode01aNEWT extends UITestCase { public static void releaseClass() throws InterruptedException { Thread.sleep(waitTimeShort); } - + static Window createWindow(Screen screen, GLCapabilities caps, String name, int x, int y, int width, int height) { Assert.assertNotNull(caps); @@ -106,7 +113,7 @@ public class TestScreenMode01aNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false)); } } - + @Test public void testScreenModeChange01() throws InterruptedException { Thread.sleep(waitTimeShort); @@ -118,7 +125,16 @@ public class TestScreenMode01aNEWT extends UITestCase { final Screen screen = NewtFactory.createScreen(display, 0); // screen 0 Assert.assertNotNull(screen); final Window window0 = createWindow(screen, caps, "win0", 0, 0, width, height); - Assert.assertNotNull(window0); + Assert.assertNotNull(window0); + + final MonitorDevice monitor = screen.getMonitorDevices().get(0); + + Rectangle window0WindowBounds = window0.getBounds(); + Rectangle window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.0: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Window bounds : "+window0SurfaceBounds+" [pixels]"); + System.err.println("Test.0: Screen viewport : "+screen.getViewport()+" [pixels], "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); final List<MonitorMode> allMonitorModes = screen.getMonitorModes(); Assert.assertTrue(allMonitorModes.size()>0); @@ -129,8 +145,6 @@ public class TestScreenMode01aNEWT extends UITestCase { return; } - final MonitorDevice monitor = screen.getMonitorDevices().get(0); - List<MonitorMode> monitorModes = monitor.getSupportedModes(); Assert.assertTrue(monitorModes.size()>0); if(monitorModes.size()==1) { @@ -140,7 +154,7 @@ public class TestScreenMode01aNEWT extends UITestCase { return; } Assert.assertTrue(allMonitorModes.containsAll(monitorModes)); - + final MonitorMode mmSet0 = monitor.queryCurrentMode(); Assert.assertNotNull(mmSet0); final MonitorMode mmOrig = monitor.getOriginalMode(); @@ -148,7 +162,7 @@ public class TestScreenMode01aNEWT extends UITestCase { System.err.println("[0] orig : "+mmOrig); System.err.println("[0] current: "+mmSet0); Assert.assertEquals(mmSet0, mmOrig); - + monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc Assert.assertNotNull(monitorModes); @@ -156,13 +170,13 @@ public class TestScreenMode01aNEWT extends UITestCase { monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0); Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); - monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601)); + monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(mm_width+1, mm_height+1)); Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate()); - Assert.assertNotNull(monitorModes); + Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); - + monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes); Assert.assertNotNull(monitorModes); Assert.assertTrue(monitorModes.size()>0); @@ -170,18 +184,29 @@ public class TestScreenMode01aNEWT extends UITestCase { // set mode { MonitorMode mm = monitorModes.get(0); - System.err.println("[0] set current: "+mm); + System.err.println("[1] set current: "+mm); final boolean smOk = monitor.setCurrentMode(mm); - MonitorMode mmCurrent = monitor.getCurrentMode(); - System.err.println("[0] has current: "+mmCurrent+", changeOK "+smOk); + MonitorMode mmCachedCurrent = monitor.getCurrentMode(); + MonitorMode mmQueriedCurrent = monitor.queryCurrentMode(); + boolean mmCurrentEquals = mmQueriedCurrent.equals(mmCachedCurrent); + System.err.println("[1] changeOK : "+smOk); + System.err.println("[1] has current cached : "+mmCachedCurrent); + System.err.println("[1] has current queried : "+mmQueriedCurrent+", equal "+mmCurrentEquals); + window0WindowBounds = window0.getBounds(); + window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.1: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.1: Window bounds : "+window0SurfaceBounds+" [pixels]"); + System.err.println("Test.1: Screen viewport : "+screen.getViewport()+" [pixels], "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.1: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); + Assert.assertTrue(monitor.isModeChangedByUs()); - Assert.assertEquals(mm, mmCurrent); - Assert.assertNotSame(mmOrig, mmCurrent); - Assert.assertEquals(mmCurrent, monitor.queryCurrentMode()); + Assert.assertEquals(mm, mmCachedCurrent); + Assert.assertNotSame(mmOrig, mmCachedCurrent); + Assert.assertEquals(mmCachedCurrent, monitor.queryCurrentMode()); Assert.assertTrue(smOk); } - Thread.sleep(waitTimeShort); + Thread.sleep(duration); Assert.assertEquals(true,display.isNativeValid()); Assert.assertEquals(true,screen.isNativeValid()); @@ -196,12 +221,12 @@ public class TestScreenMode01aNEWT extends UITestCase { Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false)); Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(false,display.isNativeValid()); - + Thread.sleep(waitTimeShort); - + validateScreenModeReset(mmOrig, 0); } - + void validateScreenModeReset(final MonitorMode mmOrig, int mmIdx) { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); @@ -212,16 +237,29 @@ public class TestScreenMode01aNEWT extends UITestCase { screen.addReference(); Assert.assertEquals(true,display.isNativeValid()); Assert.assertEquals(true,screen.isNativeValid()); - + final MonitorDevice monitor = screen.getMonitorDevices().get(0); Assert.assertEquals(mmOrig, monitor.getCurrentMode()); - + screen.removeReference(); Assert.assertEquals(false,display.isNativeValid()); Assert.assertEquals(false,screen.isNativeValid()); } public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } else if(args[i].equals("-mwidth")) { + i++; + mm_width = MiscUtils.atoi(args[i], mm_width); + } else if(args[i].equals("-mheight")) { + i++; + mm_height = MiscUtils.atoi(args[i], mm_height); + } + } + System.err.println("Desired mode w/ resolution "+mm_width+"x"+mm_height); String tstname = TestScreenMode01aNEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java index ac5e7e53c..6bf9831dc 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java @@ -156,9 +156,10 @@ public class TestScreenMode01bNEWT extends UITestCase { GLWindow window0 = createWindow(screen, caps, "win0", screenXPos, screenYPos, width, height); Assert.assertNotNull(window0); - Rectangle window0ScreenRect = window0.getSurfaceBounds(); - System.err.println("Test.0: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWindowWidth()+"x"+window0.getWindowHeight()+" [wu] within "+screen.getViewportInWindowUnits(window0)+" [wu]"); - System.err.println("Test.0: Window screenRect: "+window0ScreenRect+" [pixels]"); + Rectangle window0WindowBounds = window0.getBounds(); + Rectangle window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.0: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Window bounds : "+window0SurfaceBounds+" [pixels]"); final Animator anim = new Animator(window0); anim.start(); @@ -224,12 +225,13 @@ public class TestScreenMode01bNEWT extends UITestCase { Assert.assertTrue(smOk); } - window0ScreenRect = window0.getSurfaceBounds(); + window0WindowBounds = window0.getBounds(); + window0SurfaceBounds = window0.getSurfaceBounds(); System.err.println("Test.1: Screen : "+screen); - System.err.println("Test.1: Window bounds : "+window0.getX()+"/"+window0.getY()+" "+window0.getWindowWidth()+"x"+window0.getWindowHeight()+" [wu] within "+screen.getViewportInWindowUnits(window0)+" [wu]"); - System.err.println("Test.1: Window screenRect: "+window0ScreenRect+" [pixels]"); + System.err.println("Test.1: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.1: Window bounds : "+window0SurfaceBounds+" [pixels]"); System.err.println("Test.1: Screen viewport : "+screen.getViewport()+" [pixels]"); - System.err.println("Test.1: Window monitor : "+monitor.getViewport()+" [pixels]"); + System.err.println("Test.1: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); System.err.println("Test.1: Window main-mon : "+window0.getMainMonitor()); Thread.sleep(duration); @@ -250,11 +252,13 @@ public class TestScreenMode01bNEWT extends UITestCase { Assert.assertTrue(smOk); } + window0WindowBounds = window0.getBounds(); + window0SurfaceBounds = window0.getSurfaceBounds(); System.err.println("Test.2: Screen : "+screen); - System.err.println("Test.2: Window bounds : "+window0.getX()+"/"+window0.getY()+" "+window0.getWindowWidth()+"x"+window0.getWindowHeight()+" [wu] within "+screen.getViewportInWindowUnits(window0)+" [wu]"); - System.err.println("Test.2: Window screenRect: "+window0ScreenRect+" [pixels]"); + System.err.println("Test.2: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.2: Window bounds : "+window0SurfaceBounds+" [pixels]"); System.err.println("Test.2: Screen viewport : "+screen.getViewport()+" [pixels]"); - System.err.println("Test.2: Window monitor : "+monitor.getViewport()+" [pixels]"); + System.err.println("Test.2: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); System.err.println("Test.2: Window main-mon : "+window0.getMainMonitor()); Thread.sleep(duration); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java index b48d582ed..986f92273 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java @@ -103,7 +103,7 @@ public class TestScreenMode01cNEWT extends UITestCase { static void destroyWindow(Window window) throws InterruptedException { if(null!=window) { window.destroy(); - Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false)); + AWTRobotUtil.waitForRealized(window, false); // don't override a previous assertion failure } } @@ -119,7 +119,7 @@ public class TestScreenMode01cNEWT extends UITestCase { testScreenFullscreenImpl(screen, monitorVp.getX(), monitorVp.getY(), false, null); } finally { screen.removeReference(); - Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false)); + AWTRobotUtil.waitForRealized(screen, false); // don't override a previous assertion failure } } @@ -139,7 +139,7 @@ public class TestScreenMode01cNEWT extends UITestCase { testScreenFullscreenImpl(screen, monitorVp.getX(), monitorVp.getY(), false, null); } finally { screen.removeReference(); - Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false)); + AWTRobotUtil.waitForRealized(screen, false); // don't override a previous assertion failure } } @@ -151,9 +151,8 @@ public class TestScreenMode01cNEWT extends UITestCase { Assert.assertNotNull(screen); screen.addReference(); // trigger creation try { - final int crtCount = screen.getMonitorDevices().size(); - if( 2 >= crtCount ) { - System.err.println("Test Disabled (2): Spanning monitor count "+2+" >= screen monitor count: "+screen); + if( 2 > screen.getMonitorDevices().size() ) { + System.err.println("Test Disabled (2): Spanning monitor count < 2: "+screen); return; } final ArrayList<MonitorDevice> monitors = new ArrayList<MonitorDevice>(); @@ -163,7 +162,7 @@ public class TestScreenMode01cNEWT extends UITestCase { testScreenFullscreenImpl(screen, monitorVp.getX()+50, monitorVp.getY()+50, true, monitors); } finally { screen.removeReference(); - Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false)); + AWTRobotUtil.waitForRealized(screen, false); // don't override a previous assertion failure } } @@ -183,7 +182,7 @@ public class TestScreenMode01cNEWT extends UITestCase { testScreenFullscreenImpl(screen, monitorVp.getX()-50, monitorVp.getY()+50, true, null); } finally { screen.removeReference(); - Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false)); + AWTRobotUtil.waitForRealized(screen, false); // don't override a previous assertion failure } } @@ -201,9 +200,10 @@ public class TestScreenMode01cNEWT extends UITestCase { GLWindow window0 = createWindow(screen, caps, "win0", screenXPos, screenYPos, width, height); Assert.assertNotNull(window0); - Rectangle window0ScreenRect = window0.getSurfaceBounds(); - System.err.println("Test.0: Window bounds : "+window0.getX()+"/"+window0.getY()+" "+window0.getWindowWidth()+"x"+window0.getWindowHeight()+" [wu] within "+screen.getViewportInWindowUnits(window0)+" [wu]"); - System.err.println("Test.0: Window screenRect: "+window0ScreenRect+" [pixels]"); + Rectangle window0WindowBounds = window0.getBounds(); + Rectangle window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.0: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.0: Window bounds : "+window0SurfaceBounds+" [pixels]"); System.err.println("Test.0: Screen viewport : "+screen.getViewport()+" [pixels]"); final Animator anim = new Animator(window0); @@ -221,32 +221,35 @@ public class TestScreenMode01cNEWT extends UITestCase { } monitor = window0.getMainMonitor(); - window0ScreenRect = window0.getSurfaceBounds(); - System.err.println("Test.1: Window bounds : "+window0.getX()+"/"+window0.getY()+" "+window0.getWindowWidth()+"x"+window0.getWindowHeight()+" [wu] within "+screen.getViewportInWindowUnits(window0)+" [wu]"); - System.err.println("Test.1: Window screenRect: "+window0ScreenRect+" [pixels]"); + window0WindowBounds = window0.getBounds(); + window0SurfaceBounds = window0.getSurfaceBounds(); + System.err.println("Test.1: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.1: Window bounds : "+window0SurfaceBounds+" [pixels]"); System.err.println("Test.1: Screen viewport : "+screen.getViewport()+" [pixels]"); - System.err.println("Test.1: Window monitor : "+monitor.getViewport()+" [pixels]"); + System.err.println("Test.1: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); if( !spanAcrossMonitors ) { - Assert.assertEquals(monitor.getViewport(), window0ScreenRect); + Assert.assertEquals(monitor.getViewportInWindowUnits(), window0WindowBounds); } else { List<MonitorDevice> monitorsUsed = monitors; if( null == monitorsUsed ) { monitorsUsed = window0.getScreen().getMonitorDevices(); } - Rectangle monitorsUsedViewport = MonitorDevice.unionOfViewports(new Rectangle(), monitorsUsed); - Assert.assertEquals(monitorsUsedViewport, window0ScreenRect); + Rectangle monitorsUsedViewport = new Rectangle(); + MonitorDevice.unionOfViewports(null, monitorsUsedViewport, monitorsUsed); + Assert.assertEquals(monitorsUsedViewport, window0WindowBounds); } Thread.sleep(duration); window0.setFullscreen(false); - window0ScreenRect = window0.getSurfaceBounds(); + window0WindowBounds = window0.getBounds(); + window0SurfaceBounds = window0.getSurfaceBounds(); monitor = window0.getMainMonitor(); - System.err.println("Test.2: Window bounds : "+window0.getX()+"/"+window0.getY()+" "+window0.getWindowWidth()+"x"+window0.getWindowHeight()+" [wu] within "+screen.getViewportInWindowUnits(window0)+" [wu]"); - System.err.println("Test.2: Window screenRect: "+window0ScreenRect+" [pixels]"); + System.err.println("Test.2: Window bounds : "+window0WindowBounds+" [wu] within "+screen.getViewportInWindowUnits()+" [wu]"); + System.err.println("Test.2: Window bounds : "+window0SurfaceBounds+" [pixels]"); System.err.println("Test.2: Screen viewport : "+screen.getViewport()+" [pixels]"); - System.err.println("Test.2: Window monitor : "+monitor.getViewport()+" [pixels]"); + System.err.println("Test.2: Monitor viewport : "+monitor.getViewport()+" [pixels], "+monitor.getViewportInWindowUnits()+" [wu]"); Thread.sleep(duration); anim.stop(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01dNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01dNEWT.java index d9ea39365..d03306c4f 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01dNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01dNEWT.java @@ -55,7 +55,6 @@ import com.jogamp.opengl.test.junit.util.UITestCase; import java.util.List; import javax.media.nativewindow.util.Dimension; -import javax.media.nativewindow.util.Rectangle; import javax.media.nativewindow.util.RectangleImmutable; /** @@ -164,8 +163,8 @@ public class TestScreenMode01dNEWT extends UITestCase { final MonitorDevice monitor = window.getMainMonitor(); Assert.assertEquals(false, window.isFullscreen()); - Assert.assertEquals(width, window.getSurfaceWidth()); - Assert.assertEquals(height, window.getSurfaceHeight()); + Assert.assertEquals(width, window.getWindowWidth()); + Assert.assertEquals(height, window.getWindowHeight()); window.setFullscreen(true); Assert.assertEquals(true, window.isFullscreen()); @@ -176,8 +175,8 @@ public class TestScreenMode01dNEWT extends UITestCase { window.setFullscreen(false); Assert.assertEquals(false, window.isFullscreen()); - Assert.assertEquals(width, window.getSurfaceWidth()); - Assert.assertEquals(height, window.getSurfaceHeight()); + Assert.assertEquals(width, window.getWindowWidth()); + Assert.assertEquals(height, window.getWindowHeight()); Thread.sleep(waitTimeShort); @@ -210,8 +209,8 @@ public class TestScreenMode01dNEWT extends UITestCase { GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */); Assert.assertNotNull(window); - final RectangleImmutable screenRect = window.getSurfaceBounds(); - final MonitorDevice monitor = screen.getMainMonitor( screenRect ); + final RectangleImmutable winRect = window.getBounds(); + final MonitorDevice monitor = screen.getMainMonitor( winRect ); List<MonitorMode> monitorModes = monitor.getSupportedModes(); Assert.assertTrue(monitorModes.size()>0); @@ -284,7 +283,7 @@ public class TestScreenMode01dNEWT extends UITestCase { Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(false,display.isNativeValid()); - validateScreenModeReset(mmOrig, screenRect); + validateScreenModeReset(mmOrig, winRect); cleanupGL(); } @@ -308,8 +307,8 @@ public class TestScreenMode01dNEWT extends UITestCase { Animator animator = new Animator(window); animator.start(); - final RectangleImmutable screenRect = window.getSurfaceBounds(); - final MonitorDevice monitor = screen.getMainMonitor(screenRect); + final RectangleImmutable winRect = window.getBounds(); + final MonitorDevice monitor = screen.getMainMonitor(winRect); MonitorMode mmCurrent = monitor.queryCurrentMode(); Assert.assertNotNull(mmCurrent); MonitorMode mmOrig = monitor.getOriginalMode(); @@ -335,20 +334,20 @@ public class TestScreenMode01dNEWT extends UITestCase { Assert.assertNotNull(monitorMode); if(preFS) { - System.err.println("[0] set FS pre 0: "+window.isFullscreen()); + System.err.println("[1] set FS pre 0: "+window.isFullscreen()); window.setFullscreen(true); - System.err.println("[0] set FS pre 1: "+window.isFullscreen()); + System.err.println("[1] set FS pre 1: "+window.isFullscreen()); Assert.assertEquals(true, window.isFullscreen()); - System.err.println("[0] set FS pre X: "+window.isFullscreen()); + System.err.println("[1] set FS pre X: "+window.isFullscreen()); } Thread.sleep(waitTimeShort); // set mode { - System.err.println("[0] set current: "+monitorMode); + System.err.println("[2] set current: "+monitorMode); final boolean smOk = monitor.setCurrentMode(monitorMode); mmCurrent = monitor.getCurrentMode(); - System.err.println("[0] has current: "+mmCurrent+", changeOK "+smOk); + System.err.println("[2] has current: "+mmCurrent+", changeOK "+smOk); Assert.assertTrue(monitor.isModeChangedByUs()); Assert.assertEquals(monitorMode, mmCurrent); Assert.assertNotSame(mmOrig, mmCurrent); @@ -357,19 +356,19 @@ public class TestScreenMode01dNEWT extends UITestCase { } if(!preFS) { - System.err.println("[0] set FS post 0: "+window.isFullscreen()); + System.err.println("[3] set FS post 0: "+window.isFullscreen()); window.setFullscreen(true); Assert.assertEquals(true, window.isFullscreen()); - System.err.println("[0] set FS post X: "+window.isFullscreen()); + System.err.println("[3] set FS post X: "+window.isFullscreen()); } Thread.sleep(waitTimeLong); if(!preFS) { - System.err.println("[0] set !FS post 0: "+window.isFullscreen()); + System.err.println("[4] set !FS post 0: "+window.isFullscreen()); window.setFullscreen(false); Assert.assertEquals(false, window.isFullscreen()); - System.err.println("[0] set !FS post X: "+window.isFullscreen()); + System.err.println("[4] set !FS post X: "+window.isFullscreen()); Thread.sleep(waitTimeShort); } @@ -391,10 +390,15 @@ public class TestScreenMode01dNEWT extends UITestCase { Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(false,display.isNativeValid()); - validateScreenModeReset(mmOrig, screenRect); + validateScreenModeReset(mmOrig, winRect); cleanupGL(); } + /** + * + * @param mmOrig + * @param rect in window units + */ void validateScreenModeReset(final MonitorMode mmOrig, final RectangleImmutable rect) { final Display display = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java index 417a1c506..a02a0bac7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java @@ -110,8 +110,8 @@ public class TestParenting02NEWT extends UITestCase { GLWindow glWindow1 = GLWindow.create(window1); Assert.assertNotNull(glWindow1); glWindow1.setSize(width, height); - Assert.assertEquals(width,glWindow1.getSurfaceWidth()); - Assert.assertEquals(height,glWindow1.getSurfaceHeight()); + Assert.assertEquals(width,glWindow1.getWindowWidth()); + Assert.assertEquals(height,glWindow1.getWindowHeight()); glWindow1.setTitle("test01NewtOnNewtParentChildDraw - PARENT"); glWindow1.setPosition(x,y); //glWindow1.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); @@ -134,7 +134,7 @@ public class TestParenting02NEWT extends UITestCase { //Assert.assertEquals(width/2,glWindow2.getWidth()); //Assert.assertEquals(height/2,glWindow2.getHeight()); glWindow2.setTitle("test01NewtOnNewtParentChildDraw - CHILD"); - glWindow2.setPosition(glWindow1.getSurfaceWidth()/2, glWindow1.getSurfaceHeight()/2); + glWindow2.setPosition(glWindow1.getWindowWidth()/2, glWindow1.getWindowHeight()/2); //glWindow2.addKeyListener(new TraceKeyAdapter(new KeyAction(eventFifo))); //glWindow2.addWindowListener(new TraceWindowAdapter(new WindowAction(eventFifo))); // glWindow2.addMouseListener(new TraceMouseAdapter()); @@ -163,7 +163,7 @@ public class TestParenting02NEWT extends UITestCase { x += 1; y += 1; // glWindow1.setPosition(x,y); - glWindow2.setPosition(glWindow1.getSurfaceWidth()/2,glWindow1.getSurfaceHeight()/2-y); + glWindow2.setPosition(glWindow1.getWindowWidth()/2,glWindow1.getWindowHeight()/2-y); Thread.sleep(step); while( null != ( event = eventFifo.get() ) ) { |