diff options
author | Sven Gothel <[email protected]> | 2013-11-21 01:42:54 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-11-21 01:42:54 +0100 |
commit | 94f3c1b5d3af65cf9d985833b2c8e40ec1af4592 (patch) | |
tree | a66732a1b7957a17a92aa98a8e514c92e324c7d5 | |
parent | 291c5ac4f0f55807172d1036e7c746db9af7ceec (diff) |
Bug 909 - Reccreate GLJPanel's BufferedImage is no more sourced by singleton AWTGLPixelBuffer
GLJPanel must validate whether it's local BufferedImage's DataBuffer is sourced
by the current singleton AWTGLPixelBuffer.
Case:
GLJPanel-B has created a new singleton AWTGLPixelBuffer w/ increased size.
Previous created GLJPanel-A's local BufferedImage's DataBuffer is no more sourced
by the singleton AWTGLPixelBuffer and hence must be re-created.
4 files changed, 240 insertions, 23 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 157c8703a..809aceb0c 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -199,11 +199,12 @@ function jrun() { #D_ARGS="-Dnewt.debug.Window -Djogl.debug.GLDrawable" #D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Window.KeyEvent" #D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Window.MouseEvent -Dnewt.debug.Window.KeyEvent" - D_ARGS="-Dnewt.debug.Window" + #D_ARGS="-Dnewt.debug.Window" #D_ARGS="-Xprof" #D_ARGS="-Dnativewindow.debug=all" #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Java2D -Djogl.debug.GLJPanel" #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Java2D -Djogl.debug.GLJPanel -Djogl.gljpanel.noglsl" + D_ARGS="-Djogl.debug.GLJPanel -Djogl.debug.DebugGL" #D_ARGS="-Djogl.gljpanel.noverticalflip" #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Animator" #D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.X11Util.XSync" @@ -319,7 +320,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelAWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2GLJPanelsAWT $* -testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasAWT $* #testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestLandscapeES2NewtCanvasAWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile00NEWT $* @@ -528,6 +529,7 @@ testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NewtCanvasA #testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasAWTActionDeadlock01AWT $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLCanvasAWTActionDeadlock02AWT $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLJPanelTextureStateAWT $* +testawt com.jogamp.opengl.test.junit.jogl.awt.TestGLJPanelResize01AWT $* #testawt com.jogamp.opengl.test.bugs.Bug735Inv0AppletAWT $* #testawt com.jogamp.opengl.test.bugs.Bug735Inv1AppletAWT $* diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java index 77b14b424..a33356067 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/awt/AWTGLPixelBuffer.java @@ -101,20 +101,24 @@ public class AWTGLPixelBuffer extends GLPixelBuffer { if( width * height > image.getWidth() * image.getHeight() ) { throw new IllegalArgumentException("Requested size exceeds image size: "+width+"x"+height+" > "+image.getWidth()+"x"+image.getHeight()); } - if( width == image.getWidth() ) { - if( height == image.getHeight() ) { - return image; - } - return image.getSubimage(0, 0, width, height); + if( width == image.getWidth() && height == image.getHeight() ) { + return image; + } else { + final ColorModel cm = image.getColorModel(); + final WritableRaster raster0 = image.getRaster(); + final DataBuffer dataBuffer = raster0.getDataBuffer(); + final SinglePixelPackedSampleModel sppsm0 = (SinglePixelPackedSampleModel) raster0.getSampleModel(); + final SinglePixelPackedSampleModel sppsm1 = new SinglePixelPackedSampleModel(dataBuffer.getDataType(), + width, height, width /* scanLineStride */, sppsm0.getBitMasks()); + final WritableRaster raster1 = WritableRaster.createWritableRaster(sppsm1, dataBuffer, null); + return new BufferedImage (cm, raster1, cm.isAlphaPremultiplied(), null); } - final ColorModel cm = image.getColorModel(); - final WritableRaster raster = image.getRaster(); - final DataBuffer dataBuffer = raster.getDataBuffer(); - final SinglePixelPackedSampleModel sppsm0 = (SinglePixelPackedSampleModel) raster.getSampleModel(); - final SinglePixelPackedSampleModel sppsm1 = new SinglePixelPackedSampleModel(dataBuffer.getDataType(), - width, height, width /* scanLineStride */, sppsm0.getBitMasks()); - final WritableRaster raster1 = WritableRaster.createWritableRaster(sppsm1, dataBuffer, null); - return new BufferedImage (cm, raster1, cm.isAlphaPremultiplied(), null); + } + + public final boolean isDataBufferSource(BufferedImage imageU) { + final DataBuffer dataBuffer0 = image.getRaster().getDataBuffer(); + final DataBuffer dataBufferU = imageU.getRaster().getDataBuffer(); + return dataBufferU == dataBuffer0; } @Override diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index bff8a1880..70dd8b99d 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -580,7 +580,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing super.reshape(x, y, width, height); if( DEBUG ) { - System.err.println(getThreadName()+": GLJPanel.reshape resize"+(printActive?"WithinPrint":"")+" [ panel "+ + System.err.println(getThreadName()+": GLJPanel.reshape.0 "+this.getName()+" resize"+(printActive?"WithinPrint":"")+" [ this "+getWidth()+"x"+getHeight()+", panel "+ panelWidth+"x"+panelHeight + ", reshape: " +reshapeWidth+"x"+reshapeHeight + "] -> "+(printActive?"skipped":"") + width+"x"+height); @@ -1588,19 +1588,21 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } pixelBuffer = pixelBufferProvider.allocate(gl, pixelAttribs, panelWidth, panelHeight, 1, true, 0); if(DEBUG) { - System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: pixelBufferProvider isSingletonBufferProvider "+useSingletonBuffer+", 0x"+Integer.toHexString(pixelBufferProvider.hashCode())+", "+pixelBufferProvider.getClass().getSimpleName()); - System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: pixelBuffer 0x"+Integer.toHexString(pixelBuffer.hashCode())+", "+pixelBuffer+", alignment "+alignment); - System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: flippedVertical "+flipVertical+", glslTextureRaster "+(null!=glslTextureRaster)); - System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: panelSize "+panelWidth+"x"+panelHeight); + System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" pixelBufferProvider isSingletonBufferProvider "+useSingletonBuffer+", 0x"+Integer.toHexString(pixelBufferProvider.hashCode())+", "+pixelBufferProvider.getClass().getSimpleName()); + System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" pixelBuffer 0x"+Integer.toHexString(pixelBuffer.hashCode())+", "+pixelBuffer+", alignment "+alignment); + System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" flippedVertical "+flipVertical+", glslTextureRaster "+(null!=glslTextureRaster)); + System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" panelSize "+panelWidth+"x"+panelHeight); } } if( offscreenDrawable.getWidth() != panelWidth || offscreenDrawable.getHeight() != panelHeight ) { throw new InternalError("OffscreenDrawable panelSize mismatch (reshape missed): panelSize "+panelWidth+"x"+panelHeight+" != drawable "+offscreenDrawable.getWidth()+"x"+offscreenDrawable.getHeight()+", on thread "+getThreadName()); } - if( null == alignedImage || panelWidth != alignedImage.getWidth() || panelHeight != alignedImage.getHeight() ) { + if( null == alignedImage || + panelWidth != alignedImage.getWidth() || panelHeight != alignedImage.getHeight() || + !pixelBuffer.isDataBufferSource(alignedImage) ) { alignedImage = pixelBuffer.getAlignedImage(panelWidth, panelHeight); if(DEBUG) { - System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: alignedImage "+alignedImage.getWidth()+"x"+alignedImage.getHeight()+", pixelBuffer "+pixelBuffer.width+"x"+pixelBuffer.height); + System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL.0: "+GLJPanel.this.getName()+" new alignedImage "+alignedImage.getWidth()+"x"+alignedImage.getHeight()+", "+alignedImage+", pixelBuffer "+pixelBuffer.width+"x"+pixelBuffer.height+", "+pixelBuffer); } } final IntBuffer readBackInts; @@ -1652,7 +1654,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing viewportChange = 0 != usrViewport[0] || 0 != usrViewport[1] || offscreenDrawable.getWidth() != usrViewport[2] || offscreenDrawable.getHeight() != usrViewport[3]; if( DEBUG_VIEWPORT ) { - System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL: Viewport: change "+viewportChange+ + System.err.println(getThreadName()+": GLJPanel.OffscreenBackend.postGL: "+GLJPanel.this.getName()+" Viewport: change "+viewportChange+ ", "+usrViewport[0]+"/"+usrViewport[1]+" "+usrViewport[2]+"x"+usrViewport[3]+ " -> 0/0 "+offscreenDrawable.getWidth()+"x"+offscreenDrawable.getHeight()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java new file mode 100644 index 000000000..2133d62a2 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestGLJPanelResize01AWT.java @@ -0,0 +1,209 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.awt; + +import java.awt.Dimension; +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; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import org.junit.Assume; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Multiple GLJPanels in a JFrame + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestGLJPanelResize01AWT extends UITestCase { + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(); + } + + static Dimension[] esize00 = { + new Dimension(281, 151), + new Dimension(282, 151), + new Dimension(283, 151), + new Dimension(284, 151), + + new Dimension(284, 152), + new Dimension(283, 152), + new Dimension(282, 152), + new Dimension(281, 152), + + new Dimension(291, 153), + new Dimension(292, 153), + new Dimension(293, 153), + new Dimension(294, 153), + + new Dimension(281, 154), + new Dimension(282, 154), + new Dimension(283, 154), + new Dimension(284, 154) + }; + static Dimension[] esize01 = { + new Dimension(283, 154), // #3: new sub-aligned image in pixelBuffer-1 + new Dimension(291, 154), // #2: new pixelBuffer-1 + new Dimension(282, 154), // #1: new pixelBuffer-0 + }; + static Dimension[] esize02 = { + new Dimension(291, 154), // #2: new pixelBuffer-1 + new Dimension(282, 154), // #1: new pixelBuffer-0 + }; + + public void test(final GLCapabilitiesImmutable caps, final Dimension[] dims, final boolean useSwingDoubleBuffer) { + final int cols = 4; + final int rows = dims.length / cols + ( dims.length % cols > 0 ? 1 : 0 ); + final JFrame[] frame = new JFrame[] { null }; + + System.err.println("Frame size: cols x rows "+cols+"x"+rows); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame[0] = new JFrame(); + frame[0].setLocation(64, 64); + final JPanel panel = new JPanel(); + panel.setLayout(null); // new BorderLayout()); + panel.setDoubleBuffered(useSwingDoubleBuffer); + frame[0].getContentPane().add(panel); + + final int x0 = 4; + int x = x0, y = 4; + int maxRowWidth = 0; + for(int i=0; i<rows; i++) { + int maxColHeight = 0; + for(int j=0; j<cols; j++) { + final int idx = i*cols+j; + if( idx >= dims.length ) { break; } + final Dimension d = dims[idx]; + if( d.height > maxColHeight ) { + maxColHeight = d.height; + } + final GLJPanel glad = createGLJPanel(useSwingDoubleBuffer, caps, d, "[r "+i+", c "+j+"]"); + panel.add(glad); + glad.setLocation(x, y); + x+=d.width+4; + } + if( x > maxRowWidth ) { + maxRowWidth = x; + } + x = x0; + y += maxColHeight+4; + } + frame[0].setSize(maxRowWidth+4+64, y+4+64); + // frame[0].pack(); + frame[0].setVisible(true); + } } ); + } catch( Throwable throwable ) { + throwable.printStackTrace(); + Assume.assumeNoException( throwable ); + } + try { + Thread.sleep(duration); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame[0].dispose(); + } } ); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + + private GLJPanel createGLJPanel(final boolean useSwingDoubleBuffer, final GLCapabilitiesImmutable caps, final Dimension size, final String name) { + final GLJPanel canvas = new GLJPanel(caps); + canvas.setName(name); + canvas.setSize(size); + canvas.setPreferredSize(size); + canvas.setMinimumSize(size); + canvas.setDoubleBuffered(useSwingDoubleBuffer); + final GearsES2 g = new GearsES2(0); + g.setVerbose(false); + canvas.addGLEventListener(g); + return canvas; + } + + static GLCapabilitiesImmutable caps = null; + + // @Test + public void test00() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), esize00, false /*useSwingDoubleBuffer*/); + } + + @Test + public void test01() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), esize01, false /*useSwingDoubleBuffer*/); + } + + @Test + public void test02() throws InterruptedException, InvocationTargetException { + test(new GLCapabilities(null), esize02, false /*useSwingDoubleBuffer*/); + } + + static long duration = 600; // ms + + public static void main(String[] args) { + boolean useSwingDoubleBuffer=false, manual=false; + + 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("-swingDoubleBuffer")) { + useSwingDoubleBuffer = true; + } else if(args[i].equals("-manual")) { + manual = true; + } + } + if( manual ) { + GLProfile.initSingleton(); + TestGLJPanelResize01AWT demo = new TestGLJPanelResize01AWT(); + demo.test(new GLCapabilities(null), esize01, useSwingDoubleBuffer); + } else { + org.junit.runner.JUnitCore.main(TestGLJPanelResize01AWT.class.getName()); + } + } + +} |