summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com/jogamp
diff options
context:
space:
mode:
authorRami Santina <[email protected]>2010-10-18 23:06:50 +0300
committerRami Santina <[email protected]>2010-10-18 23:06:50 +0300
commitc74be6eeeb273cd7530ac7e94c3128cb5fa1e420 (patch)
treeac8169f6f4e6a5116ba3dedc67abf66df7a5d24e /src/newt/classes/com/jogamp
parent735ebb60ead9996106dfcb958ddfbb6b00b407fd (diff)
Added Screen Rotation manipulation API (with X11 impl)
Added screen rotation change capability with impl for X11 (using Xrandr) com.jogamp.newt.Screen: added 2 methods which cover screen roation lifecycle setScreenRotation(int rot): Change the Screen Rotation to one of the rotations defined in ScreenMode, namely: ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270 int getCurrentScreenRotation(): Get the Current screen rotation returns -1 if not implemented natively. +++++++++++++++++++++++++ Notes: 1- At init the original rotation is called natively and cached, when screen is destroyed the rotation is reverted. 2- On X11 with Nvidia: you need to edit /etc/X11/xorg.conf: Add the following line: Option "RandRRotation" "on" in Section "Device" after BoardName. +++++++++++++++ Added TestScreenMode02NEWT which includes 4 tests 1- Rotate 90 2- Rotate 180 3- Rotate 270 4- Rotate with screen mode change should fail if screen rotation not implemented natively. (4) withh fail if screen mode not impl natively as well.
Diffstat (limited to 'src/newt/classes/com/jogamp')
-rw-r--r--src/newt/classes/com/jogamp/newt/Screen.java13
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java22
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenMode.java5
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java25
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java36
5 files changed, 94 insertions, 7 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java
index 14de2f0da..ab4b9f0b4 100644
--- a/src/newt/classes/com/jogamp/newt/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/Screen.java
@@ -30,8 +30,6 @@ package com.jogamp.newt;
import com.jogamp.newt.impl.Debug;
import com.jogamp.newt.impl.ScreenMode;
-import com.jogamp.newt.impl.ScreensModeState;
-
import javax.media.nativewindow.AbstractGraphicsScreen;
public interface Screen {
@@ -101,4 +99,15 @@ public interface Screen {
* @param rate the desired rate should be one of the available rates.
*/
void setScreenMode(int modeIndex, short rate);
+
+ /** Change the Screen Rotation to
+ * one of the rotations defined in ScreenMode
+ * @param rot rotation id, example ScreenMode.ROTATE_0
+ */
+ public void setScreenRotation(int rot);
+
+ /** Get the Current screen rotation
+ * returns -1 if not implemented natively
+ */
+ public int getCurrentScreenRotation();
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java
index 793c278a1..4535213da 100644
--- a/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java
+++ b/src/newt/classes/com/jogamp/newt/impl/ScreenImpl.java
@@ -122,7 +122,7 @@ public abstract class ScreenImpl implements Screen {
String screenFQN = display.getFQName()+idx;
setScreenFQN(screenFQN);
ScreenModeStatus screenModeStatus = new ScreenModeStatus(screenFQN ,
- getDesktopScreenModeIndex(), getCurrentScreenRate());
+ getDesktopScreenModeIndex(), getCurrentScreenRate(),getCurrentScreenRotation());
screenModeStatus.setScreenModes(screenModes);
screensModeState.setScreenModeController(screenModeStatus);
@@ -130,6 +130,7 @@ public abstract class ScreenImpl implements Screen {
private void resetScreenMode() {
ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN());
+
/**Revert the screen mode and rate
* to original state of creation
*/
@@ -137,6 +138,12 @@ public abstract class ScreenImpl implements Screen {
setScreenMode(sms.getOriginalScreenMode(),
sms.getOriginalScreenRate());
}
+ /**Revert Screen Rotation
+ * to original value
+ */
+ if(!sms.isOriginalRotation()) {
+ setScreenRotation(sms.getOriginalScreenRotation());
+ }
}
public synchronized final void destroy() {
@@ -219,6 +226,19 @@ public abstract class ScreenImpl implements Screen {
return -1;
}
+
+ public void setScreenRotation(int rot) {
+
+ }
+
+ public int getCurrentScreenRotation() {
+ ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN());
+ if(sms != null) {
+ return sms.getCurrentScreenRotation();
+ }
+ return -1;
+ }
+
/** get the screens mode state handler
* which contain the screen mode controller of each screen
* @return the ScreensModeState static object
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java b/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java
index 22ed07250..74dd8ebcd 100644
--- a/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java
+++ b/src/newt/classes/com/jogamp/newt/impl/ScreenMode.java
@@ -1,6 +1,11 @@
package com.jogamp.newt.impl;
public class ScreenMode {
+ public static final int ROTATE_0 = 0;
+ public static final int ROTATE_90 = 90;
+ public static final int ROTATE_180 = 180;
+ public static final int ROTATE_270 = 270;
+
private int index;
private int width;
private int height;
diff --git a/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java b/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java
index b5b95da6a..2ea77c33e 100644
--- a/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java
+++ b/src/newt/classes/com/jogamp/newt/impl/ScreenModeStatus.java
@@ -6,18 +6,34 @@ public class ScreenModeStatus {
private int currentScreenMode = -1;
private short currentScreenRate = -1;
-
+ private int currentScreenRotation = -1;
+
private int originalScreenMode = -1;
private short originalScreenRate = -1;
+ private int originalScreenRotation = -1;
public ScreenModeStatus(String screenFQN, int originalScreenMode,
- short originalScreenRate) {
+ short originalScreenRate, int originalScreenRotation) {
this.screenFQN = screenFQN;
this.originalScreenMode = originalScreenMode;
this.originalScreenRate = originalScreenRate;
+ this.originalScreenRotation = originalScreenRotation;
this.currentScreenMode = originalScreenMode;
this.currentScreenRate = originalScreenRate;
+ this.currentScreenRotation = originalScreenRotation;
+ }
+
+ public void setCurrentScreenRotation(int currentScreenRotation) {
+ this.currentScreenRotation = currentScreenRotation;
+ }
+
+ public int getCurrentScreenRotation() {
+ return currentScreenRotation;
+ }
+
+ public int getOriginalScreenRotation() {
+ return originalScreenRotation;
}
public int getCurrentScreenMode() {
@@ -57,6 +73,11 @@ public class ScreenModeStatus {
return true;
return false;
}
+ public boolean isOriginalRotation(){
+ if(currentScreenRotation == originalScreenRotation)
+ return true;
+ return false;
+ }
public int getOriginalScreenMode() {
return originalScreenMode;
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
index 79ccf5a7d..f01ffdea4 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
@@ -98,7 +98,7 @@ public class X11Screen extends ScreenImpl {
}
- setScreenMode0(display.getHandle(), idx, selectedMode, selectedRate);
+ setScreenMode0(display.getHandle(), idx, selectedMode, selectedRate, getCurrentScreenRotation());
sms.setCurrentScreenMode(selectedMode);
sms.setCurrentScreenRate(selectedRate);
}
@@ -145,6 +145,35 @@ public class X11Screen extends ScreenImpl {
return screenMode;
}
+ public void setScreenRotation(int rot) {
+ if(!isRotationValid(rot)){
+ return;
+ }
+ ScreenModeStatus sms = screensModeState.getScreenModeController(getScreenFQN());
+ setScreenRotation0(display.getHandle(), 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 rotation = super.getCurrentScreenRotation();
+ if(rotation == -1){
+ rotation = getCurrentScreenRotation0(display.getHandle(), idx);
+ }
+ return rotation;
+ }
+
//----------------------------------------------------------------------
// Internals only
//
@@ -156,7 +185,10 @@ public class X11Screen extends ScreenImpl {
private native int getDesktopScreenModeIndex0(long display, int screen_index);
private native short getCurrentScreenRate0(long display, int screen_index);
- private native void setScreenMode0(long display, int screen_index, int mode_index, short freq);
+ private native int getCurrentScreenRotation0(long display, int screen_index);
+ private native void setScreenRotation0(long display, int screen_index, int rot);
+
+ private native void setScreenMode0(long display, int screen_index, int mode_index, short freq, int rot);
private native int[] getScreenMode0(long display, int screen_index, int mode_index);
private native int getNumScreenModes0(long display, int screen_index);