summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-09-15 23:27:16 +0200
committerSven Gothel <[email protected]>2013-09-15 23:27:16 +0200
commitc2ce31e11eefcf1b900c0e9b41264f5d5566dc46 (patch)
tree09cc72c0b515bb18062e2bdf14f651981759f6bc /src/newt/classes
parent5a946df8fd812570826f267d4123b59d79c97cf7 (diff)
Fix AWT printing issues w/ overlapping and/or non-opaque contents ; Change AWTPrintLifecycle's lifecycle
- AWTPrintLifecycle: - Should decorate: PrinterJob.print(..), instead of within Printable.print(..) { .. container.printAll(..); .. } This is due to AWT print implementation, i.e. AWT will issue Printable.print(..) multiple times for 'overlapping' or non-opaque elements! - Move from javax.media.opengl.awt -> com.jogamp.nativewindow.awt - Make _interface_ AWT agnostic, i.e. remove Graphics2D from 'setup(..)' - Add 'int numSamples' to 'setup(..)' to determine the number of samples - AWTTilePrinter: - Use double precision when scaling image-size and clip-rect, then round them to integer values. Otherwise AWT will use the bounding box for the clipping-rectangular. - Clip negative portion of clip-rect, this removes redundant overpaints, as well as increasing the tile count due to the increased clipping-size. - Clip the image-size in the tile-renderer according to the clip-rect. - DEBUG_TILES: Dump tiles to file - Use sub-image of final BuffereImage instead of adding another clipping region. This might increase performance if no clip-rect has been set. TODO: TestTiledPrintingGearsSwingAWT overlapping tests exposes a 'off by one' bug of the first layer's background! Note: The GL content seems to be correct though - maybe it's simply an AWT rounding error ..
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java63
1 files changed, 26 insertions, 37 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index cdf47cbb3..a2d4eb7f0 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -37,7 +37,6 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.KeyboardFocusManager;
-import java.awt.RenderingHints;
import java.beans.Beans;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -53,8 +52,6 @@ import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLDrawableFactory;
-import javax.media.opengl.GLProfile;
-import javax.media.opengl.awt.AWTPrintLifecycle;
import javax.swing.MenuSelectionManager;
import jogamp.nativewindow.awt.AWTMisc;
@@ -67,6 +64,7 @@ import jogamp.opengl.awt.AWTTilePainter;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.awt.AWTEDTExecutor;
+import com.jogamp.nativewindow.awt.AWTPrintLifecycle;
import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol;
import com.jogamp.nativewindow.awt.JAWTWindow;
import com.jogamp.newt.Display;
@@ -455,13 +453,20 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
private volatile boolean printActive = false;
- private boolean printUseAA = false;
+ private int printNumSamples = 0;
private GLAnimatorControl printAnimator = null;
private GLAutoDrawable printGLAD = null;
private AWTTilePainter printAWTTiles = null;
+ private final GLAutoDrawable getGLAD() {
+ if( null != newtChild && newtChild instanceof GLAutoDrawable ) {
+ return (GLAutoDrawable)newtChild;
+ }
+ return null;
+ }
+
@Override
- public void setupPrint(Graphics2D g2d, double scaleMatX, double scaleMatY) {
+ public void setupPrint(double scaleMatX, double scaleMatY, int numSamples) {
if( !validateComponent(true) ) {
if(DEBUG) {
System.err.println(getThreadName()+": Info: NewtCanvasAWT setupPrint - skipped GL render, drawable not valid yet");
@@ -474,15 +479,17 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
return; // not yet available ..
}
- printActive = true;
- 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 );
+ final GLAutoDrawable glad = getGLAD();
+ if( null == glad ) {
+ if( DEBUG ) {
+ System.err.println("AWT print.setup exit, newtChild not a GLAutoDrawable: "+newtChild);
+ }
+ return;
}
+ printActive = true;
+ printNumSamples = AWTTilePainter.getNumSamples(numSamples, glad.getChosenGLCapabilities());
if( DEBUG ) {
- System.err.println("AWT print.setup: canvasSize "+getWidth()+"x"+getWidth()+", scaleMat "+scaleMatX+" x "+scaleMatY+", useAA "+printUseAA+", printAnimator "+printAnimator);
- AWTTilePainter.dumpHintsAndScale(g2d);
+ System.err.println("AWT print.setup: canvasSize "+getWidth()+"x"+getWidth()+", scaleMat "+scaleMatX+" x "+scaleMatY+", numSamples "+numSamples+" -> "+printNumSamples+", printAnimator "+printAnimator);
}
final int componentCount = isOpaque() ? 3 : 4;
final TileRenderer printRenderer = new TileRenderer();
@@ -492,39 +499,21 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
private final Runnable setupPrintOnEDT = new Runnable() {
@Override
public void run() {
- final GLAutoDrawable glad;
- if( null != newtChild && newtChild instanceof GLAutoDrawable ) {
- glad = (GLAutoDrawable)newtChild;
- } else {
- if( DEBUG ) {
- System.err.println("AWT print.setup exit, newtChild not a GLAutoDrawable: "+newtChild);
- }
- printAWTTiles = null;
- printActive = false;
- return;
- }
+ final GLAutoDrawable glad = getGLAD();
printAnimator = glad.getAnimator();
if( null != printAnimator ) {
printAnimator.remove(glad);
}
final GLCapabilities caps = (GLCapabilities)glad.getChosenGLCapabilities().cloneMutable();
- final GLProfile glp = caps.getGLProfile();
if( caps.getSampleBuffers() ) {
- // bug / issue w/ swapGLContextAndAllGLEventListener and onscreen MSAA w/ NV/GLX
+ // Bug 830: swapGLContextAndAllGLEventListener and onscreen MSAA w/ NV/GLX
printGLAD = glad;
} 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);
- }
+ if( printNumSamples != caps.getNumSamples() ) {
+ caps.setSampleBuffers(0 < printNumSamples);
+ caps.setNumSamples(printNumSamples);
}
final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
printGLAD = factory.createOffscreenAutoDrawable(null, caps, null, DEFAULT_PRINT_TILE_SIZE, DEFAULT_PRINT_TILE_SIZE, null);
@@ -535,7 +524,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
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 AA "+printNumSamples+", "+caps);
System.err.println("AWT print.setup "+printGLAD);
}
}
@@ -557,7 +546,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
if( DEBUG ) {
System.err.println("AWT print.release "+printAWTTiles);
}
- final GLAutoDrawable glad = (GLAutoDrawable)newtChild;
+ final GLAutoDrawable glad = getGLAD();
printAWTTiles.dispose();
printAWTTiles= null;
if( printGLAD != glad ) {