diff options
7 files changed, 229 insertions, 27 deletions
diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index d1e011184..7b5d617b5 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -24,14 +24,20 @@ if (_res == null) return null; Buffers.nativeOrder(_res); - XVisualInfo[] _retarray = new XVisualInfo[getFirstElement(arg3, arg3_offset)]; - for (int _count = 0; _count < getFirstElement(arg3, arg3_offset); _count++) { - _res.position(_count * XVisualInfo.size()); - _res.limit ((1 + _count) * XVisualInfo.size()); + final int count = getFirstElement(arg3, arg3_offset); + if (count <= 0) return null; + final int esize = _res.capacity() / count; + if( esize < XVisualInfo.size() ) { + throw new RuntimeException("element-size "+_res.capacity()+"/"+count+"="+esize+" < "+XVisualInfo.size()); + } + XVisualInfo[] _retarray = new XVisualInfo[count]; + for (int i = 0; i < count; i++) { + _res.position(i * esize); // XVisualInfo.size()); + _res.limit ((1 + i) * esize); // XVisualInfo.size()); java.nio.ByteBuffer _tmp = _res.slice(); _res.position(0); _res.limit(_res.capacity()); - _retarray[_count] = XVisualInfo.create(_tmp); + _retarray[i] = XVisualInfo.create(_tmp); } return _retarray; } diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index 66bd19362..0bbe1c420 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -13,6 +13,7 @@ NativeOutputDir gensrc/native/X11 Import java.nio.* Import java.util.* Import com.jogamp.nativewindow.util.Point +Import com.jogamp.common.util.Bitfield # XID needs to be treated as a long for 32/64 bit compatibility Opaque long XID @@ -31,6 +32,7 @@ ReturnValueCapacity XRenderFindVisualFormat sizeof(XRenderPictFormat) # We have Custom code for the following Ignore XGetVisualInfo +Ignore XRenderFindVisualFormat ManuallyImplement XCloseDisplay ManuallyImplement XUnlockDisplay @@ -40,7 +42,12 @@ ManuallyImplement XLockDisplay CustomJavaCode X11Lib private static int getFirstElement(IntBuffer buf) { return buf.get(buf.position()); } CustomJavaCode X11Lib private static int getFirstElement(int[] arr, int offset) { return arr[offset]; } -CustomJavaCode XVisualInfo public static XVisualInfo create(XVisualInfo s) { XVisualInfo d = XVisualInfo.create(); d.getBuffer().put(s.getBuffer()); d.getBuffer().rewind(); s.getBuffer().rewind(); return d; } +CustomJavaCode XVisualInfo public static XVisualInfo create(XVisualInfo s) { final ByteBuffer bb = Buffers.newDirectByteBuffer(s.getBuffer().capacity()); final XVisualInfo d = XVisualInfo.create(bb); d.getBuffer().put(s.getBuffer()); d.getBuffer().rewind(); s.getBuffer().rewind(); return d; } +CustomJavaCode XVisualInfo public String toString() { +CustomJavaCode XVisualInfo return "XVisualInfo[size "+size()+"/"+getBuffer().capacity()+", visual 0x"+Long.toHexString(getVisual())+ +CustomJavaCode XVisualInfo ", visual-id 0x"+Long.toHexString(getVisualid())+", c-class "+getC_class()+", cmap-size "+getColormap_size()+", depth "+getDepth()+ +CustomJavaCode XVisualInfo ", rgb["+Bitfield.Util.bitCount((int)getRed_mask())+", "+Bitfield.Util.bitCount((int)getRed_mask())+", "+Bitfield.Util.bitCount((int)getRed_mask())+" - "+getBits_per_rgb()+"]]"; +CustomJavaCode XVisualInfo } CustomCCode #include <gluegen_stdint.h> CustomCCode #include <gluegen_stddef.h> diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index c2a3a8411..fca77a161 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -571,7 +571,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableFactoryGL2OffscrnCapsNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableFactoryGLnBitmapCapsNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableFactoryES2OffscrnCapsNEWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableFactoryGLProfileDeviceNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableFactoryGLProfileDeviceNEWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLCanvasOnOffscrnCapsAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableGLWindowOnOffscrnCapsNEWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableNewtCanvasAWTOnOffscrnCapsAWT $* @@ -621,6 +621,7 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableFactoryGLPro #testnoawt com.jogamp.opengl.test.junit.newt.TestRemoteGLWindows01NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.TestWindows01NEWT $* +testnoawt com.jogamp.opengl.test.junit.newt.TestWindows02NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.TestWindowClosingProtocol02NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.TestWindowAndPointerIconNEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT $* diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java index 86349b645..8f7d710cd 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXGraphicsConfiguration.java @@ -275,21 +275,6 @@ public class X11GLXGraphicsConfiguration extends X11GraphicsConfiguration implem return val; } - static XRenderDirectFormat XVisual2XRenderMask(final long dpy, final long visual) { - final XRenderPictFormat renderPictFmt = X11Lib.XRenderFindVisualFormat(dpy, visual); - if(null == renderPictFmt) { - return null; - } - return renderPictFmt.getDirect(); - } - static XRenderDirectFormat XVisual2XRenderMask(final long dpy, final long visual, final XRenderPictFormat dest) { - if( !X11Lib.XRenderFindVisualFormat(dpy, visual, dest) ) { - return null; - } else { - return dest.getDirect(); - } - } - static X11GLCapabilities GLXFBConfig2GLCapabilities(final X11GraphicsDevice device, final GLProfile glp, final long fbcfg, final int winattrmask, final boolean isMultisampleAvailable) { final IntBuffer tmp = Buffers.newDirectIntBuffer(1); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java index 04619962d..bcb9741d6 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsConfiguration.java @@ -33,10 +33,15 @@ package com.jogamp.nativewindow.x11; +import com.jogamp.common.util.Bitfield; import com.jogamp.nativewindow.CapabilitiesImmutable; import com.jogamp.nativewindow.MutableGraphicsConfiguration; +import jogamp.nativewindow.x11.X11Capabilities; +import jogamp.nativewindow.x11.X11Lib; +import jogamp.nativewindow.x11.XRenderDirectFormat; +import jogamp.nativewindow.x11.XRenderPictFormat; import jogamp.nativewindow.x11.XVisualInfo; /** Encapsulates a graphics configuration, or OpenGL pixel format, on @@ -48,6 +53,44 @@ import jogamp.nativewindow.x11.XVisualInfo; public class X11GraphicsConfiguration extends MutableGraphicsConfiguration implements Cloneable { private XVisualInfo info; + // FBConfig + + protected static XRenderDirectFormat XVisual2XRenderMask(final long dpy, final long visual) { + final XRenderPictFormat xRenderPictFormat = XRenderPictFormat.create(); + return XVisual2XRenderMask(dpy, visual, xRenderPictFormat); + } + protected static XRenderDirectFormat XVisual2XRenderMask(final long dpy, final long visual, final XRenderPictFormat dest) { + if( !X11Lib.XRenderFindVisualFormat(dpy, visual, dest) ) { + return null; + } else { + return dest.getDirect(); + } + } + + public static X11Capabilities XVisualInfo2X11Capabilities(final X11GraphicsDevice device, final XVisualInfo info) { + final long display = device.getHandle(); + final X11Capabilities res = new X11Capabilities(info); + + final XRenderDirectFormat xrmask = ( null != info ) ? XVisual2XRenderMask( display, info.getVisual() ) : null ; + final int alphaMask = ( null != xrmask ) ? xrmask.getAlphaMask() : 0; + if( 0 < alphaMask ) { + res.setBackgroundOpaque(false); + res.setTransparentRedValue(xrmask.getRedMask()); + res.setTransparentGreenValue(xrmask.getGreenMask()); + res.setTransparentBlueValue(xrmask.getBlueMask()); + res.setTransparentAlphaValue(alphaMask); + } else { + res.setBackgroundOpaque(true); + } + // ALPHA shall be set at last - due to it's auto setting by the above (!opaque / samples) + res.setRedBits (Bitfield.Util.bitCount((int)info.getRed_mask())); + res.setGreenBits (Bitfield.Util.bitCount((int)info.getGreen_mask())); + res.setBlueBits (Bitfield.Util.bitCount((int)info.getBlue_mask())); + res.setAlphaBits (Bitfield.Util.bitCount(alphaMask)); + + return res; + } + public X11GraphicsConfiguration(final X11GraphicsScreen screen, final CapabilitiesImmutable capsChosen, final CapabilitiesImmutable capsRequested, final XVisualInfo info) { diff --git a/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java b/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java index f8a11f91e..4257376a0 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/jogamp/nativewindow/x11/X11GraphicsConfigurationFactory.java @@ -42,6 +42,7 @@ import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.VisualIDHolder; import com.jogamp.nativewindow.x11.X11GraphicsConfiguration; +import com.jogamp.nativewindow.x11.X11GraphicsDevice; import com.jogamp.nativewindow.x11.X11GraphicsScreen; public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactory { @@ -59,15 +60,17 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor if(!(screen instanceof X11GraphicsScreen)) { throw new NativeWindowException("Only valid X11GraphicsScreen are allowed"); } - final X11Capabilities x11CapsChosen; + final XVisualInfo x11VisualInfo; if(VisualIDHolder.VID_UNDEFINED == nativeVisualID) { - x11CapsChosen = new X11Capabilities(getXVisualInfo(screen, capsChosen)); + x11VisualInfo = getXVisualInfo(screen, capsChosen); } else { - x11CapsChosen = new X11Capabilities(getXVisualInfo(screen, nativeVisualID)); + x11VisualInfo = getXVisualInfo(screen, nativeVisualID); } + + final X11Capabilities x11CapsChosen = X11GraphicsConfiguration.XVisualInfo2X11Capabilities((X11GraphicsDevice)screen.getDevice(), x11VisualInfo); final AbstractGraphicsConfiguration res = new X11GraphicsConfiguration((X11GraphicsScreen)screen, x11CapsChosen, capsRequested, x11CapsChosen.getXVisualInfo()); if(DEBUG) { - System.err.println("X11GraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(visualID 0x"+Integer.toHexString(nativeVisualID)+", "+screen+","+capsChosen+"): "+res); + System.err.println("X11GraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(visualID 0x"+Integer.toHexString(nativeVisualID)+", "+x11VisualInfo+", "+screen+","+capsChosen+"): "+res); } return res; } @@ -85,7 +88,6 @@ public class X11GraphicsConfigurationFactory extends GraphicsConfigurationFactor if(xvis==null || num[0]<1) { return null; } - return XVisualInfo.create(xvis[0]); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows02NEWT.java new file mode 100644 index 000000000..5cdb7e118 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows02NEWT.java @@ -0,0 +1,158 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.newt; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import com.jogamp.nativewindow.*; + +import com.jogamp.newt.*; +import java.io.IOException; + +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestWindows02NEWT extends UITestCase { + static int width, height; + static long durationPerTest = 100; // ms + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(); + width = 800; + height = 600; + } + + static Window createWindow(final Capabilities caps, final int x, final int y, final int width, final int height, final boolean onscreen, final boolean undecorated) throws InterruptedException { + final boolean userPos = x>=0 && y>=0 ; // user has specified a position + + Assert.assertNotNull(caps); + caps.setOnscreen(onscreen); + // System.out.println("Requested: "+caps); + + // + // Create native windowing resources .. X11/Win/OSX + // + final Window window = NewtFactory.createWindow(caps); + Assert.assertNotNull(window); + final Screen screen = window.getScreen(); + final Display display = screen.getDisplay(); + window.setUndecorated(onscreen && undecorated); + if(userPos) { + window.setPosition(x, y); + } + window.setSize(width, height); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + window.setVisible(true); + // System.err.println("************* Created: "+window); + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window.isVisible()); + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(width, window.getWidth()); + Assert.assertEquals(height, window.getHeight()); + + final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities(); + Assert.assertNotNull(chosenCapabilities); + Assert.assertTrue(chosenCapabilities.getGreenBits()>=5); + Assert.assertTrue(chosenCapabilities.getBlueBits()>=5); + Assert.assertTrue(chosenCapabilities.getRedBits()>=5); + Assert.assertEquals(chosenCapabilities.isOnscreen(),onscreen); + + return window; + } + + static void destroyWindow(final Window window, final boolean last) { + if(null==window) { + return; + } + final Screen screen = window.getScreen(); + final Display display = screen.getDisplay(); + window.destroy(); + // System.err.println("************* Destroyed: "+window); + if(last) { + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + } else { + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,display.isNativeValid()); + } + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,window.isVisible()); + } + + + @Test + public void test01WindowDefault() throws InterruptedException { + final Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + + final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */); + final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities(); + System.err.println("XXX: "+chosenCapabilities); + for(int state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + destroyWindow(window, true); + } + + @Test + public void test02WindowDefault() throws InterruptedException { + final Capabilities caps = new Capabilities(); + Assert.assertNotNull(caps); + caps.setBackgroundOpaque(false); + + final Window window = createWindow(caps, -1, -1, width, height, true /* onscreen */, false /* undecorated */); + final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities(); + System.err.println("XXX: "+chosenCapabilities); + for(int state=0; state*100<durationPerTest; state++) { + Thread.sleep(100); + } + destroyWindow(window, true); + } + + public static void main(final String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atol(args[++i], durationPerTest); + } + } + System.out.println("durationPerTest: "+durationPerTest); + final String tstname = TestWindows02NEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} |