summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2010-04-28 11:36:07 +0800
committerOwen Lin <owenlin@google.com>2010-05-07 11:09:33 +0800
commit7b783cb800a90b3f301374f354750292bb75f7aa (patch)
treed73c2d0550bcb43061a0b39fa4139c4a055fac6f /src/com
parent7d16cd38466eaa850a08627552499116fb80286b (diff)
downloadLegacyCamera-7b783cb800a90b3f301374f354750292bb75f7aa.zip
LegacyCamera-7b783cb800a90b3f301374f354750292bb75f7aa.tar.gz
LegacyCamera-7b783cb800a90b3f301374f354750292bb75f7aa.tar.bz2
Use our own EGLChooser so that we can fall back to use "copyImage2D" when
stencil is not supported. Also fix an issue in GLListView due to a different behavior on Emulator, i.e., ACTION_MOVE won't be sent after ACTION_DOWN. Bug: 2538315 Change-Id: I8eb26794656b42df1c89e675bc153879920a7155
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/ui/CamcorderHeadUpDisplay.java2
-rw-r--r--src/com/android/camera/ui/CameraEGLConfigChooser.java95
-rw-r--r--src/com/android/camera/ui/CameraHeadUpDisplay.java16
-rw-r--r--src/com/android/camera/ui/GLListView.java5
-rw-r--r--src/com/android/camera/ui/GLRootView.java9
-rw-r--r--src/com/android/camera/ui/HeadUpDisplay.java4
-rw-r--r--src/com/android/camera/ui/PopupWindow.java45
-rw-r--r--src/com/android/camera/ui/PopupWindowStencilImpl.java34
8 files changed, 161 insertions, 49 deletions
diff --git a/src/com/android/camera/ui/CamcorderHeadUpDisplay.java b/src/com/android/camera/ui/CamcorderHeadUpDisplay.java
index 1d0b1c4..e6475ec 100644
--- a/src/com/android/camera/ui/CamcorderHeadUpDisplay.java
+++ b/src/com/android/camera/ui/CamcorderHeadUpDisplay.java
@@ -8,7 +8,7 @@ import com.android.camera.PreferenceGroup;
public class CamcorderHeadUpDisplay extends HeadUpDisplay {
- protected static final String TAG = "CamcorderHeadUpDisplay";
+ private static final String TAG = "CamcorderHeadUpDisplay";
private OtherSettingsIndicator mOtherSettings;
diff --git a/src/com/android/camera/ui/CameraEGLConfigChooser.java b/src/com/android/camera/ui/CameraEGLConfigChooser.java
new file mode 100644
index 0000000..44d7394
--- /dev/null
+++ b/src/com/android/camera/ui/CameraEGLConfigChooser.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.camera.ui;
+
+import android.opengl.GLSurfaceView.EGLConfigChooser;
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.egl.EGLDisplay;
+
+/*
+ * The code is copied/adapted from
+ * <code>android.opengl.GLSurfaceView.BaseConfigChooser</code>. Here we try to
+ * choose a configuration that support RGBA_8888 format and if possible,
+ * with stencil buffer, but is not required.
+ */
+public class CameraEGLConfigChooser implements EGLConfigChooser {
+
+ private static final int COLOR_BITS = 8;
+
+ private int mStencilBits;
+
+ private final int mConfigSpec[] = new int[] {
+ EGL10.EGL_RED_SIZE, COLOR_BITS,
+ EGL10.EGL_GREEN_SIZE, COLOR_BITS,
+ EGL10.EGL_BLUE_SIZE, COLOR_BITS,
+ EGL10.EGL_ALPHA_SIZE, COLOR_BITS,
+ EGL10.EGL_NONE
+ };
+
+ public int getStencilBits() {
+ return mStencilBits;
+ }
+
+ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
+ int[] numConfig = new int[1];
+ if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, numConfig)) {
+ throw new RuntimeException("eglChooseConfig failed");
+ }
+
+ if (numConfig[0] <= 0) {
+ throw new RuntimeException("No configs match configSpec");
+ }
+
+ EGLConfig[] configs = new EGLConfig[numConfig[0]];
+ if (!egl.eglChooseConfig(display,
+ mConfigSpec, configs, configs.length, numConfig)) {
+ throw new RuntimeException();
+ }
+
+ return chooseConfig(egl, display, configs);
+ }
+
+ private EGLConfig chooseConfig(
+ EGL10 egl, EGLDisplay display, EGLConfig configs[]) {
+
+ EGLConfig result = null;
+ int minStencil = Integer.MAX_VALUE;
+ int value[] = new int[1];
+
+ // Because we need only one bit of stencil, try to choose a config that
+ // 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_STENCIL_SIZE, value)) {
+ if (value[0] == 0) continue;
+ if (value[0] < minStencil) {
+ minStencil = value[0];
+ result = configs[i];
+ }
+ } else {
+ throw new RuntimeException(
+ "eglGetConfigAttrib error: " + egl.eglGetError());
+ }
+ }
+ if (result == null) result = configs[0];
+ egl.eglGetConfigAttrib(
+ display, result, EGL10.EGL_STENCIL_SIZE, value);
+ mStencilBits = value[0];
+ return result;
+ }
+}
diff --git a/src/com/android/camera/ui/CameraHeadUpDisplay.java b/src/com/android/camera/ui/CameraHeadUpDisplay.java
index bf9f249..9883698 100644
--- a/src/com/android/camera/ui/CameraHeadUpDisplay.java
+++ b/src/com/android/camera/ui/CameraHeadUpDisplay.java
@@ -9,14 +9,16 @@ import com.android.camera.PreferenceGroup;
public class CameraHeadUpDisplay extends HeadUpDisplay {
- protected static final String TAG = "CamcoderHeadUpDisplay";
+ private static final String TAG = "CamcoderHeadUpDisplay";
private OtherSettingsIndicator mOtherSettings;
private GpsIndicator mGpsIndicator;
private ZoomIndicator mZoomIndicator;
+ private Context mContext;
public CameraHeadUpDisplay(Context context) {
super(context);
+ mContext = context;
}
@Override
@@ -49,9 +51,6 @@ public class CameraHeadUpDisplay extends HeadUpDisplay {
addIndicator(context, group, CameraSettings.KEY_WHITE_BALANCE);
addIndicator(context, group, CameraSettings.KEY_FLASH_MODE);
-
- mZoomIndicator = new ZoomIndicator(context);
- mIndicatorBar.addComponent(mZoomIndicator);
}
public void setZoomListener(ZoomController.ZoomListener listener) {
@@ -75,7 +74,16 @@ public class CameraHeadUpDisplay extends HeadUpDisplay {
}
}
+ /**
+ * Sets the zoom rations the camera driver provides. This methods must be
+ * called before <code>setZoomListener()</code> and
+ * <code>setZoomIndex()</code>
+ */
public void setZoomRatios(float[] zoomRatios) {
+ if (mZoomIndicator == null) {
+ mZoomIndicator = new ZoomIndicator(mContext);
+ mIndicatorBar.addComponent(mZoomIndicator);
+ }
mZoomIndicator.setZoomRatios(zoomRatios);
}
}
diff --git a/src/com/android/camera/ui/GLListView.java b/src/com/android/camera/ui/GLListView.java
index 97bdc2f..dcba22f 100644
--- a/src/com/android/camera/ui/GLListView.java
+++ b/src/com/android/camera/ui/GLListView.java
@@ -277,11 +277,12 @@ public class GLListView extends GLView {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
+ mIsPressed = true;
mHandler.removeMessages(HIDE_SCROLL_BAR);
setScrollBarVisible(mScrollHeight > getHeight());
- break;
+
+ // fallthrough: we need to highlight the item which is pressed
case MotionEvent.ACTION_MOVE:
- mIsPressed = true;
if (!mScrollable) {
findAndSetHighlightItem((int) event.getY());
}
diff --git a/src/com/android/camera/ui/GLRootView.java b/src/com/android/camera/ui/GLRootView.java
index 10981b1..30adccb 100644
--- a/src/com/android/camera/ui/GLRootView.java
+++ b/src/com/android/camera/ui/GLRootView.java
@@ -75,9 +75,8 @@ public class GLRootView extends GLSurfaceView
private Thread mGLThread;
private boolean mIsQueueActive = true;
+ private CameraEGLConfigChooser mEglConfigChooser = new CameraEGLConfigChooser();
- private int mFirstWidth;
- private int mFirstHeight;
// TODO: move this part (handler) into GLSurfaceView
private final Looper mLooper;
@@ -156,9 +155,13 @@ public class GLRootView extends GLSurfaceView
}
}
+ public CameraEGLConfigChooser getEGLConfigChooser() {
+ return mEglConfigChooser;
+ }
+
private void initialize() {
mFlags |= FLAG_INITIALIZED;
- setEGLConfigChooser(8, 8, 8, 8, 0, 4);
+ setEGLConfigChooser(mEglConfigChooser);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
setZOrderOnTop(true);
diff --git a/src/com/android/camera/ui/HeadUpDisplay.java b/src/com/android/camera/ui/HeadUpDisplay.java
index ac2928f..2c6a00b 100644
--- a/src/com/android/camera/ui/HeadUpDisplay.java
+++ b/src/com/android/camera/ui/HeadUpDisplay.java
@@ -50,7 +50,7 @@ public class HeadUpDisplay extends GLView {
private static int sPopupWindowOverlap;
private static int sPopupTriangleOffset;
- protected static final String TAG = "HeadUpDisplay";
+ private static final String TAG = "HeadUpDisplay";
protected IndicatorBar mIndicatorBar;
@@ -259,7 +259,7 @@ public class HeadUpDisplay extends GLView {
}
private void initializePopupWindow(Context context) {
- mPopupWindow = new PopupWindowStencilImpl();
+ mPopupWindow = new PopupWindow();
mPopupWindow.setBackground(
new NinePatchTexture(context, R.drawable.menu_popup));
mPopupWindow.setAnchor(new ResourceTexture(
diff --git a/src/com/android/camera/ui/PopupWindow.java b/src/com/android/camera/ui/PopupWindow.java
index 235e2ac..c12dce9 100644
--- a/src/com/android/camera/ui/PopupWindow.java
+++ b/src/com/android/camera/ui/PopupWindow.java
@@ -20,11 +20,18 @@ public class PopupWindow extends GLView {
private RawTexture mBackupTexture;
protected FrameTexture mBackground;
+ private boolean mUsingStencil;
public PopupWindow() {
super.addComponent(mRotatePane);
}
+ @Override
+ protected void onAttachToRoot(GLRootView root) {
+ super.onAttachToRoot(root);
+ mUsingStencil = root.getEGLConfigChooser().getStencilBits() > 0;
+ }
+
public void setBackground(FrameTexture background) {
if (background == mBackground) return;
mBackground = background;
@@ -86,8 +93,32 @@ public class PopupWindow extends GLView {
mAnchorPosition = yoffset;
}
- @Override
- protected void renderBackground(GLRootView root, GL11 gl) {
+ private void renderBackgroundWithStencil(GLRootView root, GL11 gl) {
+ int width = getWidth();
+ int height = getHeight();
+ int aWidth = mAnchor.getWidth();
+ int aHeight = mAnchor.getHeight();
+
+ Rect p = mPaddings;
+ int aXoffset = width - aWidth;
+ int aYoffset = Math.max(p.top, mAnchorPosition - aHeight / 2);
+ aYoffset = Math.min(aYoffset, height - p.bottom - aHeight);
+
+ if (mAnchor != null) {
+ gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
+ gl.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
+ mAnchor.draw(root, aXoffset, aYoffset);
+ gl.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);
+ gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
+ }
+
+ if (mBackground != null) {
+ mBackground.setSize(width - aWidth + mAnchorOffset, height);
+ mBackground.draw(root, 0, 0);
+ }
+ }
+
+ private void renderBackgroundWithoutStencil(GLRootView root, GL11 gl) {
int width = getWidth();
int height = getHeight();
int aWidth = mAnchor.getWidth();
@@ -126,6 +157,15 @@ public class PopupWindow extends GLView {
gl.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
+ @Override
+ protected void renderBackground(GLRootView root, GL11 gl) {
+ if (mUsingStencil) {
+ renderBackgroundWithStencil(root, gl);
+ } else {
+ renderBackgroundWithoutStencil(root, gl);
+ }
+ }
+
public void setContent(GLView content) {
mRotatePane.setContent(content);
}
@@ -174,5 +214,4 @@ public class PopupWindow extends GLView {
break;
}
}
-
}
diff --git a/src/com/android/camera/ui/PopupWindowStencilImpl.java b/src/com/android/camera/ui/PopupWindowStencilImpl.java
deleted file mode 100644
index 87267c4..0000000
--- a/src/com/android/camera/ui/PopupWindowStencilImpl.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.android.camera.ui;
-
-import android.graphics.Rect;
-
-import javax.microedition.khronos.opengles.GL11;
-
-public class PopupWindowStencilImpl extends PopupWindow {
-
- @Override
- protected void renderBackground(GLRootView rootView, GL11 gl) {
- int width = getWidth();
- int height = getHeight();
- int aWidth = mAnchor.getWidth();
- int aHeight = mAnchor.getHeight();
-
- Rect p = mPaddings;
- int aXoffset = width - aWidth;
- int aYoffset = Math.max(p.top, mAnchorPosition - aHeight / 2);
- aYoffset = Math.min(aYoffset, height - p.bottom - aHeight);
-
- if (mAnchor != null) {
- gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
- gl.glStencilFunc(GL11.GL_ALWAYS, 1, 1);
- mAnchor.draw(rootView, aXoffset, aYoffset);
- gl.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);
- gl.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
- }
-
- if (mBackground != null) {
- mBackground.setSize(width - aWidth + mAnchorOffset, height);
- mBackground.draw(rootView, 0, 0);
- }
- }
-}