diff options
author | Byunghun Jeon <bjeon@codeaurora.org> | 2014-08-29 17:56:11 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2014-11-17 17:55:49 -0800 |
commit | ff68f85c5e55d28d329af073f51dea48c37a9df3 (patch) | |
tree | 0348209524a34fefdef251cb59d8f8db53a7fd4b | |
parent | 74dbd7a70f07f6c3e0e1e3f9a83d7102c681d076 (diff) | |
download | android_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
-rw-r--r-- | res/layout/photo_module.xml | 133 | ||||
-rw-r--r-- | res/layout/video_module.xml | 86 | ||||
-rw-r--r-- | src/com/android/camera/CameraActivity.java | 10 | ||||
-rw-r--r-- | src/com/android/camera/PhotoModule.java | 44 | ||||
-rw-r--r-- | src/com/android/camera/PhotoUI.java | 155 | ||||
-rw-r--r-- | src/com/android/camera/VideoModule.java | 12 | ||||
-rw-r--r-- | src/com/android/camera/VideoUI.java | 196 | ||||
-rw-r--r-- | src/com/android/camera/ui/FaceView.java | 5 |
8 files changed, 337 insertions, 304 deletions
diff --git a/res/layout/photo_module.xml b/res/layout/photo_module.xml index 5f6bcb0d5..5047112a0 100644 --- a/res/layout/photo_module.xml +++ b/res/layout/photo_module.xml @@ -23,63 +23,68 @@ <merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_gravity="center"> - <include layout="@layout/count_down_to_capture"/> - <!-- Wrap a frame layout around texture view so that when scaled, texture - view will not draw outside its unscaled bounds --> + android:layout_gravity="center" > + <include layout="@layout/count_down_to_capture" /> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_gravity="center_vertical|center_horizontal"> - <TextureView - android:id="@+id/preview_content" + android:layout_gravity="center_vertical|center_horizontal" > + <SurfaceView + android:id="@+id/mdp_preview_content" android:layout_width="match_parent" android:layout_height="match_parent" /> - </FrameLayout> - <RelativeLayout android:id="@+id/linear" + </FrameLayout> + <View + android:id="@+id/preview_cover" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/black" + android:visibility="gone" /> + <RelativeLayout android:id="@+id/linear" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <ProgressBar + style="?android:attr/progressBarStyleHorizontal" + android:id="@+id/progress" android:orientation="vertical" + android:layout_width="200dip" + android:layout_height="wrap_content" + android:layout_marginTop="14dip" + android:layout_marginBottom="14dip" + android:layout_marginLeft="30dip" + android:layout_marginRight="30dip" /> + <com.android.camera.GraphView + android:id="@+id/graph_view" + android:layout_width="200dip" + android:layout_height="200dip" + android:layout_marginTop="60dip" + android:layout_marginLeft="90dip" /> + <com.android.camera.DrawAutoHDR + android:id="@+id/autohdr_view" + android:layout_width="200dip" + android:layout_height="200dip" + android:layout_marginTop="15dip" + android:layout_marginLeft="15dip" /> + <TableLayout + android:id="@+id/relative_seek" android:layout_width="match_parent" - android:layout_height="match_parent"> - <ProgressBar - style="?android:attr/progressBarStyleHorizontal" - android:id="@+id/progress" - android:visibility="gone" - android:orientation="vertical" - android:layout_width="200dip" - android:layout_height="wrap_content" - android:layout_marginTop="14dip" - android:layout_marginBottom="14dip" - android:layout_marginLeft="30dip" - android:layout_marginRight="30dip" /> - <com.android.camera.GraphView - android:id="@+id/graph_view" - android:layout_width="200dip" - android:layout_height="200dip" - android:layout_marginTop="60dip" - android:layout_marginLeft="90dip" /> - <com.android.camera.DrawAutoHDR - android:id="@+id/autohdr_view" - android:layout_width="200dip" - android:layout_height="200dip" - android:layout_marginTop="15dip" - android:layout_marginLeft="15dip" /> - <TableLayout - android:id="@+id/relative_seek" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="20px" - android:layout_marginRight="20px" - android:layout_marginLeft="20px" - android:stretchColumns="1"> - <TableRow> <TextView + android:layout_height="match_parent" + android:layout_marginTop="20px" + android:layout_marginRight="20px" + android:layout_marginLeft="20px" + android:stretchColumns="1"> + <TableRow> + <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/skintonetitle" android:layout_gravity="center" android:textSize="22.0sp" android:textStyle="bold" /> - </TableRow> - <TableRow> <SeekBar + </TableRow> + <TableRow> + <SeekBar android:id="@+id/skintoneseek" android:layout_below="@+id/skintonetitle" android:layout_width="match_parent" @@ -87,29 +92,23 @@ android:layout_height="33dip" android:layout_marginLeft="25px" android:layout_marginTop="2dip"/> - </TableRow> - <TableRow> - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:id="@+id/skintoneleft" - android:textSize="22.0sp" - android:textStyle="bold" /> - <TextView - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:id="@+id/skintoneright" - android:textSize="22.0sp" - android:textStyle="bold"/> - </TableRow> - </TableLayout> - </RelativeLayout> - <View - android:id="@+id/preview_cover" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:background="@android:color/black" - android:visibility="gone" /> + </TableRow> + <TableRow> + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:id="@+id/skintoneleft" + android:textSize="22.0sp" + android:textStyle="bold" /> + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:id="@+id/skintoneright" + android:textSize="22.0sp" + android:textStyle="bold"/> + </TableRow> + </TableLayout> + </RelativeLayout> <ImageView android:id="@+id/review_image" android:layout_width="match_parent" diff --git a/res/layout/video_module.xml b/res/layout/video_module.xml index af839e774..6f36081e2 100644 --- a/res/layout/video_module.xml +++ b/res/layout/video_module.xml @@ -15,25 +15,26 @@ --> <!-- This layout is shared by phone and tablet in landscape orientation. --> <merge xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_width="match_parent"> - <!-- Wrap a frame layout around texture view so that when scaled, texture - view will not draw outside its unscaled bounds --> + android:layout_gravity="center" > <FrameLayout android:layout_width="match_parent" - android:layout_height="match_parent"> - <TextureView - android:id="@+id/preview_content" - android:layout_width="match_parent" - android:layout_height="match_parent" /> - <View - android:id="@+id/preview_cover" + android:layout_height="match_parent" + android:layout_gravity="center_vertical|center_horizontal" > + <SurfaceView + android:id="@+id/mdp_preview_content" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@android:color/black" android:visibility="gone" /> </FrameLayout> <View + android:id="@+id/preview_cover" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/black" + android:visibility="gone" /> + <View android:id="@+id/flash_overlay" android:layout_width="match_parent" android:layout_height="match_parent" @@ -41,47 +42,46 @@ android:visibility="gone" android:alpha="0" /> <FrameLayout android:id="@+id/preview_border" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:visibility="gone" - android:background="@drawable/ic_snapshot_border" /> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="gone" + android:background="@drawable/ic_snapshot_border" /> <com.android.camera.ui.RenderOverlay android:id="@+id/render_overlay" android:layout_width="match_parent" android:layout_height="match_parent" /> <com.android.camera.ui.RotateLayout android:id="@+id/recording_time_rect" - android:layout_height="match_parent" - android:layout_width="match_parent"> - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="horizontal" - android:layout_height="match_parent" - android:layout_width="match_parent"> - <com.android.camera.PauseButton android:id="@+id/video_pause" - android:layout_height="wrap_content" - android:layout_width="wrap_content" - android:layout_marginLeft="50dp" - android:padding="23dp" - android:visibility="gone" - android:src="@drawable/btn_pause_recording"/> - <include layout="@layout/viewfinder_labels_video" - android:id="@+id/labels" /> - </LinearLayout> + android:layout_height="match_parent" + android:layout_width="match_parent"> + <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="horizontal" + android:layout_height="match_parent" + android:layout_width="match_parent"> + <com.android.camera.PauseButton android:id="@+id/video_pause" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:layout_marginLeft="50dp" + android:padding="23dp" + android:visibility="gone" + android:src="@drawable/btn_pause_recording"/> + <include layout="@layout/viewfinder_labels_video" + android:id="@+id/labels" /> + </LinearLayout> </com.android.camera.ui.RotateLayout> <ImageView android:id="@+id/review_image" - android:layout_height="match_parent" - android:layout_width="match_parent" - android:visibility="gone" - android:background="@android:color/black"/> + android:layout_height="match_parent" + android:layout_width="match_parent" + android:visibility="gone" + android:background="@android:color/black"/> <ImageView - android:id="@+id/btn_play" - style="@style/ReviewControlIcon" - android:layout_centerInParent="true" - android:src="@drawable/ic_gallery_play_big" - android:scaleType="center" - android:visibility="gone" - android:onClick="onReviewPlayClicked"/> - + android:id="@+id/btn_play" + style="@style/ReviewControlIcon" + android:layout_centerInParent="true" + android:src="@drawable/ic_gallery_play_big" + android:scaleType="center" + android:visibility="gone" + android:onClick="onReviewPlayClicked"/> <include layout="@layout/camera_controls" android:layout_gravity="center" style="@style/CameraControls"/> 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 31c071667..eb4ce8349 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) { |