aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/scripts/tests.sh4
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java49
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java85
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLJPanel.java121
-rw-r--r--src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java53
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java27
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java59
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java58
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java124
9 files changed, 345 insertions, 235 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index fee4b3ec0..2b7a2563e 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -216,7 +216,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.GLContext -Dnewt.debug=all -Djogamp.debug.Lock -Djogamp.common.utils.locks.Lock.timeout=10000"
#D_ARGS="-Djogl.debug.GLContext -Dnewt.debug=all"
#D_ARGS="-Dnewt.debug=all"
- D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.GLJPanel -Djogl.debug.TileRenderer"
+ #D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.GLJPanel -Djogl.debug.TileRenderer"
#D_ARGS="-Djogl.debug.PNGImage"
#D_ARGS="-Djogl.debug.JPEGImage"
#D_ARGS="-Djogl.debug.GLDrawable -Dnativewindow.debug.GraphicsConfiguration -Djogl.debug.CapabilitiesChooser"
@@ -330,7 +330,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.tile.TestRandomTiledRendering2GL2NEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.tile.TestRandomTiledRendering3GL2AWT $*
testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsAWT $*
-#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT $*
+testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT $*
#
# core/newt (testnoawt and testawt)
diff --git a/src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java b/src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java
index 077ee42a9..293bdb809 100644
--- a/src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java
+++ b/src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java
@@ -29,9 +29,12 @@ package javax.media.opengl.awt;
import javax.media.opengl.GLAutoDrawable;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import jogamp.nativewindow.awt.AWTMisc;
+
/**
* Interface describing print lifecycle to support AWT printing
* on AWT {@link GLAutoDrawable}s.
@@ -41,11 +44,55 @@ public interface AWTPrintLifecycle {
/**
* Shall be called before {@link Component#print(Graphics)}.
* @param g2d the {@link Graphics2D} instance, which will be used for printing.
+ * @param scaleMatX {@link Graphics2D} {@link Graphics2D#scale(double, double) scaling factor}, i.e. rendering 1/scaleMatX * width pixels
+ * @param scaleMatY {@link Graphics2D} {@link Graphics2D#scale(double, double) scaling factor}, i.e. rendering 1/scaleMatY * height pixels
*/
- void setupPrint(Graphics2D g2d);
+ void setupPrint(Graphics2D g2d, double scaleMatX, double scaleMatY);
/**
* Shall be called after very last {@link Component#print(Graphics)}.
*/
void releasePrint();
+
+ public static class Context {
+ public static Context setupPrint(Container c, Graphics2D g2d, double scaleMatX, double scaleMatY) {
+ final Context t = new Context(c, g2d, scaleMatX, scaleMatY);
+ t.setupPrint(c);
+ return t;
+ }
+
+ public void releasePrint() {
+ count = AWTMisc.performAction(cont, AWTPrintLifecycle.class, releaseAction);
+ }
+
+ public int getCount() { return count; }
+
+ private final Container cont;
+ private final Graphics2D g2d;
+ private final double scaleMatX;
+ private final double scaleMatY;
+ private int count;
+
+ private final AWTMisc.ComponentAction setupAction = new AWTMisc.ComponentAction() {
+ @Override
+ public void run(Component c) {
+ ((AWTPrintLifecycle)c).setupPrint(g2d, scaleMatX, scaleMatY);
+ } };
+ private final AWTMisc.ComponentAction releaseAction = new AWTMisc.ComponentAction() {
+ @Override
+ public void run(Component c) {
+ ((AWTPrintLifecycle)c).releasePrint();
+ } };
+
+ private Context(Container c, Graphics2D g2d, double scaleMatX, double scaleMatY) {
+ this.cont = c;
+ this.g2d = g2d;
+ this.scaleMatX = scaleMatX;
+ this.scaleMatY = scaleMatY;
+ this.count = 0;
+ }
+ private void setupPrint(Container c) {
+ count = AWTMisc.performAction(c, AWTPrintLifecycle.class, setupAction);
+ }
+ }
}
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index 8f9684db1..b2ffc17a2 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -86,7 +86,6 @@ import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
-import javax.media.opengl.GLOffscreenAutoDrawable;
import javax.media.opengl.GLProfile;
import javax.media.opengl.GLRunnable;
import javax.media.opengl.Threading;
@@ -733,11 +732,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
private volatile boolean printActive = false;
private boolean printUseAA = false;
private GLAnimatorControl printAnimator = null;
- private GLOffscreenAutoDrawable printGLAD = null;
+ private GLAutoDrawable printGLAD = null;
private AWTTilePainter printAWTTiles = null;
@Override
- public void setupPrint(Graphics2D g2d) {
+ public void setupPrint(Graphics2D g2d, double scaleMatX, double scaleMatY) {
if( !validateGLDrawable() ) {
if(DEBUG) {
System.err.println(getThreadName()+": Info: GLCanvas setupPrint - skipped GL render, drawable not valid yet");
@@ -758,7 +757,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
printUseAA = null != _useAA && ( _useAA == RenderingHints.VALUE_ANTIALIAS_DEFAULT || _useAA == RenderingHints.VALUE_ANTIALIAS_ON );
}
if( DEBUG ) {
- System.err.println("AWT print.setup: canvasSize "+getWidth()+"x"+getWidth()+", useAA "+printUseAA+", printAnimator "+printAnimator);
+ System.err.println("AWT print.setup: canvasSize "+getWidth()+"x"+getWidth()+", scaleMat "+scaleMatX+" x "+scaleMatY+", useAA "+printUseAA+", printAnimator "+printAnimator);
{
final Set<Entry<Object, Object>> rEntries = rHints.entrySet();
int count = 0;
@@ -770,7 +769,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
final AffineTransform aTrans = g2d.getTransform();
System.err.println(" scale "+aTrans.getScaleX()+" x "+aTrans.getScaleY());
System.err.println(" move "+aTrans.getTranslateX()+" x "+aTrans.getTranslateY());
- }
+ }
+ final int componentCount = isOpaque() ? 3 : 4;
+ final TileRenderer printRenderer = new TileRenderer();
+ printAWTTiles = new AWTTilePainter(printRenderer, componentCount, scaleMatX, scaleMatY, DEBUG);
AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, setupPrintOnEDT);
}
private final Runnable setupPrintOnEDT = new Runnable() {
@@ -782,30 +784,31 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
printAnimator.remove(GLCanvas.this);
}
final GLCapabilities caps = (GLCapabilities)getChosenGLCapabilities().cloneMutable();
- caps.setDoubleBuffered(false);
final GLProfile glp = caps.getGLProfile();
- if( printUseAA && !caps.getSampleBuffers() ) {
- if ( !glp.isGL2ES3() ) {
- if( DEBUG ) {
- System.err.println("Ignore MSAA due to gl-profile < GL2ES3");
+ if( caps.getSampleBuffers() ) {
+ // bug / issue w/ swapGLContextAndAllGLEventListener and onscreen MSAA w/ NV/GLX
+ printGLAD = GLCanvas.this;
+ } else {
+ caps.setDoubleBuffered(false);
+ caps.setOnscreen(false);
+ if( printUseAA && !caps.getSampleBuffers() ) {
+ if ( !glp.isGL2ES3() ) {
+ if( DEBUG ) {
+ System.err.println("Ignore MSAA due to gl-profile < GL2ES3");
+ }
+ printUseAA = false;
+ } else {
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(8);
}
- printUseAA = false;
- } else {
- caps.setSampleBuffers(true);
- caps.setNumSamples(8); // FIXME
}
+ final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
+ printGLAD = factory.createOffscreenAutoDrawable(null, caps, null, PRINT_TILE_SIZE, PRINT_TILE_SIZE, null);
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(GLCanvas.this, printGLAD);
}
- caps.setOnscreen(false);
- final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
- printGLAD = factory.createOffscreenAutoDrawable(null, caps, null, PRINT_TILE_SIZE, PRINT_TILE_SIZE, null);
- GLDrawableUtil.swapGLContextAndAllGLEventListener(GLCanvas.this, printGLAD);
- destroyOnEDTAction.run();
- final int componentCount = isOpaque() ? 3 : 4;
- final TileRenderer printRenderer = new TileRenderer();
- printRenderer.setTileSize(printGLAD.getWidth(), printGLAD.getHeight(), 0);
- printRenderer.attachToAutoDrawable(printGLAD);
- printAWTTiles = new AWTTilePainter(printRenderer, componentCount, DEBUG);
+ printAWTTiles.renderer.setTileSize(printGLAD.getWidth(), printGLAD.getHeight(), 0);
+ printAWTTiles.renderer.attachToAutoDrawable(printGLAD);
if( DEBUG ) {
System.err.println("AWT print.setup "+printAWTTiles);
System.err.println("AWT print.setup AA "+printUseAA+", "+caps);
@@ -832,9 +835,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
printAWTTiles.dispose();
printAWTTiles= null;
- createDrawableAndContext( false );
- GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, GLCanvas.this);
- printGLAD.destroy();
+ if( printGLAD != GLCanvas.this ) {
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, GLCanvas.this);
+ printGLAD.destroy();
+ }
printGLAD = null;
if( null != printAnimator ) {
printAnimator.add(GLCanvas.this);
@@ -854,17 +858,26 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
// we cannot dispatch print on AWT-EDT due to printing internal locking ..
}
sendReshape = false; // clear reshape flag
- final Graphics2D printGraphics = (Graphics2D)graphics;
- printAWTTiles.updateGraphics2DAndClipBounds(printGraphics);
- final TileRenderer tileRenderer = printAWTTiles.getTileRenderer();
- if( DEBUG ) {
- System.err.println("AWT print.0: "+tileRenderer);
+
+ final Graphics2D g2d = (Graphics2D)graphics;
+ printAWTTiles.setupGraphics2DAndClipBounds(g2d);
+ try {
+ final TileRenderer tileRenderer = printAWTTiles.renderer;
+ if( DEBUG ) {
+ System.err.println("AWT print.0: "+tileRenderer);
+ }
+ do {
+ if( printGLAD != GLCanvas.this ) {
+ tileRenderer.display();
+ } else {
+ Threading.invoke(true, displayOnEDTAction, getTreeLock());
+ }
+ } while ( !tileRenderer.eot() );
+ } finally {
+ printAWTTiles.resetGraphics2D();
}
- do {
- tileRenderer.display();
- } while ( !tileRenderer.eot() );
if( DEBUG ) {
- System.err.println("AWT print.X: "+tileRenderer);
+ System.err.println("AWT print.X: "+printAWTTiles);
}
}
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
index 2488bd443..b549ad30c 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java
@@ -98,6 +98,7 @@ import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol;
import com.jogamp.opengl.FBObject;
import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
import com.jogamp.opengl.util.GLPixelBuffer.SingletonGLPixelBufferProvider;
+import com.jogamp.opengl.util.GLDrawableUtil;
import com.jogamp.opengl.util.GLPixelStorageModes;
import com.jogamp.opengl.util.TileRenderer;
import com.jogamp.opengl.util.awt.AWTGLPixelBuffer;
@@ -500,12 +501,15 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
}
+ private static final int PRINT_TILE_SIZE = 512;
private volatile boolean printActive = false;
+ private boolean printUseAA = false;
private GLAnimatorControl printAnimator = null;
+ private GLAutoDrawable printGLAD = null;
private AWTTilePainter printAWTTiles = null;
@Override
- public void setupPrint(Graphics2D g2d) {
+ public void setupPrint(Graphics2D g2d, double scaleMatX, double scaleMatY) {
if (!isInitialized) {
if(DEBUG) {
System.err.println(getThreadName()+": Info: GLJPanel setupPrint - skipped GL render, drawable not valid yet");
@@ -521,6 +525,28 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
printActive = true;
sendReshape = false; // clear reshape flag
handleReshape = false; // ditto
+ final RenderingHints rHints = g2d.getRenderingHints();
+ {
+ final Object _useAA = rHints.get(RenderingHints.KEY_ANTIALIASING);
+ printUseAA = null != _useAA && ( _useAA == RenderingHints.VALUE_ANTIALIAS_DEFAULT || _useAA == RenderingHints.VALUE_ANTIALIAS_ON );
+ }
+ if( DEBUG ) {
+ System.err.println("AWT print.setup: canvasSize "+getWidth()+"x"+getWidth()+", scaleMat "+scaleMatX+" x "+scaleMatY+", useAA "+printUseAA+", printAnimator "+printAnimator);
+ {
+ final Set<Entry<Object, Object>> rEntries = rHints.entrySet();
+ int count = 0;
+ for(Iterator<Entry<Object, Object>> rEntryIter = rEntries.iterator(); rEntryIter.hasNext(); count++) {
+ final Entry<Object, Object> rEntry = rEntryIter.next();
+ System.err.println("Hint["+count+"]: "+rEntry.getKey()+" -> "+rEntry.getValue());
+ }
+ }
+ final AffineTransform aTrans = g2d.getTransform();
+ System.err.println(" scale "+aTrans.getScaleX()+" x "+aTrans.getScaleY());
+ System.err.println(" move "+aTrans.getTranslateX()+" x "+aTrans.getTranslateY());
+ }
+ final int componentCount = isOpaque() ? 3 : 4;
+ final TileRenderer printRenderer = new TileRenderer();
+ printAWTTiles = new AWTTilePainter(printRenderer, componentCount, scaleMatX, scaleMatY, DEBUG);
AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, setupPrintOnEDT);
}
private final Runnable setupPrintOnEDT = new Runnable() {
@@ -531,14 +557,34 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
printAnimator = helper.getAnimator();
if( null != printAnimator ) {
printAnimator.remove(GLJPanel.this);
- }
- final int componentCount = isOpaque() ? 3 : 4;
- final TileRenderer printRenderer = new TileRenderer();
- printRenderer.setTileSize(getWidth(), getHeight(), 0);
- printRenderer.attachToAutoDrawable(GLJPanel.this);
- printAWTTiles = new AWTTilePainter(printRenderer, componentCount, DEBUG);
+ }
+
+ printGLAD = GLJPanel.this; // default: re-use
+ final GLCapabilities caps = (GLCapabilities)getChosenGLCapabilities().cloneMutable();
+ final GLProfile glp = caps.getGLProfile();
+ if( printUseAA && !caps.getSampleBuffers() ) {
+ if ( !glp.isGL2ES3() ) {
+ if( DEBUG ) {
+ System.err.println("Ignore MSAA due to gl-profile < GL2ES3");
+ }
+ printUseAA = false;
+ } else {
+ // MSAA FBO ..
+ caps.setDoubleBuffered(false);
+ caps.setOnscreen(false);
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(8);
+ final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
+ printGLAD = factory.createOffscreenAutoDrawable(null, caps, null, PRINT_TILE_SIZE, PRINT_TILE_SIZE, null);
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(GLJPanel.this, printGLAD);
+ }
+ }
+ printAWTTiles.renderer.setTileSize(printGLAD.getWidth(), printGLAD.getHeight(), 0);
+ printAWTTiles.renderer.attachToAutoDrawable(printGLAD);
if( DEBUG ) {
System.err.println("AWT print.setup "+printAWTTiles);
+ System.err.println("AWT print.setup AA "+printUseAA+", "+caps);
+ System.err.println("AWT print.setup "+printGLAD);
}
}
};
@@ -563,6 +609,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
printAWTTiles.dispose();
printAWTTiles= null;
+ if( printGLAD != GLJPanel.this ) {
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, GLJPanel.this);
+ printGLAD.destroy();
+ }
+ printGLAD = null;
if( null != printAnimator ) {
printAnimator.add(GLJPanel.this);
printAnimator = null;
@@ -582,33 +633,26 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
}
sendReshape = false; // clear reshape flag
handleReshape = false; // ditto
- final Graphics2D printGraphics = (Graphics2D)graphics;
- if( DEBUG ) {
- System.err.println("AWT print.0: canvasSize "+getWidth()+"x"+getWidth()+", printAnimator "+printAnimator);
- {
- final RenderingHints rHints = printGraphics.getRenderingHints();
- final Set<Entry<Object, Object>> rEntries = rHints.entrySet();
- int count = 0;
- for(Iterator<Entry<Object, Object>> rEntryIter = rEntries.iterator(); rEntryIter.hasNext(); count++) {
- final Entry<Object, Object> rEntry = rEntryIter.next();
- System.err.println("Hint["+count+"]: "+rEntry.getKey()+" -> "+rEntry.getValue());
- }
+
+ final Graphics2D g2d = (Graphics2D)graphics;
+ printAWTTiles.setupGraphics2DAndClipBounds(g2d);
+ try {
+ final TileRenderer tileRenderer = printAWTTiles.renderer;
+ if( DEBUG ) {
+ System.err.println("AWT print.0: "+tileRenderer);
}
- final AffineTransform aTrans = printGraphics.getTransform();
- System.err.println(" scale "+aTrans.getScaleX()+" x "+aTrans.getScaleY());
- System.err.println(" move "+aTrans.getTranslateX()+" x "+aTrans.getTranslateY());
- }
- printAWTTiles.updateGraphics2DAndClipBounds(printGraphics);
- final TileRenderer tileRenderer = printAWTTiles.getTileRenderer();
- if( DEBUG ) {
- System.err.println("AWT print.0: "+tileRenderer);
+ do {
+ if( printGLAD != GLJPanel.this ) {
+ tileRenderer.display();
+ } else {
+ backend.doPlainPaint();
+ }
+ } while ( !tileRenderer.eot() );
+ } finally {
+ printAWTTiles.resetGraphics2D();
}
- do {
- // printRenderer.display();
- backend.doPlainPaint();
- } while ( !tileRenderer.eot() );
if( DEBUG ) {
- System.err.println("AWT print.X: "+tileRenderer);
+ System.err.println("AWT print.X: "+printAWTTiles);
}
}
@Override
@@ -803,6 +847,12 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
// so swapping the buffers doesn't do anything. We also don't
// currently have the provision to skip copying the data to the
// Swing portion of the GLJPanel in any of the rendering paths.
+ if( printActive && isInitialized) {
+ final Backend b = backend;
+ if ( null != b ) {
+ b.getDrawable().swapBuffers();
+ }
+ }
}
@Override
@@ -1007,7 +1057,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
backend.postGL(g, true);
}
- public void print(GLAutoDrawable drawable) {
+ public void plainPaint(GLAutoDrawable drawable) {
helper.display(GLJPanel.this);
}
@@ -1066,7 +1116,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
private final Runnable updaterPlainDisplayAction = new Runnable() {
@Override
public void run() {
- updater.print(GLJPanel.this);
+ updater.plainPaint(GLJPanel.this);
}
};
@@ -1405,13 +1455,14 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing
gl2es3.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, pixelBuffer.width);
gl2es3.glReadBuffer(gl2es3.getDefaultReadBuffer());
}
-
+
+ offscreenDrawable.swapBuffers();
+
if(null != glslTextureRaster) { // implies flippedVertical
// perform vert-flipping via OpenGL/FBO
final GLFBODrawable fboDrawable = (GLFBODrawable)offscreenDrawable;
final FBObject.TextureAttachment fboTex = fboDrawable.getTextureBuffer(GL.GL_FRONT);
- fboDrawable.swapBuffers();
fboFlipped.bind(gl);
// gl.glActiveTexture(GL.GL_TEXTURE0 + fboDrawable.getTextureUnit()); // implicit by GLFBODrawableImpl: swapBuffers/contextMadeCurent -> swapFBOImpl
diff --git a/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java b/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java
index 7493a19c5..8d07bdb8e 100644
--- a/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java
+++ b/src/jogl/classes/jogamp/opengl/awt/AWTTilePainter.java
@@ -31,6 +31,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
+import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
@@ -51,13 +52,15 @@ import com.jogamp.opengl.util.awt.AWTGLPixelBuffer.AWTGLPixelBufferProvider;
* </p>
*/
public class AWTTilePainter {
- final private TileRenderer renderer;
- final private int componentCount;
- final private boolean verbose;
+ public final TileRenderer renderer;
+ public final int componentCount;
+ public final double scaleMatX, scaleMatY;
+ public final boolean verbose;
private AWTGLPixelBuffer tBuffer = null;
private BufferedImage vFlipImage = null;
private Graphics2D g2d = null;
+ private AffineTransform saveAT = null;
/**
* Assumes a configured {@link TileRenderer}, i.e.
@@ -69,30 +72,43 @@ public class AWTTilePainter {
* <p>
* <code>componentCount</code> reflects opaque, i.e. 4 if non opaque.
* </p>
+ * @param renderer
+ * @param componentCount
+ * @param scaleMatX {@link Graphics2D} {@link Graphics2D#scale(double, double) scaling factor}, i.e. rendering 1/scaleMatX * width pixels
+ * @param scaleMatY {@link Graphics2D} {@link Graphics2D#scale(double, double) scaling factor}, i.e. rendering 1/scaleMatY * height pixels
+ * @param verbose
*/
- public AWTTilePainter(TileRenderer renderer, int componentCount, boolean verbose) {
+ public AWTTilePainter(TileRenderer renderer, int componentCount, double scaleMatX, double scaleMatY, boolean verbose) {
this.renderer = renderer;
this.renderer.setGLEventListener(preTileGLEL, postTileGLEL);
this.componentCount = componentCount;
+ this.scaleMatX = scaleMatX;
+ this.scaleMatY = scaleMatY;
this.verbose = verbose;
this.renderer.setRowOrder(TileRenderer.TR_TOP_TO_BOTTOM);
}
public String toString() { return renderer.toString(); }
- public TileRenderer getTileRenderer() { return renderer; }
-
/**
* Caches the {@link Graphics2D} instance for rendering.
* <p>
+ * Copies the current {@link Graphics2D} {@link AffineTransform}
+ * and scales {@link Graphics2D} w/ <code>scaleMatX</code> x <code>scaleMatY</code>.<br>
+ * After rendering, the {@link AffineTransform} should be reset via {@link #resetGraphics2D()}.
+ * </p>
+ * <p>
* Sets the {@link TileRenderer}'s {@link TileRenderer#setImageSize(int, int) image size}
* and {@link TileRenderer#setTileOffset(int, int) tile offset} according the
* the {@link Graphics2D#getClipBounds() graphics clip bounds}.
* </p>
* @param g2d
*/
- public void updateGraphics2DAndClipBounds(Graphics2D g2d) {
+ public void setupGraphics2DAndClipBounds(Graphics2D g2d) {
this.g2d = g2d;
+ saveAT = g2d.getTransform();
+ g2d.scale(scaleMatX, scaleMatY);
+
final Rectangle gClipOrig = g2d.getClipBounds();
final Rectangle gClip = new Rectangle(gClipOrig);
if( 0 > gClip.x ) {
@@ -106,10 +122,15 @@ public class AWTTilePainter {
if( verbose ) {
System.err.println("AWT print.0: "+gClipOrig+" -> "+gClip);
}
- renderer.setImageSize(gClip.width, gClip.height);
+ renderer.setImageSize(gClip.width, gClip.height);
renderer.setTileOffset(gClip.x, gClip.y);
}
+ /** See {@ #setupGraphics2DAndClipBounds(Graphics2D)}. */
+ public void resetGraphics2D() {
+ g2d.setTransform(saveAT);
+ }
+
/**
* Disposes resources and {@link TileRenderer#detachFromAutoDrawable() detaches}
* the {@link TileRenderer}'s {@link GLAutoDrawable}.
@@ -194,24 +215,20 @@ public class AWTTilePainter {
}
final Shape oClip = g2d.getClip();
g2d.clipRect(pX, pYf, tWidth, tHeight);
- final Shape clip = g2d.getClip();
g2d.drawImage(dstImage, pX, pYf, dstImage.getWidth(), dstImage.getHeight(), null); // Null ImageObserver since image data is ready.
- g2d.setColor(Color.BLACK);
- g2d.drawRect(pX, pYf, tWidth, tHeight);
- {
+ if( verbose ) {
+ System.err.println("XXX tile-post.X clip "+oClip+" -> "+g2d.getClip());
+ g2d.setColor(Color.BLACK);
+ g2d.drawRect(pX, pYf, tWidth, tHeight);
final Rectangle r = oClip.getBounds();
g2d.setColor(Color.YELLOW);
g2d.drawRect(r.x, r.y, r.width, r.height);
- }
- g2d.setClip(oClip);
- if( verbose ) {
- System.err.println("XXX tile-post.X clip "+oClip+" -> "+clip);
System.err.println("XXX tile-post.X "+renderer);
System.err.println("XXX tile-post.X dst-img "+dstImage.getWidth()+"x"+dstImage.getHeight()+" -> "+pX+"/"+pYf);
}
+ g2d.setClip(oClip);
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
- };
-
+ };
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
index 66be82a44..f38e7ea2b 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
@@ -69,6 +69,33 @@ public class AWTMisc {
return (Container) c;
}
+ public static interface ComponentAction {
+ /**
+ * @param c the component to perform the action on
+ */
+ public void run(Component c);
+ }
+
+ public static int performAction(Container c, Class<?> cType, ComponentAction action) {
+ int count = 0;
+ final int cc = c.getComponentCount();
+ for(int i=0; i<cc; i++) {
+ final Component e = c.getComponent(i);
+ if( e instanceof Container ) {
+ count += performAction((Container)e, cType, action);
+ } else if( cType.isInstance(e) ) {
+ action.run(e);
+ count++;
+ }
+ }
+ // we come at last ..
+ if( cType.isInstance(c) ) {
+ action.run(c);
+ count++;
+ }
+ return count;
+ }
+
/**
* Traverse to the next forward or backward component using the
* container's FocusTraversalPolicy.
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java
index 86c06247f..60ba35836 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java
@@ -66,6 +66,8 @@ import com.jogamp.opengl.util.Animator;
public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
static boolean waitForKey = false;
+ /** only when run manually .. */
+ static boolean allow600dpi = false;
static GLProfile glp;
static int width, height;
@@ -87,7 +89,7 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
public static void releaseClass() {
}
- protected void runTestGL(GLCapabilities caps, final boolean offscreenPrinting) throws InterruptedException, InvocationTargetException {
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException {
final GLCanvas glCanvas = new GLCanvas(caps);
Assert.assertNotNull(glCanvas);
Dimension glc_sz = new Dimension(width, height);
@@ -98,33 +100,33 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
final Gears gears = new Gears();
glCanvas.addGLEventListener(gears);
- final Frame frame = new Frame("AWT Print (offscr "+offscreenPrinting+")");
+ final Frame frame = new Frame("AWT Print");
Assert.assertNotNull(frame);
final ActionListener print72DPIAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
- doPrintManual(frame, glCanvas, TestTiledPrintingGearsAWT.this, offscreenPrinting, 72, false);
+ doPrintManual(frame, 72, false);
} };
- final ActionListener print150DPIAction = new ActionListener() {
+ final ActionListener print300DPIAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
- doPrintManual(frame, glCanvas, TestTiledPrintingGearsAWT.this, offscreenPrinting, 150, false);
+ doPrintManual(frame, 300, false);
} };
- final ActionListener print300DPIAction = new ActionListener() {
+ final ActionListener print600DPIAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
- doPrintManual(frame, glCanvas, TestTiledPrintingGearsAWT.this, offscreenPrinting, 300, false);
+ doPrintManual(frame, 600, false);
} };
final Button print72DPIButton = new Button("72dpi");
print72DPIButton.addActionListener(print72DPIAction);
- final Button print150DPIButton = new Button("150dpi");
- print150DPIButton.addActionListener(print150DPIAction);
final Button print300DPIButton = new Button("300dpi");
print300DPIButton.addActionListener(print300DPIAction);
+ final Button print600DPIButton = new Button("600dpi");
+ print600DPIButton.addActionListener(print600DPIAction);
frame.setLayout(new BorderLayout());
Panel printPanel = new Panel();
printPanel.add(print72DPIButton);
- printPanel.add(print150DPIButton);
printPanel.add(print300DPIButton);
+ printPanel.add(print600DPIButton);
Panel southPanel = new Panel();
southPanel.add(new Label("South"));
Panel eastPanel = new Panel();
@@ -155,22 +157,22 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
animator.setUpdateFPSFrames(60, System.err);
animator.start();
- boolean dpi72Done = false;
- boolean dpi150Done = false;
+ boolean printDone = false;
while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.getTotalFPSDuration()<duration )) {
- Thread.sleep(100);
- if( !dpi72Done ) {
- dpi72Done = true;
- doPrintAuto(frame, glCanvas, TestTiledPrintingGearsAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 72, false);
+ Thread.sleep(200);
+ if( !printDone ) {
+ printDone = true;
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 72, false);
waitUntilPrintJobsIdle();
- doPrintAuto(frame, glCanvas, TestTiledPrintingGearsAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 72, true);
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 72, true);
waitUntilPrintJobsIdle();
- } else if( !dpi150Done ) {
- dpi150Done = true;
- doPrintAuto(frame, glCanvas, TestTiledPrintingGearsAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 150, false);
- waitUntilPrintJobsIdle();
- doPrintAuto(frame, glCanvas, TestTiledPrintingGearsAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 150, true);
+ // No AA needed for 300 dpi and greater :)
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 300, false);
waitUntilPrintJobsIdle();
+ if( allow600dpi ) {
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 600, false);
+ waitUntilPrintJobsIdle();
+ }
}
}
// try { Thread.sleep(4000); } catch (InterruptedException e) { } // time to finish print jobs .. FIXME ??
@@ -197,26 +199,21 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase {
@Test
public void test01_Onscreen_aa0() throws InterruptedException, InvocationTargetException {
GLCapabilities caps = new GLCapabilities(glp);
- runTestGL(caps, false);
+ runTestGL(caps);
}
- // @Test
+ @Test
public void test02_Onscreen_aa8() throws InterruptedException, InvocationTargetException {
GLCapabilities caps = new GLCapabilities(glp);
caps.setSampleBuffers(true);
caps.setNumSamples(8); // FIXME
- runTestGL(caps, false);
- }
-
- @Test
- public void test03_Offscreen_aa0() throws InterruptedException, InvocationTargetException {
- GLCapabilities caps = new GLCapabilities(glp);
- runTestGL(caps, true);
+ runTestGL(caps);
}
static long duration = 500; // ms
public static void main(String args[]) {
+ allow600dpi = true;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
index 0f3267dc6..d63f73924 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java
@@ -69,6 +69,8 @@ import com.jogamp.opengl.util.Animator;
public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
static boolean waitForKey = false;
+ /** only when run manually .. */
+ static boolean allow600dpi = false;
static GLProfile glp;
static int width, height;
@@ -90,7 +92,7 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
public static void releaseClass() {
}
- protected void runTestGL(GLCapabilities caps, final boolean offscreenPrinting) throws InterruptedException, InvocationTargetException {
+ protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException {
final GLJPanel glJPanel = new GLJPanel(caps);
Assert.assertNotNull(glJPanel);
Dimension glc_sz = new Dimension(width, height);
@@ -101,32 +103,32 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
final Gears gears = new Gears();
glJPanel.addGLEventListener(gears);
- final JFrame frame = new JFrame("Swing Print (offscr "+offscreenPrinting+")");
+ final JFrame frame = new JFrame("Swing Print");
Assert.assertNotNull(frame);
final ActionListener print72DPIAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
- doPrintManual(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, offscreenPrinting, 72, false);
+ doPrintManual(frame, 72, false);
} };
- final ActionListener print150DPIAction = new ActionListener() {
+ final ActionListener print300DPIAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
- doPrintManual(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, offscreenPrinting, 150, false);
+ doPrintManual(frame, 300, false);
} };
- final ActionListener print300DPIAction = new ActionListener() {
+ final ActionListener print600DPIAction = new ActionListener() {
public void actionPerformed(ActionEvent e) {
- doPrintManual(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, offscreenPrinting, 300, false);
+ doPrintManual(frame, 600, false);
} };
final Button print72DPIButton = new Button("72dpi");
print72DPIButton.addActionListener(print72DPIAction);
- final Button print150DPIButton = new Button("150dpi");
- print150DPIButton.addActionListener(print150DPIAction);
final Button print300DPIButton = new Button("300dpi");
print300DPIButton.addActionListener(print300DPIAction);
+ final Button print600DPIButton = new Button("600dpi");
+ print600DPIButton.addActionListener(print600DPIAction);
final JPanel printPanel = new JPanel();
printPanel.add(print72DPIButton);
- printPanel.add(print150DPIButton);
printPanel.add(print300DPIButton);
+ printPanel.add(print600DPIButton);
final JPanel southPanel = new JPanel();
southPanel.add(new Label("South"));
final JPanel eastPanel = new JPanel();
@@ -161,22 +163,22 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
animator.start();
Assert.assertEquals(true, animator.isAnimating());
- boolean dpi72Done = false;
- boolean dpi150Done = false;
+ boolean printDone = false;
while(!quitAdapter.shouldQuit() && animator.isAnimating() && ( 0 == duration || animator.getTotalFPSDuration()<duration )) {
Thread.sleep(200);
- if( !dpi72Done ) {
- dpi72Done = true;
- doPrintAuto(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 72, false);
- waitUntilPrintJobsIdle();
- doPrintAuto(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 72, true);
+ if( !printDone ) {
+ printDone = true;
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 72, false);
waitUntilPrintJobsIdle();
- } else if( !dpi150Done ) {
- dpi150Done = true;
- doPrintAuto(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 150, false);
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 72, true);
waitUntilPrintJobsIdle();
- doPrintAuto(frame, glJPanel, TestTiledPrintingGearsSwingAWT.this, PageFormat.LANDSCAPE, null, offscreenPrinting, 150, true);
+ // No AA needed for 300 dpi and greater :)
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 300, false);
waitUntilPrintJobsIdle();
+ if( allow600dpi ) {
+ doPrintAuto(frame, PageFormat.LANDSCAPE, null, 600, false);
+ waitUntilPrintJobsIdle();
+ }
}
}
// try { Thread.sleep(4000); } catch (InterruptedException e) { } // time to finish print jobs .. FIXME ??
@@ -201,19 +203,23 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase {
}
@Test
- public void test01_Onscreen() throws InterruptedException, InvocationTargetException {
+ public void test01_Onscreen_aa0() throws InterruptedException, InvocationTargetException {
GLCapabilities caps = new GLCapabilities(glp);
- runTestGL(caps, false);
+ runTestGL(caps);
}
+
@Test
- public void test02_Offscreen() throws InterruptedException, InvocationTargetException {
+ public void test02_Onscreen_aa8() throws InterruptedException, InvocationTargetException {
GLCapabilities caps = new GLCapabilities(glp);
- runTestGL(caps, true);
+ caps.setSampleBuffers(true);
+ caps.setNumSamples(8); // FIXME
+ runTestGL(caps);
}
-
+
static long duration = 500; // ms
public static void main(String args[]) {
+ allow600dpi = true;
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
i++;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java
index 6b4742b6e..50625d48c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java
@@ -33,7 +33,6 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.Printable;
@@ -65,14 +64,10 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
public static final double A0_WIDTH_INCH = A0_WIDTH_MM / MM_PER_INCH;
public static final double A0_HEIGHT_INCH = A0_WIDTH_MM / MM_PER_INCH; */
- /** Helper to pass desired AWTPrintLifecycle ! **/
- private AWTPrintLifecycle awtPrintObject = null;
/** Helper to pass desired Frame to print! **/
private Frame frame;
- /** Helper to pass desired on- and offscreen mode ! **/
- private boolean printOffscreen = false;
/** Helper to pass desired DPI value ! **/
- private int printDPI = 72;
+ private int glDPI = 72;
/** Helper to pass desired AA hint ! **/
private boolean printAA = false;
@@ -126,94 +121,56 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
System.err.println("PF: Page orientation "+pf.getOrientation());
/**
- * We fit the frame into the imageable area with the desired DPI.
- * <p>
- * We assume AWT painting happens w/ 72 dpi!
- * </p>
+ * We fit the frame into the imageable area with for 72 dpi,
+ * assuming that is the default AWT painting density.
* <p>
* The frame borders are considered.
* </p>
+ * <p>
+ * The frame's scale factor is used for the graphics print matrix
+ * of the overall print-job, hence no frame resize is required.
+ * </p>
+ * <p>
+ * The GL scale factor 'scaleGLMatXY', 72dpi/glDPI, is passed to the GL object
+ * which locally scales the print matrix and renders the scene with 1/scaleGLMatXY pixels.
+ * </p>
*/
final Insets frameInsets = frame.getInsets();
final int frameWidth = frame.getWidth();
final int frameHeight= frame.getHeight();
- final int frameWidthS;
- final int frameHeightS;
- final double scaleComp;
+ final double scaleComp72;
{
final int frameBorderW = frameInsets.left + frameInsets.right;
final int frameBorderH = frameInsets.top + frameInsets.bottom;
final double sx = pf.getImageableWidth() / ( frameWidth + frameBorderW );
final double sy = pf.getImageableHeight() / ( frameHeight + frameBorderH );
- scaleComp = Math.min(sx, sy) * ( printDPI/72.0 );
- if( 0f < scaleComp ) {
- frameWidthS = (int) ( frameWidth*scaleComp ); // cut off FIXME
- frameHeightS = (int) ( frameHeight*scaleComp ); // cut off FIXME
- } else {
- frameWidthS = frameWidth;
- frameHeightS = frameHeight;
- }
+ scaleComp72 = Math.min(sx, sy);
}
- // Since we fit the frame size into the imageable size respecting the DPI,
- // we simply can scale the print graphics matrix to the DPI
- // w/o the need to fiddle w/ the margins (matrix translation).
- final double scaleGraphics = 72.0 / printDPI;
-
- System.err.println("PRINT offscreen: "+printOffscreen+", thread "+Thread.currentThread().getName());
- System.err.println("PRINT DPI: "+printDPI+", AA "+printAA+", scaleGraphics "+scaleGraphics+", scaleComp "+scaleComp+
- ", frame: border "+frameInsets+", size "+frameWidth+"x"+frameHeight+" -> "+frameWidthS+"x"+frameHeightS);
+ final double scaleGLMatXY = 72.0 / glDPI;
+ System.err.println("PRINT thread "+Thread.currentThread().getName());
+ System.err.println("PRINT DPI: "+glDPI+", AA "+printAA+", scaleGL "+scaleGLMatXY+", scaleComp72 "+scaleComp72+
+ ", frame: border "+frameInsets+", size "+frameWidth+"x"+frameHeight);
final Graphics2D printG2D = (Graphics2D)g;
- final Graphics2D offscreenG2D;
- final BufferedImage offscreenImage;
- final Graphics2D g2d;
- if( printOffscreen ) {
- offscreenImage = new BufferedImage(frameWidthS, frameHeightS, BufferedImage.TYPE_4BYTE_ABGR);
- offscreenG2D = (Graphics2D) offscreenImage.getGraphics();
- offscreenG2D.setClip(0, 0, frameWidthS, frameHeightS);
- g2d = offscreenG2D;
- } else {
- offscreenG2D = null;
- offscreenImage = null;
- g2d = printG2D;
+ final Graphics2D g2d = printG2D;
- g2d.translate(pf.getImageableX(), pf.getImageableY());
- g2d.scale(scaleGraphics, scaleGraphics);
- }
+ g2d.translate(pf.getImageableX(), pf.getImageableY());
+ g2d.scale(scaleComp72, scaleComp72);
+
if( printAA ) {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
- awtPrintObject.setupPrint(g2d);
+ final AWTPrintLifecycle.Context ctx = AWTPrintLifecycle.Context.setupPrint(frame, g2d, scaleGLMatXY, scaleGLMatXY);
try {
+ System.err.println("PRINT AWTPrintLifecycle.setup.count "+ctx.getCount());
AWTEDTExecutor.singleton.invoke(true, new Runnable() {
- public void run() {
- frame.setSize(frameWidthS, frameHeightS);
- frame.invalidate();
- frame.validate();
- }
- });
-
- AWTEDTExecutor.singleton.invoke(true, new Runnable() {
- public void run() {
- frame.printAll(g2d);
- } } );
-
- System.err.println("PRINT DPI: reset frame size "+frameWidth+"x"+frameHeight);
- AWTEDTExecutor.singleton.invoke(true, new Runnable() {
- public void run() {
- frame.setSize(frameWidth, frameHeight);
- frame.invalidate();
- frame.validate();
+ public void run() {
+ frame.printAll(g2d);
}
});
} finally {
- awtPrintObject.releasePrint();
- }
-
- if( printOffscreen ) {
- printG2D.translate(pf.getImageableX(), pf.getImageableY());
- printG2D.scale(scaleGraphics, scaleGraphics);
- printG2D.drawImage(offscreenImage, 0, 0, offscreenImage.getWidth(), offscreenImage.getHeight(), null); // Null ImageObserver since image data is ready.
+ ctx.releasePrint();
+ System.err.println("PRINT AWTPrintLifecycle.release.count "+ctx.getCount());
}
/* tell the caller that this page is part of the printed document */
@@ -230,8 +187,7 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
super();
}
- public void doPrintAuto(Frame frame, AWTPrintLifecycle awtPrintObject,
- Printable printable, int pOrientation, Paper paper, boolean offscreen, int dpi, boolean antialiasing) {
+ public void doPrintAuto(Frame frame, int pOrientation, Paper paper, int dpi, boolean antialiasing) {
lock.lock();
try {
final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
@@ -253,7 +209,7 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
FileOutputStream outstream;
try {
outstream = new FileOutputStream(fname);
- Assert.assertTrue(doPrintAutoImpl(frame, awtPrintObject, printable, pj, factories[0].getPrintService(outstream), pOrientation, paper, offscreen, dpi, antialiasing));
+ Assert.assertTrue(doPrintAutoImpl(frame, pj, factories[0].getPrintService(outstream), pOrientation, paper, dpi, antialiasing));
} catch (FileNotFoundException e) {
Assert.assertNull("Unexpected exception", e);
}
@@ -268,7 +224,7 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
FileOutputStream outstream;
try {
outstream = new FileOutputStream(fname);
- Assert.assertTrue(doPrintAutoImpl(frame, awtPrintObject, printable, pj, factories[0].getPrintService(outstream), pOrientation, paper, offscreen, dpi, antialiasing));
+ Assert.assertTrue(doPrintAutoImpl(frame, pj, factories[0].getPrintService(outstream), pOrientation, paper, dpi, antialiasing));
} catch (FileNotFoundException e) {
Assert.assertNull("Unexpected exception", e);
}
@@ -285,13 +241,11 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
final String sAA = antialiasing ? "aa_" : "raw";
return String.format("%-"+maxSimpleTestNameLen+"s-n%04d-dpi%03d-%s.%s", simpleTestName, printCount, dpi, sAA, suffix).replace(' ', '_');
}
- private boolean doPrintAutoImpl(Frame frame, AWTPrintLifecycle awtPrintObject,
- Printable printable, PrinterJob job, StreamPrintService ps, int pOrientation,
- Paper paper, boolean offscreen, int dpi, boolean antialiasing) {
- this.awtPrintObject = awtPrintObject;
+ private boolean doPrintAutoImpl(Frame frame, PrinterJob job,
+ StreamPrintService ps, int pOrientation, Paper paper, int dpi,
+ boolean antialiasing) {
this.frame = frame;
- printOffscreen = offscreen;
- printDPI = dpi;
+ glDPI = dpi;
printAA = antialiasing;
boolean ok = true;
try {
@@ -305,7 +259,7 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
}
pageFormat.setOrientation(pOrientation); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT
job.setPrintService(ps);
- job.setPrintable(printable, pageFormat);
+ job.setPrintable(this, pageFormat);
job.print();
} catch (PrinterException pe) {
pe.printStackTrace();
@@ -314,16 +268,14 @@ public abstract class TiledPrintingAWTBase extends UITestCase implements Printab
return ok;
}
- public void doPrintManual(Frame frame, AWTPrintLifecycle awtPrintObject, Printable printable, boolean offscreen, int dpi, boolean antialiasing) {
+ public void doPrintManual(Frame frame, int dpi, boolean antialiasing) {
lock.lock();
try {
- this.awtPrintObject = awtPrintObject;
this.frame = frame;
- printOffscreen = offscreen;
- printDPI = dpi;
+ glDPI = dpi;
printAA = antialiasing;
PrinterJob job = PrinterJob.getPrinterJob();
- job.setPrintable(printable);
+ job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {