diff options
| author | tedbo <tedbo@google.com> | 2011-06-22 15:52:53 -0700 |
|---|---|---|
| committer | tedbo <tedbo@google.com> | 2011-06-22 16:18:09 -0700 |
| commit | 4e8a5c922c287ec97fec847194e930f8598a1941 (patch) | |
| tree | 4cb995f8d142f646a8c99d9818b6cdee456de398 | |
| parent | 0f5d8441ef3ee88855df71b15d81f4c14f12d63d (diff) | |
| download | frameworks_base-4e8a5c922c287ec97fec847194e930f8598a1941.zip frameworks_base-4e8a5c922c287ec97fec847194e930f8598a1941.tar.gz frameworks_base-4e8a5c922c287ec97fec847194e930f8598a1941.tar.bz2 | |
Add method to create a ParcelSurfaceTexture from android.view.Surface.
Change-Id: I05e343ab7e327478f60322af9373574b70c148f5
| -rw-r--r-- | core/jni/android/graphics/ParcelSurfaceTexture.cpp | 19 | ||||
| -rw-r--r-- | core/jni/android_view_Surface.cpp | 7 | ||||
| -rw-r--r-- | graphics/java/android/graphics/ParcelSurfaceTexture.java | 20 | ||||
| -rw-r--r-- | include/android_runtime/android_view_Surface.h | 5 | ||||
| -rw-r--r-- | include/surfaceflinger/Surface.h | 2 | ||||
| -rw-r--r-- | 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 40966e1..754485f 100644 --- a/core/jni/android/graphics/ParcelSurfaceTexture.cpp +++ b/core/jni/android/graphics/ParcelSurfaceTexture.cpp @@ -17,9 +17,11 @@ #define LOG_TAG "ParcelSurfaceTexture" #include <gui/SurfaceTextureClient.h> +#include <surfaceflinger/Surface.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/android_graphics_SurfaceTexture.h> +#include <android_runtime/android_view_Surface.h> #include <utils/Log.h> @@ -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(Surface_getSurface(env, jSurface)); + sp<ISurfaceTexture> iSurfaceTexture(surface->getSurfaceTexture()); + ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture); +} + +static void ParcelSurfaceTexture_initFromSurfaceTexture( + JNIEnv* env, jobject thiz, jobject jSurfaceTexture) { sp<ISurfaceTexture> 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 70c2f7b..0dc9293 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<Surface> getSurface(JNIEnv* env, jobject clazz) { - sp<Surface> result((Surface*)env->GetIntField(clazz, so.surface)); + sp<Surface> 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> Surface_getSurface(JNIEnv* env, jobject clazz) { + sp<Surface> surface((Surface*)env->GetIntField(clazz, so.surface)); + return surface; +} + static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& 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 5272cc6..cc8bd02 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; /** * @@ -34,6 +35,17 @@ public final class ParcelSurfaceTexture implements Parcelable { 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 * * @param surfaceTexture The SurfaceTexture to transport. @@ -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 317f1e7..fb0b057 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<ANativeWindow> 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> 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 8845dc9..dc2a845 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<ISurfaceTexture> 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 4d1d923..9185e1e 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<ISurfaceTexture> Surface::getSurfaceTexture() { + return mSurface != NULL ? mSurface->getSurfaceTexture() : NULL; +} + sp<IBinder> Surface::asBinder() const { return mSurface!=0 ? mSurface->asBinder() : 0; } |
