summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSenpo Hu <senpo@google.com>2015-06-12 16:20:46 -0700
committerSenpo Hu <senpo@google.com>2015-06-25 13:32:07 -0400
commita6572422e8940e176e3630c23a331927b5b08853 (patch)
tree6e26cfffe472cd69836d7d37aefc1ccf7c77af9a /src
parent8d8b329da25456adb5ee45e0450680654114e125 (diff)
downloadandroid_packages_apps_Camera2-a6572422e8940e176e3630c23a331927b5b08853.tar.gz
android_packages_apps_Camera2-a6572422e8940e176e3630c23a331927b5b08853.tar.bz2
android_packages_apps_Camera2-a6572422e8940e176e3630c23a331927b5b08853.zip
Fix transform issue in CaptureIntent.
On M, EventOnTextureViewLayoutChanged comes earlier during app initialization in StateForeground which doesn't handle it. So here in StateReadyForCapture, we pull the current preview layout size and inform ResourceSurfaceTexture to allow it to calculate transform. Noted that we also need to bring this fix to Ivvavik. Bug: 21786937 Bug: 20173626 Change-Id: I417aef2f09247e77059fc5b066cbf10602ce5cf1
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/captureintent/CaptureIntentModuleUI.java8
-rw-r--r--src/com/android/camera/captureintent/resource/ResourceSurfaceTextureImpl.java24
-rw-r--r--src/com/android/camera/captureintent/state/StateReadyForCapture.java11
3 files changed, 39 insertions, 4 deletions
diff --git a/src/com/android/camera/captureintent/CaptureIntentModuleUI.java b/src/com/android/camera/captureintent/CaptureIntentModuleUI.java
index 5f518a45f..740218134 100644
--- a/src/com/android/camera/captureintent/CaptureIntentModuleUI.java
+++ b/src/com/android/camera/captureintent/CaptureIntentModuleUI.java
@@ -25,6 +25,7 @@ import com.android.camera.ui.PreviewStatusListener;
import com.android.camera.ui.ProgressOverlay;
import com.android.camera.ui.focus.FocusRing;
import com.android.camera.util.AndroidServices;
+import com.android.camera.util.Size;
import com.android.camera2.R;
import android.graphics.Bitmap;
@@ -112,6 +113,13 @@ public class CaptureIntentModuleUI {
}
/**
+ * Obtains the current preview layout size.
+ */
+ public Size getPreviewSurfaceSize() {
+ return new Size(mAppUI.getSurfaceWidth(), mAppUI.getSurfaceHeight());
+ }
+
+ /**
* Configures the bottom bar UI.
*
* @param hardwareSpec The hardware spec.
diff --git a/src/com/android/camera/captureintent/resource/ResourceSurfaceTextureImpl.java b/src/com/android/camera/captureintent/resource/ResourceSurfaceTextureImpl.java
index c980f9464..a4e63e7e3 100644
--- a/src/com/android/camera/captureintent/resource/ResourceSurfaceTextureImpl.java
+++ b/src/com/android/camera/captureintent/resource/ResourceSurfaceTextureImpl.java
@@ -96,7 +96,20 @@ public class ResourceSurfaceTextureImpl implements ResourceSurfaceTexture {
@Override
public void setPreviewSize(Size previewSize) {
// Update preview transform when preview stream size is changed.
- mPreviewSize = previewSize;
+ if (!mPreviewSize.equals(previewSize)) {
+ mPreviewSize = previewSize;
+
+ /**
+ * Update transform here since preview size might change when
+ * switching between back and front camera.
+ */
+ mResourceConstructed.get().getMainThread().execute(new Runnable() {
+ @Override
+ public void run() {
+ updatePreviewTransform();
+ }
+ });
+ }
// Update surface texture's default buffer size. See b/17286155.
mSurfaceTexture.setDefaultBufferSize(mPreviewSize.width(), mPreviewSize.height());
@@ -124,10 +137,15 @@ public class ResourceSurfaceTextureImpl implements ResourceSurfaceTexture {
@Override
public void updatePreviewTransform() {
MainThread.checkMainThread();
- if (mPreviewSize.getWidth() == 0 || mPreviewSize.getHeight() == 0 ||
- mPreviewLayoutSize.getWidth() == 0 || mPreviewLayoutSize.getHeight() == 0) {
+ if (mPreviewSize.getWidth() == 0 || mPreviewSize.getHeight() == 0) {
+ Log.w(TAG, "Do nothing since mPreviewSize is 0");
+ return;
+ }
+ if (mPreviewLayoutSize.getWidth() == 0 || mPreviewLayoutSize.getHeight() == 0) {
+ Log.w(TAG, "Do nothing since mPreviewLayoutSize is 0");
return;
}
+
Matrix transformMatrix = mPreviewTransformCalculator.toTransformMatrix(
mPreviewLayoutSize, mPreviewSize);
mResourceConstructed.get().getModuleUI().updatePreviewTransform(transformMatrix);
diff --git a/src/com/android/camera/captureintent/state/StateReadyForCapture.java b/src/com/android/camera/captureintent/state/StateReadyForCapture.java
index 481c03972..d4fb5e8e7 100644
--- a/src/com/android/camera/captureintent/state/StateReadyForCapture.java
+++ b/src/com/android/camera/captureintent/state/StateReadyForCapture.java
@@ -65,6 +65,8 @@ import com.android.camera.settings.SettingsManager;
import com.android.camera.ui.CountDownView;
import com.android.camera.ui.TouchCoordinate;
import com.android.camera.ui.focus.FocusController;
+import com.android.camera.util.Size;
+
import com.google.common.base.Optional;
import javax.annotation.Nullable;
@@ -224,8 +226,15 @@ public final class StateReadyForCapture extends StateImpl {
public Optional<State> processEvent(EventOnSurfaceTextureUpdated event) {
if (mShouldUpdateTransformOnNextSurfaceTextureUpdate) {
mShouldUpdateTransformOnNextSurfaceTextureUpdate = false;
+
+ // We have to provide a preview layout size to
+ // ResourceSurfaceTexture. Otherwise, it will
+ // not be able to calculate transform matrix.
+ Size previewSurfaceSize = mResourceCaptureTools.get().getModuleUI()
+ .getPreviewSurfaceSize();
mResourceCaptureTools.get().getResourceSurfaceTexture().get()
- .updatePreviewTransform();
+ .setPreviewLayoutSize(previewSurfaceSize);
+
removeEventHandler(EventOnSurfaceTextureUpdated.class);
}
return NO_CHANGE;