From 0cb58a0566b3168a397782432e595ea0580b0391 Mon Sep 17 00:00:00 2001 From: Jack Yoo Date: Tue, 21 Jun 2016 16:30:11 -0700 Subject: SnapdragonCamera: Replacing mono surface Replacing mono surface to allocation dummy surface Change-Id: I8ed7396e6bee7fd34e223f285c0d9693ff04527a CRs-Fixed: 1035245 --- res/layout/capture_module.xml | 7 +- src/com/android/camera/CaptureModule.java | 8 +- src/com/android/camera/CaptureUI.java | 162 +++++++++++++++++++--------- src/com/android/camera/SettingsManager.java | 2 +- 4 files changed, 118 insertions(+), 61 deletions(-) diff --git a/res/layout/capture_module.xml b/res/layout/capture_module.xml index 07594cef3..dd7d3cb1b 100644 --- a/res/layout/capture_module.xml +++ b/res/layout/capture_module.xml @@ -32,17 +32,16 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_vertical|center_horizontal"> - - + android:layout_height="300dp" + android:id="@+id/mdp_preview_content_mono" + android:visibility="gone"/> surfaceList, int id) { if (isBackCamera() && getCameraMode() == DUAL_MODE && id == MONO_ID) { if(surfaceList != null) { - surfaceList.add(mUI.getSurfaceHolder2().getSurface()); + surfaceList.add(mUI.getMonoDummySurface()); } - builder.addTarget(mUI.getSurfaceHolder2().getSurface()); + builder.addTarget(mUI.getMonoDummySurface()); return; } else { List surfaces = mFrameProcessor.getInputSurfaces(); @@ -2744,7 +2744,7 @@ public class CaptureModule implements CameraModule, PhotoController, private Surface getPreviewSurfaceForSession(int id) { if (isBackCamera()) { if (getCameraMode() == DUAL_MODE && id == MONO_ID) { - return mUI.getSurfaceHolder2().getSurface(); + return mUI.getMonoDummySurface(); } else { return mUI.getSurfaceHolder().getSurface(); } diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java index 30a9425b4..dd06ba400 100644 --- a/src/com/android/camera/CaptureUI.java +++ b/src/com/android/camera/CaptureUI.java @@ -22,16 +22,24 @@ package com.android.camera; import android.animation.Animator; import android.content.Context; import android.content.res.Resources; +import android.graphics.ImageFormat; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.AnimationDrawable; import android.hardware.Camera.Face; +import android.media.ImageReader; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.ScriptIntrinsicYuvToRGB; +import android.renderscript.Type; import android.text.TextUtils; import android.util.Log; import android.view.Display; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; +import android.view.Surface; import android.view.SurfaceHolder; import android.view.View; import android.view.ViewGroup; @@ -42,6 +50,8 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.android.camera.imageprocessor.ScriptC_YuvToRgb; +import com.android.camera.imageprocessor.ScriptC_rotator; import com.android.camera.imageprocessor.filter.BeautificationFilter; import com.android.camera.imageprocessor.filter.TrackingFocusFrameListener; import com.android.camera.ui.AutoFitSurfaceView; @@ -66,6 +76,7 @@ import org.codeaurora.snapcam.R; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Set; public class CaptureUI implements FocusOverlayManager.FocusUI, PreviewGestures.SingleTapListener, @@ -125,9 +136,9 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private View mPreviewCover; private CaptureModule mModule; private AutoFitSurfaceView mSurfaceView; - private AutoFitSurfaceView mSurfaceView2; + private AutoFitSurfaceView mSurfaceViewMono; private SurfaceHolder mSurfaceHolder; - private SurfaceHolder mSurfaceHolder2; + private SurfaceHolder mSurfaceHolderMono; private int mOrientation; private RotateLayout mMenuLayout; private RotateLayout mSubMenuLayout; @@ -145,6 +156,23 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private Camera2FaceView mFaceView; private Point mDisplaySize = new Point(); + private SurfaceHolder.Callback callbackMono = new SurfaceHolder.Callback() { + // SurfaceHolder callbacks + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + mSurfaceHolderMono = holder; + if(mMonoDummyOutputAllocation != null) { + mMonoDummyOutputAllocation.setSurface(mSurfaceHolderMono.getSurface()); + } + } + @Override + public void surfaceCreated(SurfaceHolder holder) { + } + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + } + }; + private SurfaceHolder.Callback callback = new SurfaceHolder.Callback() { // SurfaceHolder callbacks @@ -180,6 +208,9 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private CameraControls mCameraControls; private PieRenderer mPieRenderer; private ZoomRenderer mZoomRenderer; + private Allocation mMonoDummyAllocation; + private Allocation mMonoDummyOutputAllocation; + private boolean mIsMonoDummyAllocationEverUsed = false; private int mScreenRatio = CameraUtil.RATIO_UNKNOWN; private int mTopMargin = 0; @@ -200,35 +231,8 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, int mPreviewWidth; int mPreviewHeight; - private SurfaceHolder.Callback callback2 = new SurfaceHolder.Callback() { - - // SurfaceHolder callbacks - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - Log.v(TAG, "surfaceChanged2"); - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - Log.v(TAG, "surfaceCreated2"); - mSurfaceHolder2 = holder; - previewUIReady(); - } - - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - Log.v(TAG, "surfaceDestroyed2"); - mSurfaceHolder2 = null; - previewUIDestroyed(); - } - }; - private void previewUIReady() { - if((mSurfaceHolder != null && mSurfaceHolder.getSurface().isValid()) && - (mSurfaceView2.getVisibility() != View.VISIBLE || - (mSurfaceView2.getVisibility() == View.VISIBLE && - mSurfaceHolder2 != null && - mSurfaceHolder2.getSurface().isValid()))) { + if((mSurfaceHolder != null && mSurfaceHolder.getSurface().isValid())) { mModule.onPreviewUIReady(); mActivity.updateThumbnail(mThumbnail); } @@ -257,8 +261,6 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, mPreviewCover = mRootView.findViewById(R.id.preview_cover); // display the view mSurfaceView = (AutoFitSurfaceView) mRootView.findViewById(R.id.mdp_preview_content); - mSurfaceView2 = (AutoFitSurfaceView) mRootView.findViewById(R.id.mdp_preview_content2); - mSurfaceView2.setZOrderMediaOverlay(true); mSurfaceHolder = mSurfaceView.getHolder(); mSurfaceHolder.addCallback(callback); mSurfaceView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @@ -273,8 +275,11 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } } }); - mSurfaceHolder2 = mSurfaceView2.getHolder(); - mSurfaceHolder2.addCallback(callback2); + + mSurfaceViewMono = (AutoFitSurfaceView) mRootView.findViewById(R.id.mdp_preview_content_mono); + mSurfaceViewMono.setZOrderMediaOverlay(true); + mSurfaceHolderMono = mSurfaceViewMono.getHolder(); + mSurfaceHolderMono.addCallback(callbackMono); mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay); mShutterButton = (ShutterButton) mRootView.findViewById(R.id.shutter_button); @@ -394,6 +399,14 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, if (mTrackingFocusRenderer != null) { mTrackingFocusRenderer.setVisible(true); } + if (mSurfaceViewMono != null) { + if (mSettingsManager != null && mSettingsManager.getValue(SettingsManager.KEY_MONO_PREVIEW) != null + && mSettingsManager.getValue(SettingsManager.KEY_MONO_PREVIEW).equalsIgnoreCase("on")) { + mSurfaceViewMono.setVisibility(View.VISIBLE); + } else { + mSurfaceViewMono.setVisibility(View.GONE); + } + } } // called from onResume but only the first time @@ -1302,8 +1315,59 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, return mSurfaceHolder; } - public SurfaceHolder getSurfaceHolder2() { - return mSurfaceHolder2; + private class MonoDummyListener implements Allocation.OnBufferAvailableListener { + ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic; + public MonoDummyListener(ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic) { + this.yuvToRgbIntrinsic = yuvToRgbIntrinsic; + } + + @Override + public void onBufferAvailable(Allocation a) { + if(mMonoDummyAllocation != null) { + mMonoDummyAllocation.ioReceive(); + mIsMonoDummyAllocationEverUsed = true; + if(mSurfaceViewMono.getVisibility() == View.VISIBLE) { + try { + yuvToRgbIntrinsic.forEach(mMonoDummyOutputAllocation); + mMonoDummyOutputAllocation.ioSend(); + } catch(Exception e) + { + Log.e(TAG, e.toString()); + } + } + } + } + } + + public Surface getMonoDummySurface() { + if (mMonoDummyAllocation == null) { + RenderScript rs = RenderScript.create(mActivity); + Type.Builder yuvTypeBuilder = new Type.Builder(rs, Element.YUV(rs)); + yuvTypeBuilder.setX(mPreviewWidth); + yuvTypeBuilder.setY(mPreviewHeight); + yuvTypeBuilder.setYuvFormat(ImageFormat.YUV_420_888); + mMonoDummyAllocation = Allocation.createTyped(rs, yuvTypeBuilder.create(), Allocation.USAGE_IO_INPUT|Allocation.USAGE_SCRIPT); + ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.RGBA_8888(rs)); + yuvToRgbIntrinsic.setInput(mMonoDummyAllocation); + + if(mSettingsManager.getValue(SettingsManager.KEY_MONO_PREVIEW).equalsIgnoreCase("on")) { + Type.Builder rgbTypeBuilder = new Type.Builder(rs, Element.RGBA_8888(rs)); + rgbTypeBuilder.setX(mPreviewWidth); + rgbTypeBuilder.setY(mPreviewHeight); + mMonoDummyOutputAllocation = Allocation.createTyped(rs, rgbTypeBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_OUTPUT); + mMonoDummyOutputAllocation.setSurface(mSurfaceHolderMono.getSurface()); + mActivity.runOnUiThread(new Runnable() { + public void run() { + mSurfaceHolderMono.setFixedSize(mPreviewWidth, mPreviewHeight); + mSurfaceViewMono.setVisibility(View.VISIBLE); + } + }); + } + mMonoDummyAllocation.setOnBufferAvailableListener(new MonoDummyListener(yuvToRgbIntrinsic)); + + mIsMonoDummyAllocationEverUsed = false; + } + return mMonoDummyAllocation.getSurface(); } public void showPreviewCover() { @@ -1345,10 +1409,20 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, public void onPause() { cancelCountDown(); collapseCameraControls(); + if (mFaceView != null) mFaceView.clear(); if(mTrackingFocusRenderer != null) { mTrackingFocusRenderer.setVisible(false); } + if (mMonoDummyAllocation != null && mIsMonoDummyAllocationEverUsed) { + mMonoDummyAllocation.setOnBufferAvailableListener(null); + mMonoDummyAllocation.destroy(); + mMonoDummyAllocation = null; + } + if (mMonoDummyOutputAllocation != null && mIsMonoDummyAllocationEverUsed) { + mMonoDummyOutputAllocation.destroy(); + mMonoDummyOutputAllocation = null; + } } public boolean collapseCameraControls() { @@ -1453,12 +1527,6 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, return point; } - public Point getSurfaceView2Size() { - Point point = new Point(); - if (mSurfaceView2 != null) point.set(mSurfaceView2.getWidth(), mSurfaceView2.getHeight()); - return point; - } - public void adjustOrientation() { setOrientation(mOrientation, true); } @@ -1617,22 +1685,12 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, public void hideSurfaceView() { mSurfaceView.setVisibility(View.INVISIBLE); - mSurfaceView2.setVisibility(View.INVISIBLE); } public void showSurfaceView() { mSurfaceView.getHolder().setFixedSize(mPreviewWidth, mPreviewHeight); mSurfaceView.setAspectRatio(mPreviewHeight, mPreviewWidth); mSurfaceView.setVisibility(View.VISIBLE); - mSurfaceView2.setVisibility(View.VISIBLE); - } - - public void setSurfaceView(boolean show) { - if (show) { - mSurfaceView2.setVisibility(View.VISIBLE); - } else { - mSurfaceView2.setVisibility(View.INVISIBLE); - } } public boolean setPreviewSize(int width, int height) { diff --git a/src/com/android/camera/SettingsManager.java b/src/com/android/camera/SettingsManager.java index 7ab45fbdc..90f426090 100644 --- a/src/com/android/camera/SettingsManager.java +++ b/src/com/android/camera/SettingsManager.java @@ -141,7 +141,7 @@ public class SettingsManager implements ListMenu.SettingsListener { String cameraId = cameraIdList[i]; CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); - Byte monoOnly = 0; + byte monoOnly = 0; try { monoOnly = characteristics.get(CaptureModule.MetaDataMonoOnlyKey); }catch(Exception e) { -- cgit v1.2.3