summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedbo <tedbo@google.com>2011-06-06 16:02:47 -0700
committertedbo <tedbo@google.com>2011-06-09 11:59:23 -0700
commit050316184b01c0d1a01c46afae7429b89a27c31b (patch)
treeb21b202cd5345f3989b512b74b227f3fc910383a
parent890e013c05ed62bea9781168f3f65efebcbac4d5 (diff)
downloadframeworks_base-050316184b01c0d1a01c46afae7429b89a27c31b.zip
frameworks_base-050316184b01c0d1a01c46afae7429b89a27c31b.tar.gz
frameworks_base-050316184b01c0d1a01c46afae7429b89a27c31b.tar.bz2
Add ParcelSurfaceTexture Java class to enable ISurfaceTexture sharing via Binder.
This adds a new ParcelSurfaceTexture.java class that can be instantiated with a SurfaceTexture and used to send the corresponding ISurfaceTexture interface to another process via Binder. The ParcelSurfaceTexture java object can then be used to create an ANativeWindow based on the SurfaceTextureClient interface. Change-Id: Ie38ea948b866e52f36a6d0f6cde19b54a8546817
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/AndroidRuntime.cpp2
-rw-r--r--core/jni/android/graphics/ParcelSurfaceTexture.cpp152
-rw-r--r--core/jni/android/graphics/SurfaceTexture.cpp18
-rw-r--r--core/jni/android/graphics/SurfaceTexture.h31
-rw-r--r--core/jni/android_view_Surface.cpp10
-rw-r--r--graphics/java/android/graphics/ParcelSurfaceTexture.aidl19
-rw-r--r--graphics/java/android/graphics/ParcelSurfaceTexture.java102
-rw-r--r--graphics/java/android/graphics/SurfaceTexture.java11
-rw-r--r--include/android_runtime/android_graphics_ParcelSurfaceTexture.h32
-rw-r--r--include/android_runtime/android_graphics_SurfaceTexture.h2
-rw-r--r--include/android_runtime/android_view_Surface.h1
-rw-r--r--native/android/native_window.cpp10
13 files changed, 385 insertions, 6 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 223008c..51cc8e9 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -105,6 +105,7 @@ LOCAL_SRC_FILES:= \
android/graphics/NinePatchImpl.cpp \
android/graphics/NinePatchPeeker.cpp \
android/graphics/Paint.cpp \
+ android/graphics/ParcelSurfaceTexture.cpp \
android/graphics/Path.cpp \
android/graphics/PathMeasure.cpp \
android/graphics/PathEffect.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index e610640..2de728e 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -105,6 +105,7 @@ extern int register_android_graphics_ColorFilter(JNIEnv* env);
extern int register_android_graphics_DrawFilter(JNIEnv* env);
extern int register_android_graphics_Matrix(JNIEnv* env);
extern int register_android_graphics_Paint(JNIEnv* env);
+extern int register_android_graphics_ParcelSurfaceTexture(JNIEnv* env);
extern int register_android_graphics_Path(JNIEnv* env);
extern int register_android_graphics_PathMeasure(JNIEnv* env);
extern int register_android_graphics_Picture(JNIEnv*);
@@ -1144,6 +1145,7 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_graphics_Movie),
REG_JNI(register_android_graphics_NinePatch),
REG_JNI(register_android_graphics_Paint),
+ REG_JNI(register_android_graphics_ParcelSurfaceTexture),
REG_JNI(register_android_graphics_Path),
REG_JNI(register_android_graphics_PathMeasure),
REG_JNI(register_android_graphics_PathEffect),
diff --git a/core/jni/android/graphics/ParcelSurfaceTexture.cpp b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
new file mode 100644
index 0000000..517d7e2
--- /dev/null
+++ b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2011 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 "ParcelSurfaceTexture"
+
+#include <gui/SurfaceTextureClient.h>
+
+#include <android_runtime/AndroidRuntime.h>
+
+#include <utils/Log.h>
+
+#include <binder/Parcel.h>
+
+#include "android_util_Binder.h"
+#include "jni.h"
+#include "JNIHelp.h"
+#include "SurfaceTexture.h"
+
+// ----------------------------------------------------------------------------
+
+namespace android {
+
+const char* const kParcelSurfaceTextureClassPathName =
+ "android/graphics/ParcelSurfaceTexture";
+
+struct fields_t {
+ jfieldID iSurfaceTexture;
+};
+static fields_t fields;
+
+#define ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID "mISurfaceTexture"
+
+// ----------------------------------------------------------------------------
+
+static void ParcelSurfaceTexture_setISurfaceTexture(
+ JNIEnv* env, jobject thiz, const sp<ISurfaceTexture>& iSurfaceTexture)
+{
+ ISurfaceTexture* const p =
+ (ISurfaceTexture*)env->GetIntField(thiz, fields.iSurfaceTexture);
+ if (iSurfaceTexture.get()) {
+ iSurfaceTexture->incStrong(thiz);
+ }
+ if (p) {
+ p->decStrong(thiz);
+ }
+ env->SetIntField(thiz, fields.iSurfaceTexture, (int)iSurfaceTexture.get());
+}
+
+static sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
+ JNIEnv* env, jobject thiz)
+{
+ sp<ISurfaceTexture> iSurfaceTexture(
+ (ISurfaceTexture*)env->GetIntField(thiz, fields.iSurfaceTexture));
+ return iSurfaceTexture;
+}
+
+sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
+ JNIEnv* env, jobject thiz)
+{
+ sp<ISurfaceTexture> iSurfaceTexture(
+ ParcelSurfaceTexture_getISurfaceTexture(env, thiz));
+ sp<SurfaceTextureClient> surfaceTextureClient(iSurfaceTexture != NULL ?
+ new SurfaceTextureClient(iSurfaceTexture) : NULL);
+ return surfaceTextureClient;
+}
+
+bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz)
+{
+ jclass parcelSurfaceTextureClass = env->FindClass(
+ kParcelSurfaceTextureClassPathName);
+ return env->IsInstanceOf(thiz, parcelSurfaceTextureClass);
+}
+
+// ----------------------------------------------------------------------------
+
+static void ParcelSurfaceTexture_classInit(JNIEnv* env, jclass clazz)
+{
+ fields.iSurfaceTexture =
+ env->GetFieldID(clazz, ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID, "I");
+ if (fields.iSurfaceTexture == NULL) {
+ LOGE("can't find android/graphics/ParcelSurfaceTexture.%s",
+ ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID);
+ }
+}
+
+static void ParcelSurfaceTexture_init(JNIEnv* env, jobject thiz, jobject jSurfaceTexture)
+{
+ sp<ISurfaceTexture> iSurfaceTexture(
+ SurfaceTexture_getSurfaceTexture(env, jSurfaceTexture));
+ ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
+}
+
+static void ParcelSurfaceTexture_finalize(JNIEnv* env, jobject thiz)
+{
+ ParcelSurfaceTexture_setISurfaceTexture(env, thiz, 0);
+}
+
+static void ParcelSurfaceTexture_writeToParcel(
+ JNIEnv* env, jobject thiz, jobject jParcel, jint flags)
+{
+ Parcel* parcel = parcelForJavaObject(env, jParcel);
+ sp<ISurfaceTexture> iSurfaceTexture(
+ ParcelSurfaceTexture_getISurfaceTexture(env, thiz));
+ sp<IBinder> b(iSurfaceTexture->asBinder());
+ parcel->writeStrongBinder(b);
+}
+
+static void ParcelSurfaceTexture_readFromParcel(
+ JNIEnv* env, jobject thiz, jobject jParcel)
+{
+ Parcel* parcel = parcelForJavaObject(env, jParcel);
+ sp<ISurfaceTexture> iSurfaceTexture(
+ interface_cast<ISurfaceTexture>(parcel->readStrongBinder()));
+ ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
+}
+
+// ----------------------------------------------------------------------------
+
+static JNINativeMethod gParcelSurfaceTextureMethods[] = {
+ {"nativeClassInit", "()V", (void*)ParcelSurfaceTexture_classInit },
+ {"nativeInit", "(Landroid/graphics/SurfaceTexture;)V",
+ (void *)ParcelSurfaceTexture_init },
+ { "nativeFinalize", "()V", (void *)ParcelSurfaceTexture_finalize },
+ { "nativeWriteToParcel", "(Landroid/os/Parcel;I)V",
+ (void *)ParcelSurfaceTexture_writeToParcel },
+ { "nativeReadFromParcel", "(Landroid/os/Parcel;)V",
+ (void *)ParcelSurfaceTexture_readFromParcel },
+};
+
+
+int register_android_graphics_ParcelSurfaceTexture(JNIEnv* env)
+{
+ int err = 0;
+ err = AndroidRuntime::registerNativeMethods(env, kParcelSurfaceTextureClassPathName,
+ gParcelSurfaceTextureMethods, NELEM(gParcelSurfaceTextureMethods));
+ return err;
+}
+
+} // namespace android
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp
index 2f70190..3f922f6 100644
--- a/core/jni/android/graphics/SurfaceTexture.cpp
+++ b/core/jni/android/graphics/SurfaceTexture.cpp
@@ -35,6 +35,7 @@ namespace android {
static const char* const OutOfResourcesException =
"android/graphics/SurfaceTexture$OutOfResourcesException";
+const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
struct fields_t {
jfieldID surfaceTexture;
@@ -74,6 +75,12 @@ sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(
return surfaceTextureClient;
}
+bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz)
+{
+ jclass surfaceTextureClass = env->FindClass(kSurfaceTextureClassPathName);
+ return env->IsInstanceOf(thiz, surfaceTextureClass);
+}
+
// ----------------------------------------------------------------------------
class JNISurfaceTextureContext : public SurfaceTexture::FrameAvailableListener
@@ -123,7 +130,6 @@ static void SurfaceTexture_classInit(JNIEnv* env, jclass clazz)
if (fields.postEvent == NULL) {
LOGE("can't find android/graphics/SurfaceTexture.postEventFromNative");
}
-
}
static void SurfaceTexture_init(JNIEnv* env, jobject thiz, jint texName,
@@ -156,6 +162,13 @@ static void SurfaceTexture_finalize(JNIEnv* env, jobject thiz)
SurfaceTexture_setSurfaceTexture(env, thiz, 0);
}
+static void SurfaceTexture_setDefaultBufferSize(
+ JNIEnv* env, jobject thiz, jint width, jint height)
+{
+ sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
+ surfaceTexture->setDefaultBufferSize(width, height);
+}
+
static void SurfaceTexture_updateTexImage(JNIEnv* env, jobject thiz)
{
sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, thiz));
@@ -179,12 +192,11 @@ static jlong SurfaceTexture_getTimestamp(JNIEnv* env, jobject thiz)
// ----------------------------------------------------------------------------
-const char* const kSurfaceTextureClassPathName = "android/graphics/SurfaceTexture";
-
static JNINativeMethod gSurfaceTextureMethods[] = {
{"nativeClassInit", "()V", (void*)SurfaceTexture_classInit },
{"nativeInit", "(ILjava/lang/Object;)V", (void*)SurfaceTexture_init },
{"nativeFinalize", "()V", (void*)SurfaceTexture_finalize },
+ {"nativeSetDefaultBufferSize", "(II)V", (void*)SurfaceTexture_setDefaultBufferSize },
{"nativeUpdateTexImage", "()V", (void*)SurfaceTexture_updateTexImage },
{"nativeGetTransformMatrix", "([F)V", (void*)SurfaceTexture_getTransformMatrix },
{"nativeGetTimestamp", "()J", (void*)SurfaceTexture_getTimestamp }
diff --git a/core/jni/android/graphics/SurfaceTexture.h b/core/jni/android/graphics/SurfaceTexture.h
new file mode 100644
index 0000000..79d8dd3
--- /dev/null
+++ b/core/jni/android/graphics/SurfaceTexture.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#ifndef _ANDROID_GRAPHICS_SURFACETEXTURE_H
+#define _ANDROID_GRAPHICS_SURFACETEXTURE_H
+
+#include <gui/SurfaceTexture.h>
+#include <utils/StrongPointer.h>
+#include "jni.h"
+
+namespace android {
+
+/* Gets the underlying SurfaceTexture from a SurfaceTexture Java object. */
+sp<SurfaceTexture> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz);
+
+} // namespace android
+
+#endif // _ANDROID_GRAPHICS_SURFACETEXTURE_H
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index ec8b6e0..70c2f7b 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -55,6 +55,9 @@ enum {
static const char* const OutOfResourcesException =
"android/view/Surface$OutOfResourcesException";
+const char* const kSurfaceSessionClassPathName = "android/view/SurfaceSession";
+const char* const kSurfaceClassPathName = "android/view/Surface";
+
struct sso_t {
jfieldID client;
};
@@ -181,6 +184,11 @@ sp<ANativeWindow> android_Surface_getNativeWindow(
return getSurface(env, clazz);
}
+bool android_Surface_isInstanceOf(JNIEnv* env, jobject obj) {
+ jclass surfaceClass = env->FindClass(kSurfaceClassPathName);
+ return env->IsInstanceOf(obj, surfaceClass);
+}
+
static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)
{
Surface* const p = (Surface*)env->GetIntField(clazz, so.surface);
@@ -759,8 +767,6 @@ static void Surface_writeToParcel(
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
-const char* const kSurfaceSessionClassPathName = "android/view/SurfaceSession";
-const char* const kSurfaceClassPathName = "android/view/Surface";
static void nativeClassInit(JNIEnv* env, jclass clazz);
static JNINativeMethod gSurfaceSessionMethods[] = {
diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.aidl b/graphics/java/android/graphics/ParcelSurfaceTexture.aidl
new file mode 100644
index 0000000..35ff285
--- /dev/null
+++ b/graphics/java/android/graphics/ParcelSurfaceTexture.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, 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;
+
+parcelable ParcelSurfaceTexture;
diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.java b/graphics/java/android/graphics/ParcelSurfaceTexture.java
new file mode 100644
index 0000000..5272cc6
--- /dev/null
+++ b/graphics/java/android/graphics/ParcelSurfaceTexture.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2011 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;
+
+import android.graphics.SurfaceTexture;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ *
+ * @hide Pending review by API council.
+ */
+public final class ParcelSurfaceTexture implements Parcelable {
+ /**
+ * This field is used by native code, do not access or modify.
+ *
+ * @hide
+ */
+ @SuppressWarnings({"UnusedDeclaration"})
+ private int mISurfaceTexture;
+
+ /**
+ * Create a new ParcelSurfaceTexture from a SurfaceTexture
+ *
+ * @param surfaceTexture The SurfaceTexture to transport.
+ *
+ * @return Returns a new ParcelSurfaceTexture for the given SurfaceTexture.
+ */
+ public static ParcelSurfaceTexture fromSurfaceTexture(SurfaceTexture surfaceTexture) {
+ return new ParcelSurfaceTexture(surfaceTexture);
+ }
+
+ /**
+ * @see android.os.Parcelable#describeContents()
+ */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ nativeWriteToParcel(dest, flags);
+ }
+
+ public static final Parcelable.Creator<ParcelSurfaceTexture> CREATOR =
+ new Parcelable.Creator<ParcelSurfaceTexture>() {
+ @Override
+ public ParcelSurfaceTexture createFromParcel(Parcel in) {
+ return new ParcelSurfaceTexture(in);
+ }
+ @Override
+ public ParcelSurfaceTexture[] newArray(int size) {
+ return new ParcelSurfaceTexture[size];
+ }
+ };
+
+ private ParcelSurfaceTexture(Parcel in) {
+ nativeReadFromParcel(in);
+ }
+ private ParcelSurfaceTexture(SurfaceTexture surfaceTexture) {
+ nativeInit(surfaceTexture);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ nativeFinalize();
+ } finally {
+ super.finalize();
+ }
+ }
+
+ private native void nativeInit(SurfaceTexture surfaceTexture);
+ private native void nativeFinalize();
+ private native void nativeWriteToParcel(Parcel dest, int flags);
+ private native void nativeReadFromParcel(Parcel in);
+
+ /*
+ * We use a class initializer to allow the native code to cache some
+ * field offsets.
+ */
+ private static native void nativeClassInit();
+ static { nativeClassInit(); }
+}
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index 3c43a39..0ffd201 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -118,6 +118,16 @@ public class SurfaceTexture {
}
/**
+ * Set the size of buffers returned by requestBuffers when a width and height
+ * of zero is requested.
+ *
+ * @hide Pending approval by API council.
+ */
+ public void setDefaultBufferSize(int width, int height) {
+ nativeSetDefaultBufferSize(width, height);
+ }
+
+ /**
* 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.
@@ -206,6 +216,7 @@ public class SurfaceTexture {
private native void nativeFinalize();
private native void nativeGetTransformMatrix(float[] mtx);
private native long nativeGetTimestamp();
+ private native void nativeSetDefaultBufferSize(int width, int height);
private native void nativeUpdateTexImage();
/*
diff --git a/include/android_runtime/android_graphics_ParcelSurfaceTexture.h b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
new file mode 100644
index 0000000..22f1c12
--- /dev/null
+++ b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+#ifndef _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
+#define _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
+
+#include <android/native_window.h>
+
+#include "jni.h"
+
+namespace android {
+
+extern sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
+ JNIEnv* env, jobject thiz);
+extern bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
+
+} // namespace android
+
+#endif // _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
diff --git a/include/android_runtime/android_graphics_SurfaceTexture.h b/include/android_runtime/android_graphics_SurfaceTexture.h
index 8e6fc6e..acf1ca8 100644
--- a/include/android_runtime/android_graphics_SurfaceTexture.h
+++ b/include/android_runtime/android_graphics_SurfaceTexture.h
@@ -25,6 +25,8 @@ namespace android {
extern sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(
JNIEnv* env, jobject thiz);
+extern bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
+
} // namespace android
diff --git a/include/android_runtime/android_view_Surface.h b/include/android_runtime/android_view_Surface.h
index c37932e..317f1e7 100644
--- a/include/android_runtime/android_view_Surface.h
+++ b/include/android_runtime/android_view_Surface.h
@@ -25,6 +25,7 @@ namespace android {
extern sp<ANativeWindow> android_Surface_getNativeWindow(
JNIEnv* env, jobject clazz);
+extern bool android_Surface_isInstanceOf(JNIEnv* env, jobject obj);
} // namespace android
diff --git a/native/android/native_window.cpp b/native/android/native_window.cpp
index 8d42edb..2c0e88e 100644
--- a/native/android/native_window.cpp
+++ b/native/android/native_window.cpp
@@ -20,12 +20,20 @@
#include <android/native_window_jni.h>
#include <surfaceflinger/Surface.h>
#include <android_runtime/android_view_Surface.h>
+#include <android_runtime/android_graphics_ParcelSurfaceTexture.h>
#include <android_runtime/android_graphics_SurfaceTexture.h>
using namespace android;
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) {
- sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface);
+ sp<ANativeWindow> win;
+ if (android_Surface_isInstanceOf(env, surface)) {
+ win = android_Surface_getNativeWindow(env, surface);
+ } else if (android_SurfaceTexture_isInstanceOf(env, surface)) {
+ win = android_SurfaceTexture_getNativeWindow(env, surface);
+ } else if (android_ParcelSurfaceTexture_isInstanceOf(env, surface)) {
+ win = android_ParcelSurfaceTexture_getNativeWindow(env, surface);
+ }
if (win != NULL) {
win->incStrong((void*)ANativeWindow_acquire);
}