summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Yoo <jyoo@codeaurora.org>2016-06-21 16:30:11 -0700
committerGerrit - the friendly Code Review server <code-review@localhost>2016-07-07 09:41:04 -0700
commit0cb58a0566b3168a397782432e595ea0580b0391 (patch)
treeefda08a71e327d8080d7bdf9812cba74f96d020e
parentc8513bf1f30d0cf0257feaf4956e5179cfefe52b (diff)
downloadandroid_packages_apps_Snap-0cb58a0566b3168a397782432e595ea0580b0391.tar.gz
android_packages_apps_Snap-0cb58a0566b3168a397782432e595ea0580b0391.tar.bz2
android_packages_apps_Snap-0cb58a0566b3168a397782432e595ea0580b0391.zip
SnapdragonCamera: Replacing mono surface
Replacing mono surface to allocation dummy surface Change-Id: I8ed7396e6bee7fd34e223f285c0d9693ff04527a CRs-Fixed: 1035245
-rw-r--r--res/layout/capture_module.xml7
-rw-r--r--src/com/android/camera/CaptureModule.java8
-rw-r--r--src/com/android/camera/CaptureUI.java162
-rw-r--r--src/com/android/camera/SettingsManager.java2
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">
-
<com.android.camera.ui.AutoFitSurfaceView
android:id="@+id/mdp_preview_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
-
<com.android.camera.ui.AutoFitSurfaceView
- android:id="@+id/mdp_preview_content2"
android:layout_width="300dp"
- android:layout_height="300dp" />
+ android:layout_height="300dp"
+ android:id="@+id/mdp_preview_content_mono"
+ android:visibility="gone"/>
</FrameLayout>
<View
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index cc9de40c2..5f7395f71 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -708,7 +708,7 @@ public class CaptureModule implements CameraModule, PhotoController,
@Override
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
- Log.e(TAG, "cameracapturesession - onConfigureFailed");
+ Log.e(TAG, "cameracapturesession - onConfigureFailed "+id);
new AlertDialog.Builder(mActivity)
.setTitle("Camera Initialization Failed")
.setMessage("Closing SnapdragonCamera")
@@ -2725,9 +2725,9 @@ public class CaptureModule implements CameraModule, PhotoController,
private void addPreviewSurface(CaptureRequest.Builder builder, List<Surface> 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<Surface> 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) {