summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/PhotoUI.java
diff options
context:
space:
mode:
authorByunghun Jeon <bjeon@codeaurora.org>2014-08-29 17:56:11 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2014-11-17 17:55:49 -0800
commitff68f85c5e55d28d329af073f51dea48c37a9df3 (patch)
tree0348209524a34fefdef251cb59d8f8db53a7fd4b /src/com/android/camera/PhotoUI.java
parent74dbd7a70f07f6c3e0e1e3f9a83d7102c681d076 (diff)
downloadandroid_packages_apps_Snap-ff68f85c5e55d28d329af073f51dea48c37a9df3.tar.gz
android_packages_apps_Snap-ff68f85c5e55d28d329af073f51dea48c37a9df3.tar.bz2
android_packages_apps_Snap-ff68f85c5e55d28d329af073f51dea48c37a9df3.zip
SnapdragonCamera: Use MDP composition instead of GPU
Use MDP composition instead of GPU Change-Id: I4f47d26365bd611242a21e66b232d7521b502b04
Diffstat (limited to 'src/com/android/camera/PhotoUI.java')
-rw-r--r--src/com/android/camera/PhotoUI.java155
1 files changed, 92 insertions, 63 deletions
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index 238be864a..803c2b19b 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -26,14 +26,17 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.RectF;
-import android.graphics.SurfaceTexture;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Camera;
import android.hardware.Camera.Face;
import android.os.AsyncTask;
+import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
-import android.view.TextureView;
+import android.view.Surface;
+import android.view.SurfaceView;
+import android.view.SurfaceHolder;
+import android.view.SurfaceHolder.Callback;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
@@ -41,6 +44,7 @@ import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.ViewStub;
+import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -67,10 +71,12 @@ import com.android.camera.util.CameraUtil;
import org.codeaurora.snapcam.R;
public class PhotoUI implements PieListener,
- PreviewGestures.SingleTapListener,
- FocusUI, TextureView.SurfaceTextureListener,
- LocationManager.Listener, CameraRootView.MyDisplayListener,
- CameraManager.CameraFaceDetectionCallback {
+ PreviewGestures.SingleTapListener,
+ FocusUI,
+ SurfaceHolder.Callback,
+ LocationManager.Listener,
+ CameraRootView.MyDisplayListener,
+ CameraManager.CameraFaceDetectionCallback {
private static final String TAG = "CAM_UI";
private int mDownSampleFactor = 4;
@@ -80,7 +86,7 @@ public class PhotoUI implements PieListener,
private PreviewGestures mGestures;
private View mRootView;
- private SurfaceTexture mSurfaceTexture;
+ private SurfaceHolder mSurfaceHolder;
private PopupWindow mPopup;
private ShutterButton mShutterButton;
@@ -122,7 +128,7 @@ public class PhotoUI implements PieListener,
private View mFlashOverlay;
private SurfaceTextureSizeChangedListener mSurfaceTextureSizeListener;
- private TextureView mTextureView;
+ private SurfaceView mSurfaceView = null;
private Matrix mMatrix = null;
private float mAspectRatio = 4f / 3f;
private boolean mAspectRatioResize;
@@ -130,13 +136,30 @@ public class PhotoUI implements PieListener,
private boolean mOrientationResize;
private boolean mPrevOrientationResize;
private View mPreviewCover;
- private final Object mSurfaceTextureLock = new Object();
private LinearLayout mMenuLayout;
private LinearLayout mSubMenuLayout;
private LinearLayout mPreviewMenuLayout;
private boolean mUIhidden = false;
private int mPreviewOrientation = -1;
+ // temporary variables for updating SurfaceView
+ private int mTempWidth;
+ private int mTempHeight;
+
+ private final Handler mSurfaceViewUpdateHandler = new Handler();
+
+ private Runnable updateSurfaceView = new Runnable() {
+
+ @Override
+ public void run() {
+ FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurfaceView
+ .getLayoutParams();
+ params.width = mTempWidth;
+ params.height = mTempHeight;
+ mSurfaceView.setLayoutParams(params);
+ }
+ };
+
public interface SurfaceTextureSizeChangedListener {
public void onSurfaceTextureSizeChanged(int uncroppedWidth, int uncroppedHeight);
}
@@ -147,6 +170,18 @@ public class PhotoUI implements PieListener,
int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int width = right - left;
int height = bottom - top;
+
+ int orientation = mActivity.getResources().getConfiguration().orientation;
+ if ((orientation == Configuration.ORIENTATION_PORTRAIT && width > height)
+ || (orientation == Configuration.ORIENTATION_LANDSCAPE && width < height)) {
+ // The screen has rotated; swap SurfaceView width & height
+ // to ensure correct preview
+ int oldWidth = width;
+ width = height;
+ height = oldWidth;
+ Log.d(TAG, "Swapping SurfaceView width & height dimensions");
+ }
+
if (mPreviewWidth != width || mPreviewHeight != height
|| (mOrientationResize != mPrevOrientationResize)
|| mAspectRatioResize) {
@@ -218,23 +253,26 @@ public class PhotoUI implements PieListener,
mActivity = activity;
mController = controller;
mRootView = parent;
-
mActivity.getLayoutInflater().inflate(R.layout.photo_module,
(ViewGroup) mRootView, true);
- mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay);
- mFlashOverlay = mRootView.findViewById(R.id.flash_overlay);
mPreviewCover = mRootView.findViewById(R.id.preview_cover);
// display the view
- mTextureView = (TextureView) mRootView.findViewById(R.id.preview_content);
- mTextureView.setSurfaceTextureListener(this);
- mTextureView.addOnLayoutChangeListener(mLayoutListener);
- initIndicators();
+ mSurfaceView = (SurfaceView) mRootView.findViewById(R.id.mdp_preview_content);
+ mSurfaceView.setVisibility(View.VISIBLE);
+ mSurfaceHolder = mSurfaceView.getHolder();
+ mSurfaceHolder.addCallback(this);
+ mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
+ mSurfaceView.addOnLayoutChangeListener(mLayoutListener);
+ Log.v(TAG, "Using mdp_preview_content (MDP path)");
+ mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay);
+ mFlashOverlay = mRootView.findViewById(R.id.flash_overlay);
mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button);
mSwitcher = (ModuleSwitcher) mRootView.findViewById(R.id.camera_switcher);
mSwitcher.setCurrentIndex(ModuleSwitcher.PHOTO_MODULE_INDEX);
mSwitcher.setSwitchListener(mActivity);
mMenuButton = mRootView.findViewById(R.id.menu);
+ mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
ViewStub faceViewStub = (ViewStub) mRootView
.findViewById(R.id.face_view_stub);
if (faceViewStub != null) {
@@ -242,9 +280,8 @@ public class PhotoUI implements PieListener,
mFaceView = (FaceView) mRootView.findViewById(R.id.face_view);
setSurfaceTextureSizeChangedListener(mFaceView);
}
- mCameraControls = (CameraControls) mRootView.findViewById(R.id.camera_controls);
+ initIndicators();
mAnimationManager = new AnimationManager();
-
mOrientationResize = false;
mPrevOrientationResize = false;
}
@@ -267,12 +304,13 @@ public class PhotoUI implements PieListener,
ratio = 1 / ratio;
}
- if (mAspectRatio != ratio) {
- Log.d(TAG,"setAspectRatio() ratio["+ratio+"] mAspectRatio["+mAspectRatio+"]");
- mAspectRatio = ratio;
+ Log.d(TAG, "setAspectRatio() ratio[" + ratio + "] mAspectRatio[" + mAspectRatio + "]");
+ if (ratio != mAspectRatio) {
mAspectRatioResize = true;
- mTextureView.requestLayout();
+ mAspectRatio = ratio;
}
+
+ mSurfaceView.requestLayout();
}
public void setSurfaceTextureSizeChangedListener(SurfaceTextureSizeChangedListener listener) {
@@ -280,12 +318,12 @@ public class PhotoUI implements PieListener,
}
private void setTransformMatrix(int width, int height) {
- mMatrix = mTextureView.getTransform(mMatrix);
- float scaleX = 1f, scaleY = 1f;
+ mMatrix = mSurfaceView.getMatrix();
+
float scaledTextureWidth, scaledTextureHeight;
- if (mOrientationResize){
+ if (mOrientationResize) {
scaledTextureWidth = height * mAspectRatio;
- if(scaledTextureWidth > width){
+ if (scaledTextureWidth > width) {
scaledTextureWidth = width;
scaledTextureHeight = scaledTextureWidth / mAspectRatio;
} else {
@@ -307,13 +345,17 @@ public class PhotoUI implements PieListener,
mSurfaceTextureUncroppedHeight = scaledTextureHeight;
if (mSurfaceTextureSizeListener != null) {
mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged(
- (int) mSurfaceTextureUncroppedWidth, (int) mSurfaceTextureUncroppedHeight);
+ (int) mSurfaceTextureUncroppedWidth,
+ (int) mSurfaceTextureUncroppedHeight);
}
}
- scaleX = scaledTextureWidth / width;
- scaleY = scaledTextureHeight / height;
- mMatrix.setScale(scaleX, scaleY, (float) width / 2, (float) height / 2);
- mTextureView.setTransform(mMatrix);
+
+ Log.v(TAG, "setTransformMatrix: scaledTextureWidth = " + scaledTextureWidth
+ + ", scaledTextureHeight = " + scaledTextureHeight);
+ mTempWidth = (int) scaledTextureWidth;
+ mTempHeight = (int) scaledTextureHeight;
+ mSurfaceView.requestLayout();
+ mSurfaceViewUpdateHandler.post(updateSurfaceView);
// Calculate the new preview rectangle.
RectF previewRect = new RectF(0, 0, width, height);
@@ -321,45 +363,32 @@ public class PhotoUI implements PieListener,
mController.onPreviewRectChanged(CameraUtil.rectFToRect(previewRect));
}
- protected Object getSurfaceTextureLock() {
- return mSurfaceTextureLock;
- }
-
+ // SurfaceHolder callbacks
@Override
- public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
- synchronized (mSurfaceTextureLock) {
- Log.v(TAG, "SurfaceTexture ready.");
- mSurfaceTexture = surface;
- mController.onPreviewUIReady();
- // Workaround for b/11168275, see b/10981460 for more details
- if (mPreviewWidth != 0 && mPreviewHeight != 0) {
- // Re-apply transform matrix for new surface texture
- setTransformMatrix(mPreviewWidth, mPreviewHeight);
- }
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ Log.v(TAG, "surfaceChanged: width =" + width + ", height = " + height);
+ // Make sure preview cover is hidden if preview data is available.
+ if (mPreviewCover.getVisibility() != View.GONE) {
+ mPreviewCover.setVisibility(View.GONE);
}
}
@Override
- public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
- // Ignored, Camera does all the work for us
- }
-
- @Override
- public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
- synchronized (mSurfaceTextureLock) {
- mSurfaceTexture = null;
- mController.onPreviewUIDestroyed();
- Log.w(TAG, "SurfaceTexture destroyed");
- return true;
+ public void surfaceCreated(SurfaceHolder holder) {
+ Log.v(TAG, "surfaceCreated");
+ mSurfaceHolder = holder;
+ mController.onPreviewUIReady();
+ if (mPreviewWidth != 0 && mPreviewHeight != 0) {
+ // Re-apply transform matrix for new surface texture
+ setTransformMatrix(mPreviewWidth, mPreviewHeight);
}
}
@Override
- public void onSurfaceTextureUpdated(SurfaceTexture surface) {
- // Make sure preview cover is hidden if preview data is available.
- if (mPreviewCover.getVisibility() != View.GONE) {
- mPreviewCover.setVisibility(View.GONE);
- }
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ Log.v(TAG, "surfaceDestroyed");
+ mSurfaceHolder = null;
+ mController.stopPreview();
}
public View getRootView() {
@@ -968,8 +997,8 @@ public class PhotoUI implements PieListener,
mActivity.setSwipingEnabled(enable);
}
- public SurfaceTexture getSurfaceTexture() {
- return mSurfaceTexture;
+ public SurfaceHolder getSurfaceHolder() {
+ return mSurfaceHolder;
}
// Countdown timer