From 48113ca0298ca79473dca73b85ebd4ef1a9cd078 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 6 Oct 2011 03:59:43 +0200 Subject: NEWT/Android: Move fullscreen setting to AndroidWindow ; Cleanup AndroidWindow --- .../jogamp/newt/driver/android/AndroidWindow.java | 79 +++++++++++----------- .../newt/driver/android/NewtBaseActivity.java | 41 +++++++---- 2 files changed, 67 insertions(+), 53 deletions(-) (limited to 'src/newt/classes/jogamp') 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(); -- cgit v1.2.3 From ea3d830c4f6c71ea18ebca07418567a6adf2a872 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 6 Oct 2011 04:01:41 +0200 Subject: NEWT/Android: Add BUTTON1 for one-pointer events --- .../jogamp/newt/driver/android/event/AndroidNewtEventFactory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java index 9661fc7fb..ecf1f72cd 100644 --- a/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/driver/android/event/AndroidNewtEventFactory.java @@ -28,6 +28,8 @@ package jogamp.newt.driver.android.event; +import java.awt.event.MouseEvent; + import com.jogamp.common.util.IntIntHashMap; import com.jogamp.newt.Window; @@ -163,7 +165,7 @@ public class AndroidNewtEventFactory { (null==newtSource)?null:(Object)newtSource, event.getEventTime(), modifiers , x, y, pressure, pointers, clickCount, - 0, rotation); + pointers.length==1 ? MouseEvent.BUTTON1 : 0, rotation); if(type == com.jogamp.newt.event.MouseEvent.EVENT_MOUSE_RELEASED) { com.jogamp.newt.event.MouseEvent me2 = @@ -172,7 +174,7 @@ public class AndroidNewtEventFactory { (null==newtSource)?null:(Object)newtSource, event.getEventTime(), modifiers , x, y, pressure, pointers, clickCount, - 0, rotation); + pointers.length==1 ? MouseEvent.BUTTON1 : 0, rotation); res = new com.jogamp.newt.event.MouseEvent[2]; res[0] = me1; res[1] = me2; -- cgit v1.2.3 From 6d28a9ed9ff039237775ea133377f8b59ca857c1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 6 Oct 2011 04:47:07 +0200 Subject: NEWT/Android: Add TRANSLUCENT feature / Demo: 'GearsES2T' --- .../resources/android/AndroidManifest-launcher.xml | 14 ++++ .../android/res-launcher/values/colors.xml | 6 ++ .../android/res-launcher/values/strings.xml | 2 + .../android/res-launcher/values/styles.xml | 20 ++++++ .../NEWTLauncherGearsES2TransActivity.java | 15 +++++ .../jogamp/newt/driver/android/AndroidWindow.java | 9 ++- .../opengl/test/android/NEWTGearsES2Activity.java | 2 +- .../test/android/NEWTGearsES2TransActivity.java | 75 ++++++++++++++++++++++ 8 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 make/resources/android/res-launcher/values/colors.xml create mode 100644 make/resources/android/res-launcher/values/styles.xml create mode 100644 src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2TransActivity.java create mode 100644 src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java (limited to 'src/newt/classes/jogamp') diff --git a/make/resources/android/AndroidManifest-launcher.xml b/make/resources/android/AndroidManifest-launcher.xml index 9166dd3c4..88abc8ba5 100644 --- a/make/resources/android/AndroidManifest-launcher.xml +++ b/make/resources/android/AndroidManifest-launcher.xml @@ -70,6 +70,20 @@ + + + + + + + + #ff000000 + #e0000000 + #00000000 + diff --git a/make/resources/android/res-launcher/values/strings.xml b/make/resources/android/res-launcher/values/strings.xml index f4b558df3..8b6928d9c 100644 --- a/make/resources/android/res-launcher/values/strings.xml +++ b/make/resources/android/res-launcher/values/strings.xml @@ -11,6 +11,8 @@ GearsES1 GearsES2 GearsES2 + GearsES2T + GearsES2T GraphUI1p GraphUI 1-pass GraphUI2p diff --git a/make/resources/android/res-launcher/values/styles.xml b/make/resources/android/res-launcher/values/styles.xml new file mode 100644 index 000000000..5b7eb7e2e --- /dev/null +++ b/make/resources/android/res-launcher/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2TransActivity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2TransActivity.java new file mode 100644 index 000000000..c55620f4c --- /dev/null +++ b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2TransActivity.java @@ -0,0 +1,15 @@ +package com.jogamp.android.launcher; + +public class NEWTLauncherGearsES2TransActivity extends NEWTLauncherActivity { + static String demo = "com.jogamp.opengl.test.android.NEWTGearsES2TransActivity"; + static String pkg = "com.jogamp.opengl.test"; + + @Override + public String getUserActivityName() { + return demo; + } + @Override + public String getUserPackageName() { + return pkg; + } +} diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index c5019bf63..2c7031dae 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -115,7 +115,9 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { public static int getFormat(CapabilitiesImmutable rCaps) { int fmt = PixelFormat.UNKNOWN; - if(rCaps.getRedBits()<=5 && + if(!rCaps.isBackgroundOpaque()) { + fmt = PixelFormat.TRANSLUCENT; + } else if(rCaps.getRedBits()<=5 && rCaps.getGreenBits()<=6 && rCaps.getBlueBits()<=5 && rCaps.getAlphaBits()==0) { @@ -313,7 +315,7 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { public void surfaceCreated(SurfaceHolder holder) { Log.d(MD.TAG, "surfaceCreated: "+x+"/"+y+" "+width+"x"+height); - surfaceRealized(holder); + // surfaceRealized(holder); Log.d(MD.TAG, "surfaceCreated: X"); } @@ -389,7 +391,8 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { class MSurfaceView extends SurfaceView { public MSurfaceView (Context ctx) { - super(ctx); + super(ctx); + setBackgroundDrawable(null); } } //---------------------------------------------------------------------- diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java index 164857760..939bfa210 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java @@ -54,7 +54,7 @@ public class NEWTGearsES2Activity extends NewtBaseActivity { GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); - glWindow.setFullscreen(true); + glWindow.setFullscreen(true); setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new GearsES2(1)); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java new file mode 100644 index 000000000..1862b1ba1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java @@ -0,0 +1,75 @@ +/** + * Copyright 2011 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: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.android; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import jogamp.newt.driver.android.NewtBaseActivity; + +import com.jogamp.newt.ScreenMode; +import com.jogamp.newt.event.ScreenModeListener; +import com.jogamp.newt.opengl.GLWindow; + +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.util.Animator; + +import android.os.Bundle; +import android.util.Log; + +public class NEWTGearsES2TransActivity extends NewtBaseActivity { + static String TAG = "NEWTGearsES2TransActivity"; + + @Override + public void onCreate(Bundle savedInstanceState) { + Log.d(TAG, "onCreate - 0"); + super.onCreate(savedInstanceState); + + // create GLWindow (-> incl. underlying NEWT Display, Screen & Window) + GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2)); + caps.setBackgroundOpaque(false); + Log.d(TAG, "req caps: "+caps); + GLWindow glWindow = GLWindow.create(caps); + glWindow.setFullscreen(true); + setContentView(getWindow(), glWindow); + + glWindow.addGLEventListener(new GearsES2(1)); + glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + public void screenModeChangeNotify(ScreenMode sm) { } + public void screenModeChanged(ScreenMode sm, boolean success) { + System.err.println("ScreenMode Changed: "+sm); + } + }); + glWindow.setVisible(true); + Animator animator = new Animator(glWindow); + animator.setUpdateFPSFrames(60, System.err); + setAnimator(animator); + + Log.d(TAG, "onCreate - X"); + } +} -- cgit v1.2.3 From 51f84125beb4ac50fedab9fe691225b234b12bc6 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 6 Oct 2011 05:50:55 +0200 Subject: NEWT/Window/setVisible: Remove setVisible(..) fast path - Always set visible=true, even if size==0 We need to earmark visible=true in case the native window could not be created, even if the size is currently 0. --- src/newt/classes/jogamp/newt/WindowImpl.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index f2012215e..00911443a 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -288,9 +288,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } } - // always flag visible, - // allowing to retry if visible && !isNativeValid() - visible = true; } } finally { if(null!=parentWindow) { @@ -699,6 +696,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer nativeWindowCreated = createNative(); madeVisible = nativeWindowCreated; } + // always flag visible, allowing a retry .. + WindowImpl.this.visible = true; } else if(WindowImpl.this.visible != visible) { if(isNativeValid()) { setVisibleImpl(visible, x, y, width, height); @@ -745,11 +744,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void setVisible(boolean visible) { - if( !isNativeValid() && visible && 0>=width*height ) { - // fast-path: not realized yet, make visible, but zero size - return; - } - if(DEBUG_IMPLEMENTATION) { System.err.println("Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+(null!=parentWindow)); Thread.dumpStack(); -- cgit v1.2.3 From fa7627f623141c6fa15856c74d26c8ffe82550d0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 6 Oct 2011 05:51:48 +0200 Subject: NEWT/Android: respect isUndecorated() and custom window size. TODO: custom position and change position ?! --- .../jogamp/newt/driver/android/AndroidWindow.java | 77 +++++++++++----------- .../test/android/NEWTGearsES2TransActivity.java | 4 +- 2 files changed, 43 insertions(+), 38 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index 2c7031dae..cd3cb489f 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -175,13 +175,23 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { // statement if back-porting this code to older SDKs. // sh.setType(SurfaceHolder.SURFACE_TYPE_GPU); // sh.setType(SurfaceHolder.SURFACE_TYPE_NORMAL); + + // default size -> TBD ! + this.width = 0; + this.height = 0; } public SurfaceView getAndroidView() { return androidView; } public void setAndroidWindow(android.view.Window window) { + System.err.println("setandroidWindow: "+window+", "+width+"x"+height); androidWindow = window; - androidSetupFullscreen(); + androidWindowConfigurationPreCreate(); + if(width>0 && height>0 && !isFullscreen()) { + if(null != androidWindow) { + androidWindow.setLayout(width, height); + } + } } public android.view.Window getAndroidWindow() { return androidWindow; } @@ -249,11 +259,15 @@ 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 void androidWindowConfigurationPreCreate() { + if( null != androidWindow) { + if( isFullscreen() || isUndecorated() ) { + androidWindow.requestFeature(Window.FEATURE_NO_TITLE); + } + if( isFullscreen() ) { + androidWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } } } @@ -315,8 +329,6 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { public void surfaceCreated(SurfaceHolder holder) { Log.d(MD.TAG, "surfaceCreated: "+x+"/"+y+" "+width+"x"+height); - // surfaceRealized(holder); - Log.d(MD.TAG, "surfaceCreated: X"); } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { @@ -333,43 +345,34 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { } getScreen().getCurrentScreenMode(); // if ScreenMode changed .. trigger ScreenMode event + if(0>x || 0>y) { + x = 0; + y = 0; + positionChanged(false, 0, 0); + } + if(0 == surfaceHandle) { - surfaceRealized(holder); - } else { - if(0>x || 0>y) { - x = 0; - y = 0; - positionChanged(false, 0, 0); + surface = holder.getSurface(); + surfaceHandle = getSurfaceHandle0(surface); + acquire0(surfaceHandle); + format = getSurfaceVisualID0(surfaceHandle); + capsByFormat = (GLCapabilitiesImmutable) fixCaps(format, getRequestedCapabilities()); + sizeChanged(false, getWidth0(surfaceHandle), getHeight0(surfaceHandle), false); + + Log.d(MD.TAG, "surfaceRealized: isValid: "+surface.isValid()+ + ", new surfaceHandle 0x"+Long.toHexString(surfaceHandle)+", format: "+format+ + ", "+x+"/"+y+" "+width+"x"+height+", visible: "+isVisible()); + + if(isVisible()) { + setVisible(true); } + } else { sizeChanged(false, width, height, false); } windowRepaint(0, 0, width, height); Log.d(MD.TAG, "surfaceChanged: X"); } - private void surfaceRealized(SurfaceHolder holder) { - surface = holder.getSurface(); - surfaceHandle = getSurfaceHandle0(surface); - acquire0(surfaceHandle); - format = getSurfaceVisualID0(surfaceHandle); - capsByFormat = (GLCapabilitiesImmutable) fixCaps(format, getRequestedCapabilities()); - if(0>x || 0>y) { - x = 0; - y = 0; - positionChanged(false, 0, 0); - } - sizeChanged(false, getWidth0(surfaceHandle), getHeight0(surfaceHandle), false); - - Log.d(MD.TAG, "surfaceRealized: isValid: "+surface.isValid()+ - ", new surfaceHandle 0x"+Long.toHexString(surfaceHandle)+", format: "+format+ - ", "+x+"/"+y+" "+width+"x"+height); - - if(isVisible()) { - setVisible(true); - } - Log.d(MD.TAG, "surfaceRealized: X"); - } - public void surfaceDestroyed(SurfaceHolder holder) { Log.d(MD.TAG, "surfaceDestroyed"); windowDestroyNotify(); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java index 1862b1ba1..84ff0a5a7 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java @@ -55,7 +55,9 @@ public class NEWTGearsES2TransActivity extends NewtBaseActivity { caps.setBackgroundOpaque(false); Log.d(TAG, "req caps: "+caps); GLWindow glWindow = GLWindow.create(caps); - glWindow.setFullscreen(true); + glWindow.setSize(300, 300); + // glWindow.setFullscreen(true); + glWindow.setUndecorated(true); setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new GearsES2(1)); -- cgit v1.2.3