From 29891baca2427483f96e6d1a8c3b13892ba5facc Mon Sep 17 00:00:00 2001 From: Rami Santina Date: Wed, 20 Oct 2010 16:26:45 +0300 Subject: Added Windows Impl for ScreenMode and rotation change; Windows Fullscreen Hint Added windows implemenation for screen mode change lifecycle and screen rotation screen modes. +++++++++++ Added getHighestAvailableRate() to Screen mode as a helper function which loops over the available rates of this screen mode and returns the highest available. Added toString impl to ScreenMode. +++++++++++ Unit Tests: TestScreenMode01NEWT,TestScreenMode02NEWT are modified adding the gears as GL event listeners. +++++++++++ Notes: 1- Screen modes with bits per pixel values not same as current are currently filtered out. 2- Since windows stores the Display settings differently you will see some duplicate values which the documentation says is usual. These modes are not filtered out in getScreenModes(). Keeping values same as provided from windows enum. 3- BitsPerPixel is currently natively read on windows only. --- .../classes/com/jogamp/newt/impl/ScreenMode.java | 37 ++++- .../classes/com/jogamp/newt/impl/WindowImpl.java | 2 +- .../jogamp/newt/impl/windows/WindowsScreen.java | 157 ++++++++++++++++++++- .../jogamp/newt/impl/windows/WindowsWindow.java | 4 +- 4 files changed, 194 insertions(+), 6 deletions(-) (limited to 'src/newt/classes/com') 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 0) { + screenModes = new ScreenMode[numModes]; + for(int i=0;i