summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2014-11-19 15:03:16 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2014-11-19 15:03:16 -0800
commita41a7928433d60533548c115f3741a980159e656 (patch)
tree20c8b063aed99c1fa57eb24d5f5550661a8b70c7 /src/com
parentfdccca6a26f8d0bdd556e2e80749e8219e2fa3b5 (diff)
parentff68f85c5e55d28d329af073f51dea48c37a9df3 (diff)
downloadandroid_packages_apps_Snap-a41a7928433d60533548c115f3741a980159e656.tar.gz
android_packages_apps_Snap-a41a7928433d60533548c115f3741a980159e656.tar.bz2
android_packages_apps_Snap-a41a7928433d60533548c115f3741a980159e656.zip
Merge "SnapdragonCamera: Use MDP composition instead of GPU"
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/camera/CameraActivity.java10
-rw-r--r--src/com/android/camera/PhotoModule.java44
-rw-r--r--src/com/android/camera/PhotoUI.java155
-rw-r--r--src/com/android/camera/VideoModule.java12
-rw-r--r--src/com/android/camera/VideoUI.java196
-rw-r--r--src/com/android/camera/ui/FaceView.java5
6 files changed, 228 insertions, 194 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 8091353ff..bc8e2f152 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -193,8 +193,8 @@ public class CameraActivity extends Activity
private LocalMediaObserver mLocalImagesObserver;
private LocalMediaObserver mLocalVideosObserver;
- private final int DEFAULT_SYSTEM_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
+ private final int DEFAULT_SYSTEM_UI_VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+
private boolean mPendingDeletion = false;
private Intent mVideoShareIntent;
@@ -535,9 +535,9 @@ public class CameraActivity extends Activity
mMainHandler.removeMessages(HIDE_ACTION_BAR);
int currentSystemUIVisibility = mAboveFilmstripControlLayout.getSystemUiVisibility();
- int newSystemUIVisibility = DEFAULT_SYSTEM_UI_VISIBILITY |
- (visible ? View.SYSTEM_UI_FLAG_VISIBLE :
- View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN);
+ int newSystemUIVisibility = DEFAULT_SYSTEM_UI_VISIBILITY
+ | (visible ? View.SYSTEM_UI_FLAG_VISIBLE : View.SYSTEM_UI_FLAG_LOW_PROFILE
+ | View.SYSTEM_UI_FLAG_FULLSCREEN);
if (newSystemUIVisibility != currentSystemUIVisibility) {
mAboveFilmstripControlLayout.setSystemUiVisibility(newSystemUIVisibility);
}
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index e10f4ecbb..81b9f695d 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -26,7 +26,6 @@ import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Rect;
-import android.graphics.SurfaceTexture;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
@@ -49,6 +48,7 @@ import android.provider.MediaStore;
import android.util.Log;
import android.view.KeyEvent;
import android.view.OrientationEventListener;
+import android.view.SurfaceHolder;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
@@ -297,6 +297,7 @@ public class PhotoModule
private ContentResolver mContentResolver;
private LocationManager mLocationManager;
+ private boolean mLocationPromptTriggered = false;
private final PostViewPictureCallback mPostViewPictureCallback =
new PostViewPictureCallback();
@@ -571,16 +572,20 @@ public class PhotoModule
// Prompt the user to pick to record location for the very first run of
// camera only
private void locationFirstRun() {
- if (RecordLocationPreference.isSet(mPreferences)) {
+ /* Do not prompt if the preference is already set, this is a secure
+ * camera session, or the prompt has already been triggered. */
+ if (RecordLocationPreference.isSet(mPreferences) ||
+ mActivity.isSecureCamera() || mLocationPromptTriggered) {
return;
}
- if (mActivity.isSecureCamera()) return;
// Check if the back camera exists
int backCameraId = CameraHolder.instance().getBackCameraId();
if (backCameraId == -1) {
// If there is no back camera, do not show the prompt.
return;
}
+
+ mLocationPromptTriggered = true;
mUI.showLocationDialog();
}
@@ -599,12 +604,12 @@ public class PhotoModule
if (mCameraState == PREVIEW_STOPPED || mCameraState == INIT) {
startPreview();
} else {
- SurfaceTexture st = mUI.getSurfaceTexture();
- if (st == null) {
- Log.w(TAG, "startPreview: surfaceTexture is not ready.");
+ SurfaceHolder sh = mUI.getSurfaceHolder();
+ if (sh == null) {
+ Log.w(TAG, "startPreview: holder for preview are not ready.");
return;
}
- mCameraDevice.setPreviewTexture(st);
+ mCameraDevice.setPreviewDisplay(sh);
}
}
@@ -613,8 +618,7 @@ public class PhotoModule
if (mCameraDevice == null) {
return;
}
- Log.v(TAG, "onPreviewUIDestroyed");
- mCameraDevice.setPreviewTexture(null);
+ mCameraDevice.setPreviewDisplay(null);
stopPreview();
}
@@ -770,7 +774,7 @@ public class PhotoModule
}
setPreviewFrameLayoutCameraOrientation();
Size size = mParameters.getPreviewSize();
- Log.e(TAG,"Width = "+ size.width+ "Height = "+size.height);
+ Log.i(TAG, "Using preview width = " + size.width + "& height = " + size.height);
mUI.setAspectRatio((float) size.width / size.height);
}
@@ -2584,20 +2588,18 @@ public class PhotoModule
return;
}
- Log.v(TAG, "startPreview");
-
- SurfaceTexture st = null;
+ SurfaceHolder sh = null;
+ Log.v(TAG, "startPreview: SurfaceHolder (MDP path)");
if (mUI != null) {
- st = mUI.getSurfaceTexture();
+ sh = mUI.getSurfaceHolder();
}
- // Surfacetexture could be null here, but its still valid and safe to set null
- // surface before startpreview. This will help in basic preview setup and
- // surface creation in parallel. Once valid surface is ready in onPreviewUIReady()
- // we set the surface to camera to actually start preview.
- mCameraDevice.setPreviewTexture(st);
+
+ setCameraParameters(UPDATE_PARAM_ALL);
+ // Let UI set its expected aspect ratio
+ mCameraDevice.setPreviewDisplay(sh);
if (!mCameraPreviewParamsReady) {
- Log.w(TAG, "startPreview: parameters for preview is not ready.");
+ Log.w(TAG, "startPreview: parameters for preview are not ready.");
return;
}
mCameraDevice.setErrorCallback(mErrorCallback);
@@ -4063,7 +4065,7 @@ public class PhotoModule
mPreferences, mContentResolver);
mLocationManager.recordLocation(recordLocation);
if(needRestart()){
- Log.v(TAG, "Restarting Preview... Camera Mode Changhed");
+ Log.v(TAG, "Restarting Preview... Camera Mode Changed");
stopPreview();
startPreview();
setCameraState(IDLE);
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
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index 20d1c3733..876905f93 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -28,7 +28,6 @@ import android.content.IntentFilter;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.graphics.Bitmap;
-import android.graphics.SurfaceTexture;
import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
@@ -52,6 +51,7 @@ import android.provider.MediaStore.Video;
import android.util.Log;
import android.view.KeyEvent;
import android.view.OrientationEventListener;
+import android.view.SurfaceHolder;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
@@ -1061,9 +1061,11 @@ public class VideoModule implements CameraModule,
Log.v(TAG, "startPreview");
mStartPrevPending = true;
- SurfaceTexture surfaceTexture = mUI.getSurfaceTexture();
- if (!mPreferenceRead || surfaceTexture == null || mPaused == true ||
- mCameraDevice == null) {
+ SurfaceHolder sh = null;
+ Log.v(TAG, "startPreview: SurfaceHolder (MDP path)");
+ sh = mUI.getSurfaceHolder();
+
+ if (!mPreferenceRead || mPaused == true || mCameraDevice == null) {
mStartPrevPending = false;
return;
}
@@ -1078,7 +1080,7 @@ public class VideoModule implements CameraModule,
setCameraParameters();
try {
- mCameraDevice.setPreviewTexture(surfaceTexture);
+ mCameraDevice.setPreviewDisplay(sh);
mCameraDevice.startPreview();
mPreviewing = true;
onPreviewStarted();
diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java
index 76e072d88..66a9d6b99 100644
--- a/src/com/android/camera/VideoUI.java
+++ b/src/com/android/camera/VideoUI.java
@@ -22,7 +22,6 @@ import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
-import android.graphics.SurfaceTexture;
import android.graphics.drawable.ColorDrawable;
import android.hardware.Camera.Parameters;
import android.os.Handler;
@@ -30,15 +29,15 @@ import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceHolder;
+import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
-import android.view.TextureView;
-import android.view.TextureView.SurfaceTextureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
+import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -61,14 +60,14 @@ import org.codeaurora.snapcam.R;
public class VideoUI implements PieRenderer.PieListener,
PreviewGestures.SingleTapListener,
CameraRootView.MyDisplayListener,
- SurfaceTextureListener, SurfaceHolder.Callback,
+ SurfaceHolder.Callback,
PauseButton.OnPauseButtonListener {
private static final String TAG = "CAM_VideoUI";
private static final int UPDATE_TRANSFORM_MATRIX = 1;
// module fields
private CameraActivity mActivity;
private View mRootView;
- private TextureView mTextureView;
+ private SurfaceHolder mSurfaceHolder;
// An review image having same size as preview. It is displayed when
// recording is stopped in capture intent.
private ImageView mReviewImage;
@@ -92,7 +91,6 @@ public class VideoUI implements PieRenderer.PieListener,
private OnScreenIndicators mOnScreenIndicators;
private RotateLayout mRecordingTimeRect;
private boolean mRecordingStarted = false;
- private SurfaceTexture mSurfaceTexture;
private VideoController mController;
private int mZoomMax;
private List<Integer> mZoomRatios;
@@ -110,8 +108,6 @@ public class VideoUI implements PieRenderer.PieListener,
private SurfaceView mSurfaceView = null;
private int mPreviewWidth = 0;
private int mPreviewHeight = 0;
- private float mSurfaceTextureUncroppedWidth;
- private float mSurfaceTextureUncroppedHeight;
private float mAspectRatio = 4f / 3f;
private boolean mAspectRatioResize;
private Matrix mMatrix = null;
@@ -119,6 +115,10 @@ public class VideoUI implements PieRenderer.PieListener,
private boolean mUIhidden = false;
private int mPreviewOrientation = -1;
+ // temporary variables for updating SurfaceView
+ private int mTempWidth;
+ private int mTempHeight;
+
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -131,25 +131,45 @@ public class VideoUI implements PieRenderer.PieListener,
}
}
};
+
+ 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);
+ }
+ };
+
private OnLayoutChangeListener mLayoutListener = new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
int width = right - left;
int height = bottom - top;
- // Full-screen screennail
- int w = width;
- int h = height;
- if (CameraUtil.getDisplayRotation(mActivity) % 180 != 0) {
- w = height;
- h = width;
+
+ 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)) {
+ || mAspectRatioResize) {
mPreviewWidth = width;
mPreviewHeight = height;
- onScreenSizeChanged(width, height, w, h);
+ setTransformMatrix(width, height);
mAspectRatioResize = false;
}
mCustomVideoMenu.tryToCloseSubList();
@@ -193,16 +213,24 @@ public class VideoUI implements PieRenderer.PieListener,
mActivity = activity;
mController = controller;
mRootView = parent;
- mActivity.getLayoutInflater().inflate(R.layout.video_module, (ViewGroup) mRootView, true);
+ mActivity.getLayoutInflater().inflate(R.layout.video_module,
+ (ViewGroup) mRootView, true);
mPreviewCover = mRootView.findViewById(R.id.preview_cover);
- mTextureView = (TextureView) mRootView.findViewById(R.id.preview_content);
- mTextureView.setSurfaceTextureListener(this);
- mTextureView.addOnLayoutChangeListener(mLayoutListener);
+ // display the view
+ 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)");
+
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.VIDEO_MODULE_INDEX);
mSwitcher.setSwitchListener(mActivity);
+
initializeMiscControls();
initializeControlByIntent();
initializeOverlay();
@@ -218,9 +246,12 @@ public class VideoUI implements PieRenderer.PieListener,
}
public void initializeSurfaceView() {
- mSurfaceView = new SurfaceView(mActivity);
- ((ViewGroup) mRootView).addView(mSurfaceView, 0);
- mSurfaceView.getHolder().addCallback(this);
+ if (mSurfaceView == null) {
+ mSurfaceView = new SurfaceView(mActivity);
+ ((ViewGroup) mRootView).addView(mSurfaceView, 0);
+ mSurfaceHolder = mSurfaceView.getHolder();
+ mSurfaceHolder.addCallback(this);
+ }
}
private void initializeControlByIntent() {
@@ -289,7 +320,10 @@ public class VideoUI implements PieRenderer.PieListener,
mAspectRatioResize = true;
mAspectRatio = ratio;
}
- mHandler.sendEmptyMessage(UPDATE_TRANSFORM_MATRIX);
+
+ if (mPreviewWidth > 0 && mPreviewHeight > 0) {
+ mHandler.sendEmptyMessage(UPDATE_TRANSFORM_MATRIX);
+ }
}
public int getPreviewWidth() {
@@ -300,22 +334,17 @@ public class VideoUI implements PieRenderer.PieListener,
return mPreviewHeight;
}
- public void onScreenSizeChanged(int width, int height, int previewWidth, int previewHeight) {
- setTransformMatrix(width, height);
- }
-
private void setTransformMatrix(int width, int height) {
- mMatrix = mTextureView.getTransform(mMatrix);
- int orientation = CameraUtil.getDisplayRotation(mActivity);
- float scaleX = 1f, scaleY = 1f;
+ mMatrix = mSurfaceView.getMatrix();
+
float scaledTextureWidth, scaledTextureHeight;
- if (mOrientationResize){
- if (width/mAspectRatio > height){
- scaledTextureHeight = height;
- scaledTextureWidth = (int)(height * mAspectRatio + 0.5f);
- } else {
+ if (mOrientationResize) {
+ scaledTextureWidth = height * mAspectRatio;
+ if (scaledTextureWidth > width) {
scaledTextureWidth = width;
- scaledTextureHeight = (int)(width / mAspectRatio + 0.5f);
+ scaledTextureHeight = scaledTextureWidth / mAspectRatio;
+ } else {
+ scaledTextureHeight = height;
}
} else {
if (width > height) {
@@ -327,23 +356,12 @@ public class VideoUI implements PieRenderer.PieListener,
}
}
- if (mSurfaceTextureUncroppedWidth != scaledTextureWidth ||
- mSurfaceTextureUncroppedHeight != scaledTextureHeight) {
- mSurfaceTextureUncroppedWidth = scaledTextureWidth;
- mSurfaceTextureUncroppedHeight = scaledTextureHeight;
- }
- scaleX = scaledTextureWidth / width;
- scaleY = scaledTextureHeight / height;
- mMatrix.setScale(scaleX, scaleY, (float) width / 2, (float) height / 2);
- mTextureView.setTransform(mMatrix);
-
- if (mSurfaceView != null && mSurfaceView.getVisibility() == View.VISIBLE) {
- LayoutParams lp = (LayoutParams) mSurfaceView.getLayoutParams();
- lp.width = (int) mSurfaceTextureUncroppedWidth;
- lp.height = (int) mSurfaceTextureUncroppedHeight;
- lp.gravity = Gravity.CENTER;
- mSurfaceView.requestLayout();
- }
+ Log.v(TAG, "setTransformMatrix: scaledTextureWidth = " + scaledTextureWidth
+ + ", scaledTextureHeight = " + scaledTextureHeight);
+ mTempWidth = (int) scaledTextureWidth;
+ mTempHeight = (int) scaledTextureHeight;
+ mSurfaceView.requestLayout();
+ mHandler.post(updateSurfaceView);
}
/**
@@ -358,10 +376,6 @@ public class VideoUI implements PieRenderer.PieListener,
*/
public void animateCapture() {
Bitmap bitmap = null;
- if (mTextureView != null) {
- bitmap = mTextureView.getBitmap((int) mSurfaceTextureUncroppedWidth / 2,
- (int) mSurfaceTextureUncroppedHeight / 2);
- }
animateCapture(bitmap);
}
@@ -480,18 +494,18 @@ public class VideoUI implements PieRenderer.PieListener,
}
public SurfaceHolder getSurfaceHolder() {
- return mSurfaceView.getHolder();
+ return mSurfaceHolder;
}
public void hideSurfaceView() {
mSurfaceView.setVisibility(View.GONE);
- mTextureView.setVisibility(View.VISIBLE);
+
setTransformMatrix(mPreviewWidth, mPreviewHeight);
}
public void showSurfaceView() {
mSurfaceView.setVisibility(View.VISIBLE);
- mTextureView.setVisibility(View.GONE);
+
setTransformMatrix(mPreviewWidth, mPreviewHeight);
}
@@ -572,12 +586,16 @@ public class VideoUI implements PieRenderer.PieListener,
ratio = 1 / ratio;
}
- if (ratio != mAspectRatio){
+ if (ratio != mAspectRatio) {
mAspectRatioResize = true;
mAspectRatio = (float)ratio;
}
- mHandler.sendEmptyMessage(UPDATE_TRANSFORM_MATRIX);
+ mSurfaceView.requestLayout();
+
+ if (mPreviewWidth > 0 && mPreviewHeight > 0) {
+ mHandler.sendEmptyMessage(UPDATE_TRANSFORM_MATRIX);
+ }
}
public void showTimeLapseUI(boolean enable) {
@@ -927,52 +945,32 @@ public class VideoUI implements PieRenderer.PieListener,
}
}
- public SurfaceTexture getSurfaceTexture() {
- return mSurfaceTexture;
- }
-
- // SurfaceTexture callbacks
- @Override
- public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
- mSurfaceTexture = surface;
- mController.onPreviewUIReady();
- }
-
- @Override
- public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
- mSurfaceTexture = null;
- mController.onPreviewUIDestroyed();
- Log.d(TAG, "surfaceTexture is destroyed");
- return true;
- }
-
- @Override
- public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
- }
-
+ // SurfaceHolder callbacks
@Override
- public void onSurfaceTextureUpdated(SurfaceTexture surface) {
+ 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);
}
}
- // SurfaceHolder callbacks
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
- Log.v(TAG, "Surface changed. width=" + width + ". height=" + height);
- }
-
@Override
public void surfaceCreated(SurfaceHolder holder) {
- Log.v(TAG, "Surface created");
+ 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 surfaceDestroyed(SurfaceHolder holder) {
- Log.v(TAG, "Surface destroyed");
- mController.stopPreview();
+ Log.v(TAG, "surfaceDestroyed");
+ mSurfaceHolder = null;
+ mController.onPreviewUIDestroyed();
}
public View getRootView() {
@@ -982,14 +980,14 @@ public class VideoUI implements PieRenderer.PieListener,
@Override
public void onButtonPause() {
mRecordingTimeView.setCompoundDrawablesWithIntrinsicBounds(
- R.drawable.ic_pausing_indicator, 0, 0, 0);
- mController.onButtonPause();
+ R.drawable.ic_pausing_indicator, 0, 0, 0);
+ mController.onButtonPause();
}
@Override
public void onButtonContinue() {
mRecordingTimeView.setCompoundDrawablesWithIntrinsicBounds(
- R.drawable.ic_recording_indicator, 0, 0, 0);
+ R.drawable.ic_recording_indicator, 0, 0, 0);
mController.onButtonContinue();
}
diff --git a/src/com/android/camera/ui/FaceView.java b/src/com/android/camera/ui/FaceView.java
index f697a5df9..f3a41509f 100644
--- a/src/com/android/camera/ui/FaceView.java
+++ b/src/com/android/camera/ui/FaceView.java
@@ -127,7 +127,10 @@ public class FaceView extends View
mHandler.removeMessages(MSG_SWITCH_FACES);
}
mFaces = faces;
- invalidate();
+ if (!mBlocked && (mFaces != null) && (mFaces.length > 0)) {
+ invalidate();
+ }
+
}
public void setDisplayOrientation(int orientation) {