diff options
Diffstat (limited to 'src/com/android/camera/CaptureUI.java')
-rw-r--r-- | src/com/android/camera/CaptureUI.java | 162 |
1 files changed, 110 insertions, 52 deletions
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) { |