diff options
author | Sven Gothel <[email protected]> | 2013-01-20 15:05:02 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-01-20 15:05:02 +0100 |
commit | 85d70b7d38885fa8ba6374aa790d5a296acc8ec1 (patch) | |
tree | 7aaf7d638fad47252695cc55894a6f3404d14b45 /src/newt | |
parent | 0989484b89535d56e9f150cdf63e2a17bf36e32e (diff) |
Android: Allow selection of native window formats RGBA8888, RGBX8888 and RGB565; Fix HiSilicon/Vivante/Immersion.16 EGLConfig selection (zero depth buffer @ visualID)
- NEWT/Android Fix PixelFormat/NativeWindowFormat/VisualID Selection
- Fix allows proper selection of native window formats: RGBA8888, RGBX8888 and RGB565
- Selection is performed in 3 steps:
1) @ Construction (non native): SurfaceHolder.setFormat( getSurfaceHolderFormat( caps ) )
2) @ Native Surface Creation: getANativeWindowFormat( androidFormat) -> ANativeWindow_setBuffersGeometry(..)
Note: The set native format is revalidated, i.e. read out via ANativeWindow_getFormat(..).
3) @ EGL Creation: ANativeWindow_getFormat(..) -> fixCaps(..) - simply fixing the chosen caps.
- NEWT GLWindow.GLLifecycleHook.resetCounter:
- Also reset GLAnimatorControl's counter, if attached.
- NEWT WindowImpl -> GLLifecycleHook.resetCounter() calls issued _after_ operation before unlock().
- JOGL/EGLGraphicsConfigurationFactory
- Validate whether the visualID matching EGLConfig depth buffer is suitable.
On HiSilicon/Vivante/Immersion.16: Depth buffer w/ matching visualID is zero!
- NativeWindow/Capabilities.compareTo: Fix alpha comparison
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/opengl/GLWindow.java | 4 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 14 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/android/WindowDriver.java | 128 |
3 files changed, 98 insertions, 48 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 73a4134bd..96d0f6e3b 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -443,6 +443,10 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind System.err.println("GLWindow.resetCounter() "+WindowImpl.getThreadName()); } GLWindow.this.resetFPSCounter(); + final GLAnimatorControl animator = GLWindow.this.getAnimator(); + if( null != animator ) { + animator.resetFPSCounter(); + } } @Override diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 89c3bada6..88fbfc951 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -707,10 +707,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer final RecursiveLock _lock = windowLock; _lock.lock(); try { - if(null!=lifecycleHook) { - lifecycleHook.resetCounter(); - } - if(!visible && null!=childWindows && childWindows.size()>0) { synchronized(childWindowsLock) { for(int i = 0; i < childWindows.size(); i++ ) { @@ -756,6 +752,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer System.err.println("Window setVisible: END ("+getThreadName()+") "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight()+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+WindowImpl.this.visible+", nativeWindowCreated: "+nativeWindowCreated+", madeVisible: "+madeVisible); } } finally { + if(null!=lifecycleHook) { + lifecycleHook.resetCounter(); + } _lock.unlock(); } if( nativeWindowCreated || madeVisible ) { @@ -1014,10 +1013,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer System.err.println("Window.reparent: START ("+getThreadName()+") valid "+isNativeValid()+", windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+", visible "+wasVisible+", old parentWindow: "+Display.hashCodeNullSafe(parentWindow)+", new parentWindow: "+Display.hashCodeNullSafe(newParentWindow)+", forceDestroyCreate "+forceDestroyCreate+", "+x+"/"+y+" "+width+"x"+height); } - if(null!=lifecycleHook) { - lifecycleHook.resetCounter(); - } - if(null!=newParentWindow) { // reset position to 0/0 within parent space x = 0; @@ -1211,6 +1206,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer System.err.println("Window.reparentWindow: END-1 ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+ Display.hashCodeNullSafe(parentWindow)+" "+getX()+"/"+getY()+" "+getWidth()+"x"+getHeight()); } } finally { + if(null!=lifecycleHook) { + lifecycleHook.resetCounter(); + } _lock.unlock(); } if(wasVisible) { diff --git a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java index ba5d09759..a85febca0 100644 --- a/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/android/WindowDriver.java @@ -71,6 +71,82 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { DisplayDriver.initSingleton(); } + /** + * First stage of selecting an Android PixelFormat, + * at construction via {@link SurfaceHolder#setFormat(int)} + * before native realization! + * + * @param rCaps requested Capabilities + * @return An Android PixelFormat number suitable for {@link SurfaceHolder#setFormat(int)}. + */ + public static final int getSurfaceHolderFormat(CapabilitiesImmutable rCaps) { + int fmt = PixelFormat.UNKNOWN; + + if( !rCaps.isBackgroundOpaque() ) { + fmt = PixelFormat.TRANSLUCENT; + } else if( rCaps.getRedBits()<=5 && + rCaps.getGreenBits()<=6 && + rCaps.getBlueBits()<=5 && + rCaps.getAlphaBits()==0 ) { + fmt = PixelFormat.RGB_565; + } else if( rCaps.getAlphaBits()==0 ) { + fmt = PixelFormat.RGB_888; + } else { + fmt = PixelFormat.RGBA_8888; + } + Log.d(MD.TAG, "getSurfaceHolderFormat: requested: "+rCaps); + Log.d(MD.TAG, "getSurfaceHolderFormat: returned: "+fmt); + + return fmt; + } + + + public static final int NATIVE_WINDOW_FORMAT_RGBA_8888 = 1; + public static final int NATIVE_WINDOW_FORMAT_RGBX_8888 = 2; + public static final int NATIVE_WINDOW_FORMAT_RGB_565 = 4; + + /** + * Second stage of selecting an Android PixelFormat, + * at right after native (surface) realization at {@link Callback2#surfaceChanged(SurfaceHolder, int, int, int)}. + * Selection happens via {@link #setSurfaceVisualID0(long, int)} before native EGL creation. + * + * @param androidPixelFormat An Android PixelFormat delivered via {@link Callback2#surfaceChanged(SurfaceHolder, int, int, int)} params. + * @return A native Android PixelFormat number suitable for {@link #setSurfaceVisualID0(long, int)}. + */ + public static final int getANativeWindowFormat(int androidPixelFormat) { + final int nativePixelFormat; + switch(androidPixelFormat) { + case PixelFormat.RGBA_8888: + case PixelFormat.RGBA_5551: + case PixelFormat.RGBA_4444: + nativePixelFormat = NATIVE_WINDOW_FORMAT_RGBA_8888; + break; + + case PixelFormat.RGBX_8888: + case PixelFormat.RGB_888: + nativePixelFormat = NATIVE_WINDOW_FORMAT_RGBX_8888; + break; + + case PixelFormat.RGB_565: + case PixelFormat.RGB_332: + nativePixelFormat = NATIVE_WINDOW_FORMAT_RGB_565; + break; + default: nativePixelFormat = NATIVE_WINDOW_FORMAT_RGBA_8888; + } + Log.d(MD.TAG, "getANativeWindowFormat: android: "+androidPixelFormat+" -> native "+nativePixelFormat); + return nativePixelFormat; + } + + /** + * Final stage of Android PixelFormat operation, + * match the requested Capabilities w/ Android PixelFormat number. + * This is done at native realization @ {@link Callback2#surfaceChanged(SurfaceHolder, int, int, int)}. + * + * @param matchFormatPrecise + * @param format + * @param rCaps requested Capabilities + * @return The fixed Capabilities + */ public static final CapabilitiesImmutable fixCaps(boolean matchFormatPrecise, int format, CapabilitiesImmutable rCaps) { PixelFormat pf = new PixelFormat(); PixelFormat.getPixelFormatInfo(format, pf); @@ -78,10 +154,10 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { int r, g, b, a; switch(format) { - case PixelFormat.RGBA_8888: r=8; g=8; b=8; a=8; break; - case PixelFormat.RGBX_8888: r=8; g=8; b=8; a=0; break; + case PixelFormat.RGBA_8888: r=8; g=8; b=8; a=8; break; // NATIVE_WINDOW_FORMAT_RGBA_8888 + case PixelFormat.RGBX_8888: r=8; g=8; b=8; a=0; break; // NATIVE_WINDOW_FORMAT_RGBX_8888 case PixelFormat.RGB_888: r=8; g=8; b=8; a=0; break; - case PixelFormat.RGB_565: r=5; g=6; b=5; a=0; break; + case PixelFormat.RGB_565: r=5; g=6; b=5; a=0; break; // NATIVE_WINDOW_FORMAT_RGB_565 case PixelFormat.RGBA_5551: r=5; g=5; b=5; a=1; break; case PixelFormat.RGBA_4444: r=4; g=4; b=4; a=4; break; case PixelFormat.RGB_332: r=3; g=3; b=2; a=0; break; @@ -110,32 +186,6 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { return res; } - public static final int getFormat(CapabilitiesImmutable rCaps) { - int fmt = PixelFormat.UNKNOWN; - - if(!rCaps.isBackgroundOpaque()) { - fmt = PixelFormat.TRANSLUCENT; - } else if(rCaps.getRedBits()<=5 && - rCaps.getGreenBits()<=6 && - rCaps.getBlueBits()<=5 && - rCaps.getAlphaBits()==0) { - fmt = PixelFormat.RGB_565; - } - /* else if(rCaps.getRedBits()<=5 && - rCaps.getGreenBits()<=5 && - rCaps.getBlueBits()<=5 && - rCaps.getAlphaBits()==1) { - fmt = PixelFormat.RGBA_5551; // FIXME: Supported ? - } */ - else { - fmt = PixelFormat.RGBA_8888; - } - Log.d(MD.TAG, "getFormat: requested: "+rCaps); - Log.d(MD.TAG, "getFormat: returned: "+fmt); - - return fmt; - } - public static final boolean isAndroidFormatTransparent(int aFormat) { switch (aFormat) { case PixelFormat.TRANSLUCENT: @@ -195,12 +245,7 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { final SurfaceHolder sh = androidView.getHolder(); sh.addCallback(WindowDriver.this); - sh.setFormat(getFormat(getRequestedCapabilities())); - } - private final void removeAndroidView() { - final SurfaceHolder sh = androidView.getHolder(); - sh.removeCallback(WindowDriver.this); - androidView = null; + sh.setFormat(getSurfaceHolderFormat(getRequestedCapabilities())); } public final SurfaceView getAndroidView() { return androidView; } @@ -287,6 +332,8 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { } final int nativeVisualID = eglConfig.getVisualID(VisualIDHolder.VIDType.NATIVE); Log.d(MD.TAG, "nativeVisualID 0x"+Integer.toHexString(nativeVisualID)); + Log.d(MD.TAG, "requestedCaps: "+eglConfig.getRequestedCapabilities()); + Log.d(MD.TAG, "chosenCaps : "+eglConfig.getChosenCapabilities()); if(VisualIDHolder.VID_UNDEFINED != nativeVisualID) { setSurfaceVisualID0(surfaceHandle, nativeVisualID); } @@ -334,16 +381,11 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { if( null != viewGroup) { viewGroup.post(new Runnable() { public void run() { - if(null == androidView) { - final Context ctx = StaticContext.getContext(); - setupAndroidView(ctx); - } viewGroup.removeView(androidView); Log.d(MD.TAG, "closeNativeImpl: removed from static ViewGroup - on thread "+Thread.currentThread().getName()); } }); } } - removeAndroidView(); } surface = null; @@ -504,7 +546,11 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { surface = aHolder.getSurface(); surfaceHandle = getSurfaceHandle0(surface); acquire0(surfaceHandle); + final int aNativeWindowFormat = getANativeWindowFormat(androidFormat); + setSurfaceVisualID0(surfaceHandle, aNativeWindowFormat); nativeFormat = getSurfaceVisualID0(surfaceHandle); + Log.d(MD.TAG, "surfaceChanged: androidFormat "+androidFormat+" -- (set-native "+aNativeWindowFormat+") --> nativeFormat "+nativeFormat); + final int nWidth = getWidth0(surfaceHandle); final int nHeight = getHeight0(surfaceHandle); capsByFormat = (GLCapabilitiesImmutable) fixCaps(true /* matchFormatPrecise */, nativeFormat, getRequestedCapabilities()); @@ -560,7 +606,9 @@ public class WindowDriver extends jogamp.newt.WindowImpl implements Callback2 { // protected static native boolean initIDs0(); protected static native long getSurfaceHandle0(Surface surface); + /** Return the native window format via <code>ANativeWindow_getFormat(..)</code>. */ protected static native int getSurfaceVisualID0(long surfaceHandle); + /** Set the native window format via <code>ANativeWindow_setBuffersGeometry(..)</code>. */ protected static native void setSurfaceVisualID0(long surfaceHandle, int nativeVisualID); protected static native int getWidth0(long surfaceHandle); protected static native int getHeight0(long surfaceHandle); |