aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-09-08 03:02:36 +0200
committerSven Gothel <[email protected]>2013-09-08 03:02:36 +0200
commit76048cd784ea6df32f19e97bb228e4ead880ea07 (patch)
tree38f86d539cfd27d8f784f767b00904342b9b42b3 /src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java
parent9b5cee85c299e72735bebbfea5c23d3c71bc704e (diff)
Test: Don't resize frame, tweek print-matrix; AWTPrintLifecycle: Add scale and convenient AWT container traversal context; GLCanvas/GLJPanel properly handle existing MSAA and req. AA;
- Test: Don't resize frame, tweek print-matrix - Use scaleComp72 to scale the frame to fit on page, i.e. global print matrix - Use scaleGLMatXY = 72.0 / glDPI to locally scale on the GL drawable as being passed to AWTPrintLifecycle.setup(..) - Hence frame stays untouched/stable, no need for 'offscreen' print test, which is removed. - AWTPrintLifecycle: Add scale and convenient AWT container traversal context Use a simple decoration for all AWTPrintLifecycle impl. components within a container: final AWTPrintLifecycle.Context ctx = AWTPrintLifecycle.Context.setupPrint(frame, g2d, scaleGLMatXY, scaleGLMatXY); try { } finally { ctx.releasePrint(); } - GLCanvas/GLJPanel properly handle existing MSAA and req. AA; - GLCanvas: Workaround bug where onscreen MSAA cannot switch to offscreen FBO, i.e. stay 'onscreen' - GLJPanel: Use new offscreen FBO if MSAA is requested and not yet used. - GLJPanel.Offscreen.postGL(): always swapBufer(), was missing for !GLSL swapping Results GLCanvas / GLJPanel: - Good scaling - Stable behavior / visibility - High DPI mode works
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java')
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/AWTPrintLifecycle.java49
1 files changed, 48 insertions, 1 deletions
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);
+ }
+ }
}