Skip to content

Commit

Permalink
Bug 1247: Align NEWT AWT driver w/ GLCanvas (not fixing any issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgothel committed Oct 9, 2015
1 parent ecdaa59 commit 108ff45
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions src/newt/classes/jogamp/newt/driver/awt/AWTCanvas.java
Expand Up @@ -60,13 +60,14 @@

@SuppressWarnings("serial")
public class AWTCanvas extends Canvas {
private GraphicsDevice device;
private GraphicsConfiguration chosen;
private AWTGraphicsConfiguration awtConfig;
private volatile JAWTWindow jawtWindow=null; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle
private CapabilitiesChooser chooser=null;
private final WindowDriver driver;
private final CapabilitiesImmutable capabilities;
private final CapabilitiesChooser chooser;
private final UpstreamScalable upstreamScale;
private GraphicsConfiguration chosen;
private volatile GraphicsDevice device;
private volatile AWTGraphicsConfiguration awtConfig;
private volatile JAWTWindow jawtWindow=null; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle

public static interface UpstreamScalable {
float[] getReqPixelScale();
Expand All @@ -75,12 +76,15 @@ public static interface UpstreamScalable {

private boolean displayConfigChanged=false;

public AWTCanvas(final CapabilitiesImmutable capabilities, final CapabilitiesChooser chooser, final UpstreamScalable upstreamScale) {
public AWTCanvas(final WindowDriver driver, final CapabilitiesImmutable capabilities, final CapabilitiesChooser chooser, final UpstreamScalable upstreamScale) {
super();

if(null==capabilities) {
throw new NativeWindowException("Capabilities null");
}
if(null==driver) {
throw new NativeWindowException("driver null");
}
this.driver = driver;
this.capabilities=capabilities;
this.chooser=chooser;
this.upstreamScale = upstreamScale;
Expand Down Expand Up @@ -117,6 +121,9 @@ public boolean hasDeviceChanged() {
@Override
public void addNotify() {

// before native peer is valid: X11
disableBackgroundErase();

/**
* 'super.addNotify()' determines the GraphicsConfiguration,
* while calling this class's overriden 'getGraphicsConfiguration()' method
Expand All @@ -134,8 +141,7 @@ public void addNotify() {
}
chosen = awtConfig.getAWTGraphicsConfiguration();

// before native peer is valid: X11
disableBackgroundErase();
setAWTGraphicsConfiguration(awtConfig);

// issues getGraphicsConfiguration() and creates the native peer
super.addNotify();
Expand All @@ -146,10 +152,13 @@ public void addNotify() {
{
jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig);
// trigger initialization cycle
jawtWindow.setSurfaceScale(upstreamScale.getReqPixelScale() );
jawtWindow.lockSurface();
upstreamScale.setHasPixelScale(jawtWindow.getCurrentSurfaceScale(new float[2]));
jawtWindow.unlockSurface();
try {
jawtWindow.setSurfaceScale(upstreamScale.getReqPixelScale() );
upstreamScale.setHasPixelScale(jawtWindow.getCurrentSurfaceScale(new float[2]));
} finally {
jawtWindow.unlockSurface();
}
}

final GraphicsConfiguration gc = super.getGraphicsConfiguration();
Expand All @@ -170,8 +179,20 @@ public boolean isOffscreenLayerSurfaceEnabled() {
return null != jawtWindow ? jawtWindow.isOffscreenLayerSurfaceEnabled() : false;
}

private void setAWTGraphicsConfiguration(final AWTGraphicsConfiguration config) {
// Cache awtConfig
awtConfig = config;
if( null != jawtWindow ) {
// Notify JAWTWindow ..
jawtWindow.setAWTGraphicsConfiguration(config);
}
}

@Override
public void removeNotify() {
if(Window.DEBUG_IMPLEMENTATION) {
System.err.println(getThreadName()+": AWTCanvas.removeNotify.0: Created Config: "+awtConfig);
}
try {
dispose();
} finally {
Expand All @@ -198,6 +219,7 @@ private void dispose() {
System.err.println(getThreadName()+": AWTCanvas.dispose(): closed GraphicsDevice: "+adeviceMsg+", result: "+closed);
}
}
awtConfig = null;
}

private String getThreadName() { return Thread.currentThread().getName(); }
Expand Down Expand Up @@ -255,18 +277,18 @@ public GraphicsConfiguration getGraphicsConfiguration() {
* block, both devices should have the same visual list, and the
* same configuration should be selected here.
*/
final AWTGraphicsConfiguration config = chooseGraphicsConfiguration(
final AWTGraphicsConfiguration newConfig = chooseGraphicsConfiguration(
awtConfig.getChosenCapabilities(), awtConfig.getRequestedCapabilities(), chooser, gc.getDevice());
final GraphicsConfiguration compatible = (null!=config)?config.getAWTGraphicsConfiguration():null;
final GraphicsConfiguration compatible = (null!=newConfig)?newConfig.getAWTGraphicsConfiguration():null;
if(Window.DEBUG_IMPLEMENTATION) {
final Exception e = new Exception("Info: Call Stack: "+Thread.currentThread().getName());
e.printStackTrace();
System.err.println("Created Config (n): HAVE GC "+chosen);
System.err.println("Created Config (n): THIS GC "+gc);
System.err.println("Created Config (n): Choosen GC "+compatible);
System.err.println("Created Config (n): HAVE CF "+awtConfig);
System.err.println("Created Config (n): Choosen CF "+config);
System.err.println("Created Config (n): EQUALS CAPS "+config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities()));
System.err.println("Created Config (n): Choosen CF "+newConfig);
System.err.println("Created Config (n): EQUALS CAPS "+newConfig.getChosenCapabilities().equals(awtConfig.getChosenCapabilities()));
}

if (compatible != null) {
Expand All @@ -275,10 +297,10 @@ public GraphicsConfiguration getGraphicsConfiguration() {
* any outside callers of this method.
*/
chosen = compatible;
if( !config.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())) {
if( !newConfig.getChosenCapabilities().equals(awtConfig.getChosenCapabilities())) {
displayConfigChanged=true;
}
awtConfig = config;
setAWTGraphicsConfiguration(newConfig);
}
}

Expand Down

0 comments on commit 108ff45

Please sign in to comment.