Bug 589

Summary: Resize GLCanvas broken on OSX and JDK7
Product: [JogAmp] Jogl Reporter: jost <jost0x2c>
Component: macosxAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: normal CC: gouessej
Priority: ---    
Version: 2   
Hardware: pc_x86_64   
OS: macosx   
Type: --- SCM Refs:
jogl c03ad260aea0b4a640a5eeb50a206688c531b591 jogl d10c7916a2444b6cb1cf45be3ccb3d6e91a2f1b4 jogl 0d7c3ed619044723cf561df424eac9992e5281c7 jogl c50fca1b5df9ec3b76fada4dd5dd307bdece531a jogl 9a7c8896fe38ebcd42ed5238b09a7a36d46db9dc
Workaround: ---
Attachments: screenshot
test1.log
test2.log

Description jost 2012-06-16 14:16:07 CEST
Created attachment 350 [details]
screenshot

While evaluating jdk1.7 (1.7.0_06-ea) on OSX I found that resizing GLCanvas no longer works as expected. This can be easily reproduced by running an example like SimpleScene (source at the bottom of https://sites.google.com/site/justinscsstuff/jogl-tutorial-3). When resizing the window, the displayed animation is scaled down to fill only a small rectangle in the bottom left corner of the window (see attached image). 
This seems to be related to an open issue filed on the "processing" issue tracker (http://code.google.com/p/processing/issues/detail?id=1070) where a similar behaviour is described in connection with a jogl based opengl renderer. 

I reproduced the issue on 2 different machines running OSX 10.6.8 and 10.7.4. test.log outputs for both machines are also attached.

While resizing console log continuously showed entries like the following: "java[11246:707] invalid drawable"
The canvas size reported by canvas.getWidth()/.getHeight() was correct (not matching the small rectangle but the outer frame).

See also http://forum.jogamp.org/Resize-GLCanvas-broken-on-OSX-and-JDK7-td4025223.html
Comment 1 jost 2012-06-16 14:17:19 CEST
Created attachment 351 [details]
test1.log
Comment 2 jost 2012-06-16 14:18:00 CEST
Created attachment 352 [details]
test2.log
Comment 3 Julien Gouesse 2012-06-18 09:52:08 CEST
Do you reproduce the same problem with a plan java.awt.Canvas? I would like to know whether this bug really comes from JOGL (or from AWT).
Comment 4 jost 2012-06-18 13:53:22 CEST
No, adding the canvas below to a java.awt.Frame paints and resizes as expected:

public static class SimpleCanvas extends java.awt.Canvas {
        @Override
        public void paint(Graphics g) {
            int w = getWidth();
            int h = getHeight();
            g.setColor(Color.RED);
            g.fillOval(10, 10, w - 20, h - 20);
        }
    }
Comment 5 Sven Gothel 2012-06-28 22:14:49 CEST
Added unit tests (enhancements and new ones) trying to [visually] cover
this situation using screenshots.

See JOGL commit c03ad260aea0b4a640a5eeb50a206688c531b591,
especially test case:
  com.jogamp.opengl.test.junit.jogl.util.texture.TestGLReadBufferUtilTextureIOWrite02AWT

Let's use these screenshots and test cases to analyze the behavior.

Your setup:
  - Mac OS X 10.7.4 (os), 
  - Java Version: 1.7.0_06-ea, VM: Java HotSpot(TM) 64-Bit Server VM
  - GL_RENDERER    NVIDIA GeForce 9400M OpenGL Engine
    GL_VERSION     2.1 NVIDIA-7.18.18
    GLSL           true, has-compiler: true, version: 1.20


Ours default: <https://jogamp.org/chuck/job/jogl/770/label=macosx-10_6-x86_64-nvidia/consoleText>
  - Mac OS X 10.7.4 (os),
  - Java Version: 1.6.0_33, VM: Java HotSpot(TM) 64-Bit Server VM
  - GL_RENDERER    NVIDIA GeForce 320M OpenGL Engine
    GL_VERSION     2.1 NVIDIA-7.18.18
    GLSL           true, has-compiler: true, version: 1.20

Will also test w/ Java 1.7* ofc. ..

Lets check the results of the new builds staring from b771:
  <https://jogamp.org/chuck/view/fwd/job/jogl/771/>

Test files and log (sections) of interest:
  - com.jogamp.opengl.test.junit.jogl.util.texture.TestGLReadBufferUtilTextureIOWrite02AWT
  - TestGLReadBufferUtilTextureIOWrite02AWT.*.png
Comment 6 Sven Gothel 2012-06-29 01:56:15 CEST
(In reply to comment #5)
>  
> com.jogamp.opengl.test.junit.jogl.util.texture.TestGLReadBufferUtilTextureIOWrite02AWT

Above test triggers a NPE (w/ offscreen layer use, resize -> recreate) .. 
The new tests allows us to nail it down, stay tuned :)
Comment 7 Sven Gothel 2012-06-29 04:29:56 CEST
(In reply to comment #6)
> (In reply to comment #5)
> >  
> > com.jogamp.opengl.test.junit.jogl.util.texture.TestGLReadBufferUtilTextureIOWrite02AWT
> 
> Above test triggers a NPE (w/ offscreen layer use, resize -> recreate) .. 
> The new tests allows us to nail it down, stay tuned :)

Fixed the NPE, good cleanup for stability catching destruction cases unhandled yet.

Now the test case reproduces your experience w/ java7
while working flawless w/ java6 - both using the offscreen layering.
(Ofc w/ java7 no onscreen rendering is available)

Minor note: the resize width is wrong on OSX.

+++

Interesting piece is that even though the screenshot does show 
a resized picture, but on the actual screen it stays small.
In some test run it freezes/deadlocks at: AWT-EventQueue-0:
  at jogamp.opengl.macosx.cgl.CGL.setNSOpenGLLayerSwapInterval(Native Method)
  at jogamp.opengl.macosx.cgl.MacOSXCGLContext$NSOpenGLImpl.setSwapInterval(MacOSXCGLContext.java:589)
  at jogamp.opengl.macosx.cgl.MacOSXCGLContext.setSwapIntervalImpl(MacOSXCGLContext.java:296)
  at javax.media.opengl.GLContext.setSwapInterval(GLContext.java:628)
  at jogamp.opengl.gl4.GL4bcImpl.setSwapInterval(GL4bcImpl.java:34143)
  at com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2.init(GearsES2.java:177)

+++

Will dig into it deeper ..
Comment 8 Sven Gothel 2012-06-30 05:19:24 CEST
Fixed.

OSXUtil.CreateCALayer*(..) needs to have the layer target size (if known)
otherwise it's possible openjdk7 uses a zero sized CALayer.

+++

Tested against:
  openjdk version "1.7.0-jdk7u5-b30"
  OpenJDK Runtime Environment (build 1.7.0-jdk7u5-b30-20120621)
  OpenJDK 64-Bit Server VM (build 23.2-b05, mixed mode)
and
  java version "1.6.0_33"
  Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
  Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
Comment 9 jost 2012-07-03 20:32:29 CEST
Thanks! I can confirm the fix with my setup. Though there still is a difference between jdk6 and jdk7. During resizing with jdk7 the canvas is flickering heavily, in fact, when resizing its more like the animation  disappears and reappears after resizing has finished. jdk6 resizing goes smoothly without disturbing the animation and without any noticeable flickering.