summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2010-12-20 12:09:37 -0800
committerJamie Gennis <jgennis@google.com>2011-01-06 16:05:14 -0800
commit6714efc5e0c52953b65e774de0003e22377e7d39 (patch)
treead85eec8ea32d2e05af0008aa9d798cbf74665bc /graphics
parentff2dc46c121c166f10684da069d07ae11d4f9b9a (diff)
downloadframeworks_base-6714efc5e0c52953b65e774de0003e22377e7d39.zip
frameworks_base-6714efc5e0c52953b65e774de0003e22377e7d39.tar.gz
frameworks_base-6714efc5e0c52953b65e774de0003e22377e7d39.tar.bz2
Add the SurfaceTexture java class.
This class exposes to Java the application-side interface to the SurfaceTexture C++ class. Change-Id: I0dba42aad90257c7adbde6fa362658c0717b70d0
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/SurfaceTexture.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
new file mode 100644
index 0000000..883c4eb
--- /dev/null
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2010 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 android.graphics;
+
+/**
+ * Captures frames from an image stream as an OpenGL ES texture.
+ *
+ * <p>The image stream may come from either video playback or camera preview. A SurfaceTexture may
+ * be used in place of a SurfaceHolder when specifying the output destination of a MediaPlayer or
+ * Camera object. This will cause all the frames from that image stream to be sent to the
+ * SurfaceTexture object rather than to the device's display. When {@link #updateTexImage} is
+ * called, the contents of the texture object specified when the SurfaceTexture was created is
+ * updated to contain the most recent image from the image stream. This may cause some frames of
+ * the stream to be skipped.
+ *
+ * <p>The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target, which is defined by the
+ * OES_EGL_image_external OpenGL ES extension. This limits how the texture may be used.
+ */
+public class SurfaceTexture {
+
+ @SuppressWarnings("unused")
+ private int mSurfaceTexture;
+
+ /**
+ * Callback interface for being notified that a new stream frame is available.
+ */
+ public interface OnFrameAvailableListener {
+ void onFrameAvailable(SurfaceTexture surfaceTexture);
+ }
+
+ /**
+ * Exception thrown when a surface couldn't be created or resized
+ */
+ public static class OutOfResourcesException extends Exception {
+ public OutOfResourcesException() {
+ }
+ public OutOfResourcesException(String name) {
+ super(name);
+ }
+ }
+
+ /**
+ * Construct a new SurfaceTexture to stream images to a given OpenGL texture.
+ *
+ * @param texName the OpenGL texture object name (e.g. generated via glGenTextures)
+ */
+ public SurfaceTexture(int texName) {
+ init(texName);
+ }
+
+ /**
+ * Register a callback to be invoked when a new image frame becomes available to the
+ * SurfaceTexture. Note that this callback may be called on an arbitrary thread, so it is not
+ * safe to call {@link #updateTexImage} without first binding the OpenGL ES context to the
+ * thread invoking the callback.
+ */
+ public void setOnFrameAvailableListener(OnFrameAvailableListener l) {
+ // TODO: Implement this!
+ }
+
+ /**
+ * Update the texture image to the most recent frame from the image stream. This may only be
+ * called while the OpenGL ES context that owns the texture is bound to the thread. It will
+ * implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.
+ */
+ public native void updateTexImage();
+
+ private native void init(int texName);
+
+ /*
+ * We use a class initializer to allow the native code to cache some
+ * field offsets.
+ */
+ private static native void nativeClassInit();
+ static { nativeClassInit(); }
+}