From 4e8a5c922c287ec97fec847194e930f8598a1941 Mon Sep 17 00:00:00 2001 From: tedbo Date: Wed, 22 Jun 2011 15:52:53 -0700 Subject: [PATCH] Add method to create a ParcelSurfaceTexture from android.view.Surface. Change-Id: I05e343ab7e327478f60322af9373574b70c148f5 --- .../android/graphics/ParcelSurfaceTexture.cpp | 19 +++++++++++++++--- core/jni/android_view_Surface.cpp | 7 ++++++- .../graphics/ParcelSurfaceTexture.java | 20 +++++++++++++++++-- .../android_runtime/android_view_Surface.h | 5 +++++ include/surfaceflinger/Surface.h | 2 ++ libs/gui/Surface.cpp | 4 ++++ 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/core/jni/android/graphics/ParcelSurfaceTexture.cpp b/core/jni/android/graphics/ParcelSurfaceTexture.cpp index 40966e1135c4e..754485f9ea4f4 100644 --- a/core/jni/android/graphics/ParcelSurfaceTexture.cpp +++ b/core/jni/android/graphics/ParcelSurfaceTexture.cpp @@ -17,9 +17,11 @@ #define LOG_TAG "ParcelSurfaceTexture" #include +#include #include #include +#include #include @@ -96,7 +98,16 @@ static void ParcelSurfaceTexture_classInit(JNIEnv* env, jclass clazz) } } -static void ParcelSurfaceTexture_init(JNIEnv* env, jobject thiz, jobject jSurfaceTexture) +static void ParcelSurfaceTexture_initFromSurface( + JNIEnv* env, jobject thiz, jobject jSurface) +{ + sp surface(Surface_getSurface(env, jSurface)); + sp iSurfaceTexture(surface->getSurfaceTexture()); + ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture); +} + +static void ParcelSurfaceTexture_initFromSurfaceTexture( + JNIEnv* env, jobject thiz, jobject jSurfaceTexture) { sp iSurfaceTexture( SurfaceTexture_getSurfaceTexture(env, jSurfaceTexture)); @@ -131,8 +142,10 @@ static void ParcelSurfaceTexture_readFromParcel( static JNINativeMethod gParcelSurfaceTextureMethods[] = { {"nativeClassInit", "()V", (void*)ParcelSurfaceTexture_classInit }, - {"nativeInit", "(Landroid/graphics/SurfaceTexture;)V", - (void *)ParcelSurfaceTexture_init }, + {"nativeInitFromSurface", "(Landroid/view/Surface;)V", + (void *)ParcelSurfaceTexture_initFromSurface }, + {"nativeInitFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)V", + (void *)ParcelSurfaceTexture_initFromSurfaceTexture }, { "nativeFinalize", "()V", (void *)ParcelSurfaceTexture_finalize }, { "nativeWriteToParcel", "(Landroid/os/Parcel;I)V", (void *)ParcelSurfaceTexture_writeToParcel }, diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 70c2f7b412510..0dc92934fdd97 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -156,7 +156,7 @@ static void setSurfaceControl(JNIEnv* env, jobject clazz, static sp getSurface(JNIEnv* env, jobject clazz) { - sp result((Surface*)env->GetIntField(clazz, so.surface)); + sp result(Surface_getSurface(env, clazz)); if (result == 0) { /* * if this method is called from the WindowManager's process, it means @@ -189,6 +189,11 @@ bool android_Surface_isInstanceOf(JNIEnv* env, jobject obj) { return env->IsInstanceOf(obj, surfaceClass); } +sp Surface_getSurface(JNIEnv* env, jobject clazz) { + sp surface((Surface*)env->GetIntField(clazz, so.surface)); + return surface; +} + static void setSurface(JNIEnv* env, jobject clazz, const sp& surface) { Surface* const p = (Surface*)env->GetIntField(clazz, so.surface); diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.java b/graphics/java/android/graphics/ParcelSurfaceTexture.java index 5272cc6f7831d..cc8bd02de19fc 100644 --- a/graphics/java/android/graphics/ParcelSurfaceTexture.java +++ b/graphics/java/android/graphics/ParcelSurfaceTexture.java @@ -19,6 +19,7 @@ package android.graphics; import android.graphics.SurfaceTexture; import android.os.Parcel; import android.os.Parcelable; +import android.view.Surface; /** * @@ -33,6 +34,17 @@ public final class ParcelSurfaceTexture implements Parcelable { @SuppressWarnings({"UnusedDeclaration"}) private int mISurfaceTexture; + /** + * Create a new ParcelSurfaceTexture from a Surface + * + * @param surface The Surface to create a ParcelSurfaceTexture from. + * + * @return Returns a new ParcelSurfaceTexture for the given Surface. + */ + public static ParcelSurfaceTexture fromSurface(Surface surface) { + return new ParcelSurfaceTexture(surface); + } + /** * Create a new ParcelSurfaceTexture from a SurfaceTexture * @@ -75,8 +87,11 @@ public final class ParcelSurfaceTexture implements Parcelable { private ParcelSurfaceTexture(Parcel in) { nativeReadFromParcel(in); } + private ParcelSurfaceTexture(Surface surface) { + nativeInitFromSurface(surface); + } private ParcelSurfaceTexture(SurfaceTexture surfaceTexture) { - nativeInit(surfaceTexture); + nativeInitFromSurfaceTexture(surfaceTexture); } @Override @@ -88,7 +103,8 @@ public final class ParcelSurfaceTexture implements Parcelable { } } - private native void nativeInit(SurfaceTexture surfaceTexture); + private native void nativeInitFromSurface(Surface surface); + private native void nativeInitFromSurfaceTexture(SurfaceTexture surfaceTexture); private native void nativeFinalize(); private native void nativeWriteToParcel(Parcel dest, int flags); private native void nativeReadFromParcel(Parcel in); diff --git a/include/android_runtime/android_view_Surface.h b/include/android_runtime/android_view_Surface.h index 317f1e71c5f9a..fb0b057c28ef8 100644 --- a/include/android_runtime/android_view_Surface.h +++ b/include/android_runtime/android_view_Surface.h @@ -23,10 +23,15 @@ namespace android { +class Surface; + extern sp android_Surface_getNativeWindow( JNIEnv* env, jobject clazz); extern bool android_Surface_isInstanceOf(JNIEnv* env, jobject obj); +/* Gets the underlying Surface from a Surface Java object. */ +extern sp Surface_getSurface(JNIEnv* env, jobject thiz); + } // namespace android #endif // _ANDROID_VIEW_SURFACE_H diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h index 8845dc9e1cb0e..dc2a845620828 100644 --- a/include/surfaceflinger/Surface.h +++ b/include/surfaceflinger/Surface.h @@ -40,6 +40,7 @@ namespace android { class GraphicBuffer; class GraphicBufferMapper; class IOMX; +class ISurfaceTexture; class Rect; class Surface; class SurfaceComposerClient; @@ -154,6 +155,7 @@ public: bool isValid(); uint32_t getFlags() const { return mFlags; } uint32_t getIdentity() const { return mIdentity; } + sp getSurfaceTexture(); // the lock/unlock APIs must be used from the same thread status_t lock(SurfaceInfo* info, bool blocking = true); diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 4d1d923a42626..9185e1e9930cc 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -421,6 +421,10 @@ status_t Surface::validate(bool inCancelBuffer) const return NO_ERROR; } +sp Surface::getSurfaceTexture() { + return mSurface != NULL ? mSurface->getSurfaceTexture() : NULL; +} + sp Surface::asBinder() const { return mSurface!=0 ? mSurface->asBinder() : 0; }