Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0694cfe4 authored by tedbo's avatar tedbo Committed by Android (Google) Code Review
Browse files

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

parents 09011777 4e8a5c92
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -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 },
+6 −1
Original line number Diff line number Diff line
@@ -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);
+18 −2
Original line number Diff line number Diff line
@@ -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);
+5 −0
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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);
Loading