diff options
author | Sven Gothel <[email protected]> | 2011-10-06 03:59:43 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-06 03:59:43 +0200 |
commit | 48113ca0298ca79473dca73b85ebd4ef1a9cd078 (patch) | |
tree | 498277e390e252bf11b15b2789fea430a1f7aede /src/newt/classes/jogamp | |
parent | fc67b7c48a7d0280c44012d5daec04f227bcf0fa (diff) |
NEWT/Android: Move fullscreen setting to AndroidWindow ; Cleanup AndroidWindow
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java | 79 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java | 41 |
2 files changed, 67 insertions, 53 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index b9301b05a..c5019bf63 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -57,6 +57,8 @@ import android.view.SurfaceHolder; import android.view.SurfaceHolder.Callback2; import android.view.SurfaceView; import android.view.View; +import android.view.Window; +import android.view.WindowManager; public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { static { @@ -113,24 +115,19 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { public static int getFormat(CapabilitiesImmutable rCaps) { int fmt = PixelFormat.UNKNOWN; - /* - if(rCaps.getAlphaBits()==0) { - fmt = PixelFormat.RGB_565; - } else { - fmt = PixelFormat.RGBA_5551; - } */ if(rCaps.getRedBits()<=5 && rCaps.getGreenBits()<=6 && rCaps.getBlueBits()<=5 && rCaps.getAlphaBits()==0) { fmt = PixelFormat.RGB_565; - } else - if(rCaps.getRedBits()<=5 && + } + /* else if(rCaps.getRedBits()<=5 && rCaps.getGreenBits()<=5 && rCaps.getBlueBits()<=5 && rCaps.getAlphaBits()==1) { fmt = PixelFormat.RGBA_5551; // FIXME: Supported ? - } else { + } */ + else { fmt = PixelFormat.RGBA_8888; } Log.d(MD.TAG, "getFormat: requested: "+rCaps); @@ -159,28 +156,32 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { @Override protected void instantiationFinished() { - nsv = new MSurfaceView(jogamp.common.os.android.StaticContext.getContext()); + androidView = new MSurfaceView(jogamp.common.os.android.StaticContext.getContext()); AndroidEvents ae = new AndroidEvents(); - nsv.setOnTouchListener(ae); - nsv.setClickable(false); + androidView.setOnTouchListener(ae); + androidView.setClickable(false); // nsv.setOnKeyListener(ae); - SurfaceHolder sh = nsv.getHolder(); + SurfaceHolder sh = androidView.getHolder(); sh.addCallback(this); // setFormat is done by SurfaceView in SDK 2.3 and newer. Uncomment // this statement if back-porting to 2.2 or older: // sh.setFormat(PixelFormat.RGB_565); - // sh.setFormat(getPixelFormat(requestedCaps)); // n/a at this moment // sh.setFormat(PixelFormat.RGBA_5551); // sh.setFormat(PixelFormat.RGBA_8888); + sh.setFormat(getFormat(getRequestedCapabilities())); // setType is not needed for SDK 2.0 or newer. Uncomment this // statement if back-porting this code to older SDKs. - sh.setFormat(getFormat(getRequestedCapabilities())); // sh.setType(SurfaceHolder.SURFACE_TYPE_GPU); // sh.setType(SurfaceHolder.SURFACE_TYPE_NORMAL); } - - public SurfaceView getView() { return nsv; } + public SurfaceView getAndroidView() { return androidView; } + + public void setAndroidWindow(android.view.Window window) { + androidWindow = window; + androidSetupFullscreen(); + } + public android.view.Window getAndroidWindow() { return androidWindow; } @Override protected boolean canCreateNativeImpl() { @@ -202,12 +203,9 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) getScreen().getDisplay().getGraphicsDevice(); - // final EGLGraphicsConfiguration eglConfig = (EGLGraphicsConfiguration) GraphicsConfigurationFactory.getFactory(eglDevice) - // .chooseGraphicsConfiguration(capsByFormat, getRequestedCapabilities(), capabilitiesChooser, getScreen().getGraphicsScreen()); final EGLGraphicsConfiguration eglConfig = EGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capsByFormat, (GLCapabilitiesImmutable) getRequestedCapabilities(), - (GLCapabilitiesChooser)capabilitiesChooser, getScreen().getGraphicsScreen(), - format); // JAU FIXME: filter out by android visualID ?? + (GLCapabilitiesChooser)capabilitiesChooser, getScreen().getGraphicsScreen(), format); if (eglConfig == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } @@ -219,8 +217,9 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { ", error 0x"+Integer.toHexString(EGL.eglGetError())); } Log.d(MD.TAG, "nativeVisualID 0x"+Integer.toHexString(nativeVisualID.get(0))); - // JAU FIXME - setSurfaceVisualID0(surfaceHandle, nativeVisualID.get(0)); + if(nativeVisualID.get(0)>0) { + setSurfaceVisualID0(surfaceHandle, nativeVisualID.get(0)); + } eglSurface = EGL.eglCreateWindowSurface(eglDevice.getHandle(), eglConfig.getNativeConfig(), surfaceHandle, null); if (EGL.EGL_NO_SURFACE==eglSurface) { @@ -248,14 +247,18 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { protected void requestFocusImpl(boolean reparented) { } + protected void androidSetupFullscreen() { + if( null != androidWindow && isFullscreen() ) { + androidWindow.requestFeature(Window.FEATURE_NO_TITLE); + androidWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + } + protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) { - if(0!=getWindowHandle()) { - if( 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) { - if( 0 != ( FLAG_IS_FULLSCREEN & flags) ) { - System.err.println("reconfigureWindowImpl.setFullscreen n/a"); - return false; - } - } + if( 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) { + System.err.println("reconfigureWindowImpl.setFullscreen post creation (setContentView()) n/a"); + return false; } if(width>0 || height>0) { if(0!=getWindowHandle()) { @@ -273,7 +276,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { return true; } - /*** + /** Canvas cLock = null; @Override @@ -347,6 +350,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { surfaceHandle = getSurfaceHandle0(surface); acquire0(surfaceHandle); format = getSurfaceVisualID0(surfaceHandle); + capsByFormat = (GLCapabilitiesImmutable) fixCaps(format, getRequestedCapabilities()); if(0>x || 0>y) { x = 0; y = 0; @@ -358,10 +362,6 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { ", new surfaceHandle 0x"+Long.toHexString(surfaceHandle)+", format: "+format+ ", "+x+"/"+y+" "+width+"x"+height); - capsByFormat = (GLCapabilitiesImmutable) fixCaps(format, getRequestedCapabilities()); - // capsByFormat = (GLCapabilitiesImmutable) fixCapsAlpha(getRequestedCapabilities()); - // capsByFormat = (GLCapabilitiesImmutable) getRequestedCapabilities(); - if(isVisible()) { setVisible(true); } @@ -379,17 +379,17 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } - private MSurfaceView nsv; + private MSurfaceView androidView; + private android.view.Window androidWindow; private int format; // stored current PixelFormat private GLCapabilitiesImmutable capsByFormat; // fixed requestedCaps by PixelFormat private Surface surface = null; private volatile long surfaceHandle = 0; private long eglSurface = 0; - static class MSurfaceView extends SurfaceView { + class MSurfaceView extends SurfaceView { public MSurfaceView (Context ctx) { - super(ctx); - + super(ctx); } } //---------------------------------------------------------------------- @@ -403,5 +403,4 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { protected static native int getHeight0(long surfaceHandle); protected static native void acquire0(long surfaceHandle); protected static native void release0(long surfaceHandle); - } diff --git a/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java b/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java index 9a2a0ea2c..5e5b90770 100644 --- a/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java +++ b/src/newt/classes/jogamp/newt/driver/android/NewtBaseActivity.java @@ -40,7 +40,7 @@ import android.os.Bundle; import android.util.Log; public class NewtBaseActivity extends Activity { - AndroidWindow window = null; + AndroidWindow newtWindow = null; Animator animator = null; boolean isInvokedByExternalActivity = false; @@ -54,25 +54,39 @@ public class NewtBaseActivity extends Activity { return null != extActivity; } - public void setContentView(Window window) { - if(window instanceof GLWindow) { - window = ((GLWindow)window).getWindow(); + public Activity getActivity() { + if(isInvokedByExternalActivity) { + return extActivity; + } else { + return this; + } + } + + public void setContentView(android.view.Window androidWindow, Window newtWindow) { + if(newtWindow instanceof GLWindow) { + newtWindow = ((GLWindow)newtWindow).getWindow(); } - if(window instanceof AndroidWindow) { - this.window = (AndroidWindow)window; + if(newtWindow instanceof AndroidWindow) { + this.newtWindow = (AndroidWindow)newtWindow; + this.newtWindow.setAndroidWindow(androidWindow); if(isInvokedByExternalActivity) { - extActivity.setContentView(this.window.getView()); + extActivity.setContentView(this.newtWindow.getAndroidView()); } else { - super.setContentView(this.window.getView()); + super.setContentView(this.newtWindow.getAndroidView()); } } else { - throw new IllegalArgumentException("Given NEWT Window is not an Android Window: "+window.getClass()); + throw new IllegalArgumentException("Given NEWT Window is not an Android Window: "+newtWindow.getClass()); } } public void setAnimator(Animator animator) { this.animator = animator; } + + @Override + public android.view.Window getWindow() { + return getActivity().getWindow(); + } @Override public void onCreate(Bundle savedInstanceState) { @@ -83,7 +97,8 @@ public class NewtBaseActivity extends Activity { jogamp.common.os.android.StaticContext.setContext(getApplicationContext()); } else { jogamp.common.os.android.StaticContext.setContext(extActivity.getApplicationContext()); - } + } + extActivity.getWindow(); // init GLProfile GLProfile.initSingleton(true); @@ -142,9 +157,9 @@ public class NewtBaseActivity extends Activity { animator.stop(); animator = null; } - if(null != window) { - window.destroy(); - window = null; + if(null != newtWindow) { + newtWindow.destroy(); + newtWindow = null; } if(!isInvokedByExternalActivity) { super.onDestroy(); |