summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2012-03-22 17:42:33 +0800
committerChih-Chung Chang <chihchung@google.com>2012-04-02 11:24:23 +0800
commit037e06c5e11ca4a4e40b0741f2d6604b2fd9337a (patch)
tree047235a4ce31aa2c013db38d99056a7196b491e1 /src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java
parentb10f96d2141fae10073ec48f25d7b824647f8f31 (diff)
downloadandroid_packages_apps_Snap-037e06c5e11ca4a4e40b0741f2d6604b2fd9337a.tar.gz
android_packages_apps_Snap-037e06c5e11ca4a4e40b0741f2d6604b2fd9337a.tar.bz2
android_packages_apps_Snap-037e06c5e11ca4a4e40b0741f2d6604b2fd9337a.zip
Use SurfaceTexture to show Camera preview.
Change-Id: I8bf63dfc5b969ecce51841378b093a650b6f91d8
Diffstat (limited to 'src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java')
-rw-r--r--src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java b/src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java
new file mode 100644
index 000000000..3a8f2b0a4
--- /dev/null
+++ b/src/com/android/gallery3d/ui/SurfaceTextureScreenNail.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.ui;
+
+import android.graphics.RectF;
+import android.graphics.SurfaceTexture;
+import android.opengl.GLES11Ext;
+import android.util.Log;
+
+import com.android.gallery3d.ui.GLCanvas;
+import com.android.gallery3d.ui.ScreenNail;
+import com.android.gallery3d.ui.ExtTexture;
+
+public abstract class SurfaceTextureScreenNail implements ScreenNail,
+ SurfaceTexture.OnFrameAvailableListener {
+ private static final String TAG = "SurfaceTextureScreenNail";
+ private ExtTexture mExtTexture;
+ private SurfaceTexture mSurfaceTexture;
+ private int mWidth, mHeight;
+ private float[] mTransform = new float[16];
+ private boolean mHasTexture = false;
+
+ public SurfaceTextureScreenNail() {
+ }
+
+ public void acquireSurfaceTexture() {
+ mExtTexture = new ExtTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
+ mExtTexture.setSize(mWidth, mHeight);
+ mSurfaceTexture = new SurfaceTexture(mExtTexture.getId());
+ mSurfaceTexture.setOnFrameAvailableListener(this);
+ synchronized (this) {
+ mHasTexture = true;
+ }
+ }
+
+ public SurfaceTexture getSurfaceTexture() {
+ return mSurfaceTexture;
+ }
+
+ public void releaseSurfaceTexture() {
+ synchronized (this) {
+ mHasTexture = false;
+ }
+ mExtTexture.recycle();
+ mExtTexture = null;
+ mSurfaceTexture.release();
+ mSurfaceTexture = null;
+ }
+
+ public void setSize(int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ }
+
+ @Override
+ public int getWidth() {
+ return mWidth;
+ }
+
+ @Override
+ public int getHeight() {
+ return mHeight;
+ }
+
+ @Override
+ public int getRotation() {
+ return 0;
+ }
+
+ @Override
+ public void draw(GLCanvas canvas, int x, int y, int width, int height) {
+ synchronized (this) {
+ if (!mHasTexture) return;
+ mSurfaceTexture.updateTexImage();
+ mSurfaceTexture.getTransformMatrix(mTransform);
+
+ // Flip vertically.
+ canvas.save(GLCanvas.SAVE_FLAG_MATRIX);
+ int cx = x + width / 2;
+ int cy = y + height / 2;
+ canvas.translate(cx, cy);
+ canvas.scale(1, -1, 1);
+ canvas.translate(-cx, -cy);
+ canvas.drawTexture(mExtTexture, mTransform, x, y, width, height);
+ canvas.restore();
+ }
+ }
+
+ @Override
+ public void draw(GLCanvas canvas, RectF source, RectF dest) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ abstract public void noDraw();
+
+ @Override
+ abstract public void pauseDraw();
+
+ @Override
+ abstract public void onFrameAvailable(SurfaceTexture surfaceTexture);
+}