diff options
author | Sven Gothel <[email protected]> | 2015-08-31 08:41:07 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-08-31 08:41:07 +0200 |
commit | cf9e2f2cb8ead7efd7751dcbfaecb36ed06cf9d6 (patch) | |
tree | 5b0879c7146983221074ed9c687be2fba7db779d /src | |
parent | cc00d9b6c5a5c6b71ba14311fc6b17ce932d9a1e (diff) |
Bug 1210 - Use manual impl. XRenderFindVisualFormat instead of buggy generated version
- XRenderDirectFormat XVisual2XRenderMask(..):
- Move from JOGL's X11GLXGraphicsConfiguration -> Nativewindow X11GraphicsConfiguration
- Always use manual impl. of XRenderFindVisualFormat
Additionally:
- Add X11GraphicsConfiguration.XVisualInfo2X11Capabilities(..)
allowing to properly setup the resulting Capabilities instance
as used in X11GraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(..)
- XVisualInfo:
- Add 'String toString()'
- 'XVisualInfo create(XVisualInfo s)' uses source buffer size!
- XGetVisualInfo: Use returned buffer-capacity/count for element-size
and also bail out if count<=0
Diffstat (limited to 'src')
4 files changed, 208 insertions, 20 deletions
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); + } + +} |