summaryrefslogtreecommitdiffstats
path: root/core/jni
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 /core/jni
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 'core/jni')
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/android/graphics/SurfaceTexture.cpp110
2 files changed, 111 insertions, 0 deletions
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