Add method to create a ParcelSurfaceTexture from android.view.Surface.

Change-Id: I05e343ab7e327478f60322af9373574b70c148f5
This commit is contained in:
tedbo
2011-06-22 15:52:53 -07:00
parent 0f5d8441ef
commit 4e8a5c922c
6 changed files with 51 additions and 6 deletions

View File

@@ -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 },

View File

@@ -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);

View File

@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -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;
}