From c5378acab92e5d9428e35acc595f09c4bfcb3823 Mon Sep 17 00:00:00 2001 From: Pin Ting Date: Wed, 19 Sep 2012 15:05:28 +0800 Subject: Use 565 pixel format for pre-JB; use 888 otherwise. Bug:7189512 Change-Id: Iec5d528fef4f4fc589370339add299a40fc8f26e --- .../com/android/gallery3d/common/ApiHelper.java | 3 +++ src/com/android/gallery3d/ui/GLRootView.java | 6 +++++- .../gallery3d/ui/GalleryEGLConfigChooser.java | 24 +++++++++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java index 20d7e1dc6..df6f94048 100644 --- a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java +++ b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java @@ -38,6 +38,9 @@ public class ApiHelper { public static final int JELLY_BEAN_MR1 = 17; } + public static final boolean USE_888_PIXEL_FORMAT = + Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; + public static final boolean ENABLE_PHOTO_EDITOR = Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index d3969349a..390d58737 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -119,7 +119,11 @@ public class GLRootView extends GLSurfaceView setBackgroundDrawable(null); setEGLConfigChooser(mEglConfigChooser); setRenderer(this); - getHolder().setFormat(PixelFormat.RGB_565); + if (ApiHelper.USE_888_PIXEL_FORMAT) { + getHolder().setFormat(PixelFormat.RGB_888); + } else { + getHolder().setFormat(PixelFormat.RGB_565); + } // Uncomment this to enable gl error check. // setDebugFlags(DEBUG_CHECK_GL_ERROR); diff --git a/src/com/android/gallery3d/ui/GalleryEGLConfigChooser.java b/src/com/android/gallery3d/ui/GalleryEGLConfigChooser.java index 7089d3c1d..deeb3b76d 100644 --- a/src/com/android/gallery3d/ui/GalleryEGLConfigChooser.java +++ b/src/com/android/gallery3d/ui/GalleryEGLConfigChooser.java @@ -17,6 +17,8 @@ package com.android.gallery3d.ui; import android.opengl.GLSurfaceView.EGLConfigChooser; +import com.android.gallery3d.common.ApiHelper; + import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLDisplay; @@ -31,7 +33,7 @@ class GalleryEGLConfigChooser implements EGLConfigChooser { private static final String TAG = "GalleryEGLConfigChooser"; - private final int mConfigSpec[] = new int[] { + private final int mConfigSpec565[] = new int[] { EGL10.EGL_RED_SIZE, 5, EGL10.EGL_GREEN_SIZE, 6, EGL10.EGL_BLUE_SIZE, 5, @@ -39,9 +41,19 @@ class GalleryEGLConfigChooser implements EGLConfigChooser { EGL10.EGL_NONE }; + private final int mConfigSpec888[] = new int[] { + EGL10.EGL_RED_SIZE, 8, + EGL10.EGL_GREEN_SIZE, 8, + EGL10.EGL_BLUE_SIZE, 8, + EGL10.EGL_ALPHA_SIZE, 0, + EGL10.EGL_NONE + }; + @Override public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { int[] numConfig = new int[1]; + int mConfigSpec[] = ApiHelper.USE_888_PIXEL_FORMAT + ? mConfigSpec888 : mConfigSpec565; if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, numConfig)) { throw new RuntimeException("eglChooseConfig failed"); } @@ -70,10 +82,12 @@ class GalleryEGLConfigChooser implements EGLConfigChooser { // has stencil support but with smallest number of stencil bits. If // none is found, choose any one. for (int i = 0, n = configs.length; i < n; ++i) { - if (egl.eglGetConfigAttrib( - display, configs[i], EGL10.EGL_RED_SIZE, value)) { - // Filter out ARGB 8888 configs. - if (value[0] == 8) continue; + if (!ApiHelper.USE_888_PIXEL_FORMAT) { + if (egl.eglGetConfigAttrib( + display, configs[i], EGL10.EGL_RED_SIZE, value)) { + // Filter out ARGB 8888 configs. + if (value[0] == 8) continue; + } } if (egl.eglGetConfigAttrib( display, configs[i], EGL10.EGL_STENCIL_SIZE, value)) { -- cgit v1.2.3