summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java20
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java74
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java11
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java21
4 files changed, 74 insertions, 52 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java
index eea9e4bed..ec584f3be 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/ScalableSurface.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2014 JogAmp Community. All rights reserved.
+ * Copyright 2014-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -39,12 +39,25 @@ public interface ScalableSurface {
public static final float AUTOMAX_PIXELSCALE = 0f;
/**
+ * Returns true if {@link #setSurfaceScale(float[])} is supported, otherwise false.
+ * <p>
+ * For pure downstream scalable surfaces like AWT widgets,
+ * setting the picel scale is not supported since the pixel scale is set by the underlying toolkit.
+ * </p>
+ */
+ public boolean canSetSurfaceScale();
+
+ /**
* Request a pixel scale in x- and y-direction for the associated {@link NativeSurface},
* where {@code size_in_pixel_units = pixel_scale * size_in_window_units}.
* <p>
* Default pixel scale request for both directions is {@link #AUTOMAX_PIXELSCALE}.
* </p>
* <p>
+ * If {@link #canSetSurfaceScale()} returns false, requested pixel scale is {@link #AUTOMAX_PIXELSCALE},
+ * immutable and method returns false.
+ * </p>
+ * <p>
* In case platform only supports uniform pixel scale, i.e. one scale for both directions,
* either {@link #AUTOMAX_PIXELSCALE} or the maximum requested pixel scale component is used.
* </p>
@@ -61,15 +74,20 @@ public interface ScalableSurface {
* @param pixelScale <i>requested</i> surface pixel scale float[2] values for x- and y-direction.
* @return {@code true} if the {@link #getCurrentSurfaceScale(float[]) current pixel scale} has changed, otherwise {@code false}.
* @see #getRequestedSurfaceScale(float[])
+ * @see #canSetSurfaceScale()
*/
public boolean setSurfaceScale(final float[] pixelScale);
/**
* Returns the {@link #setSurfaceScale(float[]) requested} pixel scale of the associated {@link NativeSurface}.
+ * <p>
+ * If {@link #canSetSurfaceScale()} returns false, requested pixel scale is {@link #AUTOMAX_PIXELSCALE} and immutable.
+ * </p>
*
* @param result float[2] storage for the result
* @return the passed storage containing the current pixelScale for chaining
* @see #setSurfaceScale(float[])
+ * @see #canSetSurfaceScale()
*/
public float[] getRequestedSurfaceScale(final float[] result);
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index 78cb58b8d..f7d4761fe 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -102,10 +102,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
protected Insets insets;
private volatile long offscreenSurfaceLayer;
- private final float[] minPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
- private final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
private final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
- private final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
private volatile boolean hasPixelScaleChanged = false;
private long drawable_old;
@@ -283,10 +280,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
insets = new Insets();
hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
- minPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
- minPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
- maxPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
- maxPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
hasPixelScaleChanged = false;
}
protected abstract void invalidateNative(final long _offscreenSurfaceLayer);
@@ -322,15 +315,36 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
return awtConfig;
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * This implementation returns false, i.e. not supporting manual change of pixel-scale.
+ * </p>
+ */
+ @Override
+ public final boolean canSetSurfaceScale() { return false; }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Ignored for an AWT widget since pixelScale is dictated by AWT mechanisms.
+ * </p>
+ */
@Override
public boolean setSurfaceScale(final float[] pixelScale) {
- System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2);
return false;
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Returns {@link ScalableSurface#AUTOMAX_PIXELSCALE}, always.
+ * </p>
+ */
@Override
public final float[] getRequestedSurfaceScale(final float[] result) {
- System.arraycopy(reqPixelScale, 0, result, 0, 2);
+ result[0] = ScalableSurface.AUTOMAX_PIXELSCALE;
+ result[1] = ScalableSurface.AUTOMAX_PIXELSCALE;
return result;
}
@@ -340,15 +354,28 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
return result;
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Returns 1.0, always.
+ * </p>
+ */
@Override
public float[] getMinimumSurfaceScale(final float[] result) {
- System.arraycopy(minPixelScale, 0, result, 0, 2);
+ result[0] = 1f;
+ result[1] = 1f;
return result;
}
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Returns {@link #getCurrentSurfaceScale(float[])}.
+ * </p>
+ */
@Override
public final float[] getMaximumSurfaceScale(final float[] result) {
- System.arraycopy(maxPixelScale, 0, result, 0, 2);
+ System.arraycopy(hasPixelScale, 0, result, 0, 2);
return result;
}
@@ -390,17 +417,15 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
* @see Component#getGraphicsConfiguration()
*/
public final boolean updatePixelScale(final GraphicsConfiguration gc, final boolean clearFlag) {
- if( JAWTUtil.getPixelScale(gc, minPixelScale, maxPixelScale) ) {
+ final float[] min = { 1, 1 };
+ final float[] max = { hasPixelScale[0], hasPixelScale[1] };
+ if( JAWTUtil.getPixelScale(gc, min, max) ) {
// Enforce maxPixelScale as used by AWT
- hasPixelScaleChanged = true;
- System.arraycopy(maxPixelScale, 0, hasPixelScale, 0, 2);
if( DEBUG ) {
- System.err.println("JAWTWindow.updatePixelScale: updated req["+
- reqPixelScale[0]+", "+reqPixelScale[1]+"], min["+
- minPixelScale[0]+", "+minPixelScale[1]+"], max["+
- maxPixelScale[0]+", "+maxPixelScale[1]+"], has["+
- hasPixelScale[0]+", "+hasPixelScale[1]+"]");
+ System.err.println("JAWTWindow.updatePixelScale: ["+hasPixelScale[0]+", "+hasPixelScale[1]+"] -> ["+max[0]+", "+max[1]+"]");
}
+ hasPixelScaleChanged = true;
+ System.arraycopy(max, 0, hasPixelScale, 0, 2);
}
if( clearFlag ) {
final boolean r = hasPixelScaleChanged;
@@ -428,15 +453,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
return v;
}
- /**
- * set requested pixelScale
- * @return true if pixelScale has changed, otherwise false
- */
- protected final boolean setReqPixelScale() {
- updatePixelScale(awtConfig.getAWTGraphicsConfiguration(), true);
- return SurfaceScaleUtils.setNewPixelScale(hasPixelScale, hasPixelScale, reqPixelScale, minPixelScale, maxPixelScale, DEBUG ? getClass().getSimpleName() : null);
- }
-
/** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds in pixel units, updated with lock */
public final RectangleImmutable getJAWTSurfaceBounds() { return jawt_surface_bounds; }
diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
index 769041f10..093625cb3 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -132,6 +132,15 @@ public class WrappedSurface extends ProxySurfaceImpl implements ScalableSurface
/**
* {@inheritDoc}
* <p>
+ * This implementation returns false, i.e. not supporting manual change of pixel-scale.
+ * </p>
+ */
+ @Override
+ public final boolean canSetSurfaceScale() { return false; }
+
+ /**
+ * {@inheritDoc}
+ * <p>
* {@link WrappedSurface}'s implementation is to simply pass the given pixelScale
* from the caller <i>down</i> to this instance without validation to be applied in the {@link #convertToPixelUnits(int[]) conversion} {@link #convertToWindowUnits(int[]) methods} <b>only</b>.<br/>
* This allows the caller to pass down knowledge about window- and pixel-unit conversion and utilize mentioned conversion methods.
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index 40fb48f33..ffd75f038 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -125,27 +125,6 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
}
@Override
- public boolean setSurfaceScale(final float[] pixelScale) {
- super.setSurfaceScale(pixelScale);
- if( 0 != getWindowHandle() && setReqPixelScale() ) { // locked at least once _and_ updated pixel-scale
- if( 0 != getAttachedSurfaceLayer() ) {
- OSXUtil.RunOnMainThread(false /* wait */, false, new Runnable() {
- @Override
- public void run() {
- final long osl = getAttachedSurfaceLayer();
- if( 0 != rootSurfaceLayer && 0 != osl ) {
- OSXUtil.SetCALayerPixelScale(rootSurfaceLayer, osl, getPixelScaleX());
- }
- }
- });
- }
- return true;
- } else {
- return false;
- }
- }
-
- @Override
protected void attachSurfaceLayerImpl(final long _offscreenSurfaceLayer) {
OSXUtil.RunOnMainThread(false /* wait */, false /* kickNSApp */, new Runnable() {
@Override