summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorTed Bonkenburg <tedbo@google.com>2011-07-25 10:24:30 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-07-25 10:24:30 -0700
commit5518dd92d38edd5902482841413722aa654cc2e7 (patch)
tree8fed33fc854d72b0000c8ad99565f8377c7e6607 /core
parent63d050034df5eedc9586e393d56444cd34681bd1 (diff)
parent0de171b0d490a5928d54d2fb67c912d140aac643 (diff)
downloadframeworks_base-5518dd92d38edd5902482841413722aa654cc2e7.zip
frameworks_base-5518dd92d38edd5902482841413722aa654cc2e7.tar.gz
frameworks_base-5518dd92d38edd5902482841413722aa654cc2e7.tar.bz2
Merge "Add support for creating a Surface from a a SurfaceTexture."
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/Surface.java18
-rw-r--r--core/jni/android_view_Surface.cpp36
2 files changed, 52 insertions, 2 deletions
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index c913bb3..836867b 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -161,6 +161,9 @@ public class Surface implements Parcelable {
*/
public static final int FLAGS_ORIENTATION_ANIMATION_DISABLE = 0x000000001;
+ // The mSurfaceControl will only be present for Surfaces used by the window
+ // server or system processes. When this class is parceled we defer to the
+ // mSurfaceControl to do the parceling. Otherwise we parcel the mNativeSurface.
@SuppressWarnings("unused")
private int mSurfaceControl;
@SuppressWarnings("unused")
@@ -202,6 +205,19 @@ public class Surface implements Parcelable {
native private static void nativeClassInit();
static { nativeClassInit(); }
+ /**
+ * Create Surface from a SurfaceTexture.
+ *
+ * @param surfaceTexture The {@link SurfaceTexture} that is updated by this Surface.
+ * @hide
+ */
+ public Surface(SurfaceTexture surfaceTexture) {
+ if (DEBUG_RELEASE) {
+ mCreationStack = new Exception();
+ }
+ mCanvas = new CompatibleCanvas();
+ initFromSurfaceTexture(surfaceTexture);
+ }
/**
* create a surface
@@ -505,5 +521,7 @@ public class Surface implements Parcelable {
private native void init(Parcel source);
+ private native void initFromSurfaceTexture(SurfaceTexture surfaceTexture);
+
private native int getIdentity();
}
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 0dc9293..4c1ca31 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -22,6 +22,7 @@
#include "android/graphics/GraphicsJNI.h"
#include <binder/IMemory.h>
+#include <gui/SurfaceTexture.h>
#include <surfaceflinger/SurfaceComposerClient.h>
#include <surfaceflinger/Surface.h>
#include <ui/Region.h>
@@ -38,6 +39,7 @@
#include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_view_Surface.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
#include <utils/misc.h>
@@ -244,6 +246,19 @@ static void Surface_init(
setSurfaceControl(env, clazz, surface);
}
+static void Surface_initFromSurfaceTexture(
+ JNIEnv* env, jobject clazz, jobject jst)
+{
+ sp<ISurfaceTexture> st(SurfaceTexture_getSurfaceTexture(env, jst));
+ sp<Surface> surface(new Surface(st));
+ if (surface == NULL) {
+ jniThrowException(env, OutOfResourcesException, NULL);
+ return;
+ }
+ setSurfaceControl(env, clazz, NULL);
+ setSurface(env, clazz, surface);
+}
+
static void Surface_initParcel(JNIEnv* env, jobject clazz, jobject argParcel)
{
Parcel* parcel = (Parcel*)env->GetIntField(argParcel, no.native_parcel);
@@ -761,10 +776,26 @@ static void Surface_writeToParcel(
return;
}
+ // The Java instance may have a SurfaceControl (in the case of the
+ // WindowManager or a system app). In that case, we defer to the
+ // SurfaceControl to send its ISurface. Otherwise, if the Surface is
+ // available we let it parcel itself. Finally, if the Surface is also
+ // NULL we fall back to using the SurfaceControl path which sends an
+ // empty surface; this matches legacy behavior.
const sp<SurfaceControl>& control(getSurfaceControl(env, clazz));
- SurfaceControl::writeSurfaceToParcel(control, parcel);
+ if (control != NULL) {
+ SurfaceControl::writeSurfaceToParcel(control, parcel);
+ } else {
+ sp<Surface> surface(Surface_getSurface(env, clazz));
+ if (surface != NULL) {
+ Surface::writeToParcel(surface, parcel);
+ } else {
+ SurfaceControl::writeSurfaceToParcel(NULL, parcel);
+ }
+ }
if (flags & PARCELABLE_WRITE_RETURN_VALUE) {
- setSurfaceControl(env, clazz, 0);
+ setSurfaceControl(env, clazz, NULL);
+ setSurface(env, clazz, NULL);
}
}
@@ -784,6 +815,7 @@ static JNINativeMethod gSurfaceMethods[] = {
{"nativeClassInit", "()V", (void*)nativeClassInit },
{"init", "(Landroid/view/SurfaceSession;ILjava/lang/String;IIIII)V", (void*)Surface_init },
{"init", "(Landroid/os/Parcel;)V", (void*)Surface_initParcel },
+ {"initFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)V", (void*)Surface_initFromSurfaceTexture },
{"getIdentity", "()I", (void*)Surface_getIdentity },
{"destroy", "()V", (void*)Surface_destroy },
{"release", "()V", (void*)Surface_release },