diff options
Diffstat (limited to 'src/newt/classes/com')
4 files changed, 194 insertions, 6 deletions
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java b/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java index 74dd8ebcd..2b61d34c4 100644 --- a/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java +++ b/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java @@ -9,6 +9,8 @@ public class ScreenMode { private int index; private int width; private int height; + private int bitsPerPixel = -1; + private short[] rates = null; public ScreenMode(int index, int width, int height) { @@ -16,7 +18,15 @@ public class ScreenMode { this.width = width; this.height = height; } - + /** Not safe to use this on platforms + * other than windows. Since the mode ids + * on X11 match the native ids. unlike windows + * where the ids are generated . + * @param index + */ + public void setIndex(int index) { + this.index = index; + } public int getIndex() { return index; } @@ -38,4 +48,29 @@ public class ScreenMode { public void setRates(short[] rates) { this.rates = rates; } + + public int getBitsPerPixel() { + return bitsPerPixel; + } + + public void setBitsPerPixel(int bitsPerPixel) { + this.bitsPerPixel = bitsPerPixel; + } + + public short getHighestAvailableRate(){ + short highest = rates[0]; + if(rates.length > 1){ + for (int i = 1; i < rates.length; i++) { + if(rates[i] > highest){ + highest = rates[i]; + } + } + } + return highest; + } + + public String toString() { + return "ScreenMode: " + this.index + " - " + this.width + " x " + + this.height + " " + getHighestAvailableRate() + " Hz"; + } } diff --git a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java index a0879a634..49816c79d 100644 --- a/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java +++ b/src/newt/classes/com/jogamp/newt/impl/WindowImpl.java @@ -1165,7 +1165,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer h = nfs_height; } if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+", "+screen); + System.err.println("Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()+", "+screen); } this.fullscreen = fullscreen; reconfigureWindowImpl(x, y, w, h); diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java index 5dd2689e5..3cac617ab 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java @@ -33,8 +33,13 @@ package com.jogamp.newt.impl.windows; +import java.util.ArrayList; + import com.jogamp.newt.*; import com.jogamp.newt.impl.ScreenImpl; +import com.jogamp.newt.impl.ScreenMode; +import com.jogamp.newt.impl.ScreenModeStatus; + import javax.media.nativewindow.*; public class WindowsScreen extends ScreenImpl { @@ -52,7 +57,155 @@ public class WindowsScreen extends ScreenImpl { } protected void closeNativeImpl() { } + + public int getDesktopScreenModeIndex() { + int index = super.getDesktopScreenModeIndex(); + if(index == -1) { + /** Set the current screen mode to refering to index zero + * dependent on the impl of getScreenModes which saves the + * current screen mode at index 0 which is the original screen mode + */ + ScreenMode[] screenModes = getScreenModes(); + if(screenModes != null) { + if(screenModes[0] != null) { + index = screenModes[0].getIndex(); + } + } + } + return index; + } + + public void setScreenMode(int modeIndex, short rate) { + ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN()); + ScreenMode[] screenModes = sms.getScreenModes(); + + short selectedRate = rate; + int selectedMode = modeIndex; + + if(modeIndex < 0 || (modeIndex > screenModes.length)){ + selectedMode = sms.getOriginalScreenMode(); + } + ScreenMode sm = screenModes[selectedMode]; + + if(selectedRate == -1){ + selectedRate = sms.getOriginalScreenRate(); + } + + boolean rateAvailable = false; + short[] rates = sm.getRates(); + for(int i=0;i<rates.length;i++){ + if(rates[i] == selectedRate){ + rateAvailable = true; + break; + } + } + if(!rateAvailable){ + selectedRate = rates[0]; + } + + if(0 == setScreenMode0(idx, sm.getWidth(), sm.getHeight(), sm.getBitsPerPixel(), selectedRate)){ + sms.setCurrentScreenMode(selectedMode); + sms.setCurrentScreenRate(selectedRate); + } + } + + public short getCurrentScreenRate() { + short rate = super.getCurrentScreenRate(); + if(rate == -1){ + rate = (short)getCurrentScreenRate0(idx); + } + return rate; + } + + public ScreenMode[] getScreenModes() { + ScreenMode[] screenModes = super.getScreenModes(); + if(screenModes == null) { + ArrayList smTemp = new ArrayList(); + + int modeID = -1; + ScreenMode mySM = getScreenMode(modeID++); + int currentBitsPerPixel = mySM.getBitsPerPixel(); + while(mySM != null){ + //filter out modes with diff bits per pixel + if(mySM.getBitsPerPixel() == currentBitsPerPixel) { + smTemp.add(mySM); + } + mySM = getScreenMode(modeID++); + } + int numModes = smTemp.size(); + if(numModes > 0) { + screenModes = new ScreenMode[numModes]; + for(int i=0;i<numModes;i++) { + ScreenMode sm = (ScreenMode)smTemp.get(i); + sm.setIndex(i); + screenModes[i] = sm; + } + } + } + return screenModes; + } + private ScreenMode getScreenMode(int modeIndex) { + int[] modeProp = getScreenMode0(idx, modeIndex); + if(modeProp == null){ + return null; + } + int propIndex = 0; + int width = modeProp[propIndex++]; + int height = modeProp[propIndex++]; + int bits = modeProp[propIndex++]; + short rate = (short)modeProp[propIndex++]; + + ScreenMode screenMode = new ScreenMode(modeIndex+1, width, height); + screenMode.setRates(new short[]{rate}); + screenMode.setBitsPerPixel(bits); + return screenMode; + } + + public void setScreenRotation(int rot) { + if(!isRotationValid(rot)){ + return; + } + ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN()); + if(0 == setScreenRotation0(idx, rot)) { + sms.setCurrentScreenRotation(rot); + } + } + + /** Check if this rotation is valid for platform + * @param rot user requested rotation angle + * @return true if is valid + */ + private boolean isRotationValid(int rot){ + if((rot == ScreenMode.ROTATE_0) || (rot == ScreenMode.ROTATE_90) || + (rot == ScreenMode.ROTATE_180) || (rot == ScreenMode.ROTATE_270)) { + return true; + } + return false; + } + + public int getCurrentScreenRotation() { + int rot = super.getCurrentScreenRotation(); + if(rot == -1){ + return getCurrentScreenRotation0(idx); + } + return rot; + } + + // Native calls - private native int getWidthImpl0(int scrn_idx); - private native int getHeightImpl0(int scrn_idx); + private native int getWidthImpl0(int scrn_idx); + private native int getHeightImpl0(int scrn_idx); + + private native int getCurrentScreenRate0(int scrn_idx); + private native int[] getScreenMode0(int screen_index, int mode_index); + + /** Change screen mode and return zero if successful + */ + private native int setScreenMode0(int screen_index, int width, int height, int bits, short freq); + + private native int getCurrentScreenRotation0(int screen_index); + + /** Change screen mode and return zero if successful + */ + private native int setScreenRotation0(int screen_index, int rot); } diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java index 3ade599da..d5d969023 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -157,7 +157,7 @@ public class WindowsWindow extends WindowImpl { } protected void reconfigureWindowImpl(int x, int y, int width, int height) { - reconfigureWindow0(fullscreen?0:getParentWindowHandle(), getWindowHandle(), x, y, width, height, isUndecorated()); + reconfigureWindow0(fullscreen?0:getParentWindowHandle(), getWindowHandle(), x, y, width, height, isUndecorated(), isFullscreen()); } protected boolean reparentWindowImpl() { @@ -194,7 +194,7 @@ public class WindowsWindow extends WindowImpl { private native void setSize0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height); private static native void setPosition0(long parentWindowHandle, long windowHandle, int x, int y /*, int width, int height*/); private native void reconfigureWindow0(long parentWindowHandle, long windowHandle, - int x, int y, int width, int height, boolean isUndecorated); + int x, int y, int width, int height, boolean isUndecorated, boolean fullscreen); private native void reparentWindow0(long parentWindowHandle, long windowHandle, int x, int y, int width, int height, boolean isUndecorated); private static native void setTitle0(long windowHandle, String title); private native void requestFocus0(long windowHandle, boolean reparented); |