summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.xml64
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/android/graphics/SurfaceTexture.cpp110
-rw-r--r--graphics/java/android/graphics/SurfaceTexture.java90
4 files changed, 265 insertions, 0 deletions
diff --git a/api/current.xml b/api/current.xml
index 112c147..d353d72 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -85932,6 +85932,70 @@
</parameter>
</constructor>
</class>
+<class name="SurfaceTexture"
+ extends="java.lang.Object"
+ abstract="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="SurfaceTexture"
+ type="android.graphics.SurfaceTexture"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="texName" type="int">
+</parameter>
+</constructor>
+<method name="setOnFrameAvailableListener"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="l" type="android.graphics.SurfaceTexture.OnFrameAvailableListener">
+</parameter>
+</method>
+<method name="updateTexImage"
+ return="void"
+ abstract="false"
+ native="true"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+</class>
+<interface name="SurfaceTexture.OnFrameAvailableListener"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="onFrameAvailable"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="surfaceTexture" type="android.graphics.SurfaceTexture">
+</parameter>
+</method>
+</interface>
<class name="SweepGradient"
extends="android.graphics.Shader"
abstract="false"
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 241bc3e..c635b39 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -111,6 +111,7 @@ LOCAL_SRC_FILES:= \
android/graphics/Rasterizer.cpp \
android/graphics/Region.cpp \
android/graphics/Shader.cpp \
+ android/graphics/SurfaceTexture.cpp \
android/graphics/TextLayout.cpp \
android/graphics/Typeface.cpp \
android/graphics/Utils.cpp \
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp
new file mode 100644
index 0000000..2645045
--- /dev/null
+++ b/core/jni/android/graphics/SurfaceTexture.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "SurfaceTexture"
+
+#include <stdio.h>
+
+#include <gui/SurfaceTexture.h>
+
+#include <android_runtime/AndroidRuntime.h>
+
+#include <utils/Log.h>
+#include <utils/misc.h>
+
+#include "android/graphics/GraphicsJNI.h"
+#include "jni.h"
+
+// ----------------------------------------------------------------------------
+
+namespace android {
+
+static const char* const OutOfResourcesException =
+ "android/graphics/SurfaceTexture$OutOfResourcesException";
+
+struct st_t {
+ jfieldID surfaceTexture;
+};
+static st_t st;
+
+// ----------------------------------------------------------------------------
+
+static void setSurfaceTexture(JNIEnv* env, jobject clazz,
+ const sp<SurfaceTexture>& surfaceTexture)
+{
+ SurfaceTexture* const p =
+ (SurfaceTexture*)env->GetIntField(clazz, st.surfaceTexture);
+ if (surfaceTexture.get()) {
+ surfaceTexture->incStrong(clazz);
+ }
+ if (p) {
+ p->decStrong(clazz);
+ }
+ env->SetIntField(clazz, st.surfaceTexture, (int)surfaceTexture.get());
+}
+
+sp<SurfaceTexture> getSurfaceTexture(JNIEnv* env, jobject clazz)
+{
+ sp<SurfaceTexture> surfaceTexture(
+ (SurfaceTexture*)env->GetIntField(clazz, st.surfaceTexture));
+ return surfaceTexture;
+}
+
+// ----------------------------------------------------------------------------
+
+static void SurfaceTexture_init(JNIEnv* env, jobject clazz, jint texName)
+{
+ sp<SurfaceTexture> surfaceTexture(new SurfaceTexture(texName));
+
+ if (surfaceTexture == 0) {
+ doThrow(env, OutOfResourcesException);
+ return;
+ }
+ setSurfaceTexture(env, clazz, surfaceTexture);
+}
+
+static void SurfaceTexture_updateTexImage(JNIEnv* env, jobject clazz)
+{
+ sp<SurfaceTexture> surfaceTexture(getSurfaceTexture(env, clazz));
+ surfaceTexture->updateTexImage();
+}
+
+// ----------------------------------------------------------------------------
+
+const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
+static void nativeClassInit(JNIEnv* env, jclass clazz);
+
+static JNINativeMethod gSurfaceTextureMethods[] = {
+ {"nativeClassInit", "()V", (void*)nativeClassInit },
+ {"init", "(I)V", (void*)SurfaceTexture_init },
+ {"updateTexImage", "()V", (void*)SurfaceTexture_updateTexImage },
+};
+
+static void nativeClassInit(JNIEnv* env, jclass clazz)
+{
+ st.surfaceTexture = env->GetFieldID(clazz,
+ ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I");
+}
+
+int register_android_graphics_SurfaceTexture(JNIEnv* env)
+{
+ int err = 0;
+ err = AndroidRuntime::registerNativeMethods(env, kSurfaceTextureClassPathName,
+ gSurfaceTextureMethods, NELEM(gSurfaceTextureMethods));
+ return err;
+}
+
+} // namespace android
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(); }
+}