diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/view/Surface.java | 21 | ||||
| -rw-r--r-- | core/java/android/view/SurfaceSession.java | 34 | ||||
| -rw-r--r-- | core/jni/android_view_Surface.cpp | 62 |
3 files changed, 70 insertions, 47 deletions
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index a6d1a3f..84b3d64 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -17,9 +17,15 @@ package android.view; import android.content.res.CompatibilityInfo.Translator; -import android.graphics.*; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Matrix; +import android.graphics.Rect; +import android.graphics.Region; +import android.graphics.SurfaceTexture; import android.os.Parcelable; import android.os.Parcel; +import android.os.Process; import android.os.SystemProperties; import android.util.Log; @@ -250,13 +256,20 @@ public class Surface implements Parcelable { public Surface(SurfaceSession s, int pid, String name, int layerStack, int w, int h, int format, int flags) throws OutOfResourcesException { + // FIXME: remove pid and layerstack arguments checkHeadless(); if (DEBUG_RELEASE) { mCreationStack = new Exception(); } + + if (name == null) { + name = "<pid " + Process.myPid() + ">"; + } + mCanvas = new CompatibleCanvas(); - init(s, pid, name, layerStack, w, h, format, flags); + init(s, name, w, h, format, flags); + setLayerStack(layerStack); mName = name; } @@ -496,8 +509,8 @@ public class Surface implements Parcelable { } } - private native void init(SurfaceSession s, - int pid, String name, int layerStack, int w, int h, int format, int flags) + private native void init(SurfaceSession s, String name, + int w, int h, int format, int flags) throws OutOfResourcesException; private native void init(Parcel source) throws OutOfResourcesException; diff --git a/core/java/android/view/SurfaceSession.java b/core/java/android/view/SurfaceSession.java index 2a04675..2491abe 100644 --- a/core/java/android/view/SurfaceSession.java +++ b/core/java/android/view/SurfaceSession.java @@ -24,26 +24,34 @@ package android.view; * {@hide} */ public class SurfaceSession { + private int mClient; + + private native void nativeInit(); + private native void nativeDestroy(); + private native void nativeKill(); + /** Create a new connection with the surface flinger. */ public SurfaceSession() { - init(); + nativeInit(); } - /** Forcibly detach native resources associated with this object. - * Unlike destroy(), after this call any surfaces that were created - * from the session will no longer work. The session itself is destroyed. - */ - public native void kill(); - /* no user serviceable parts here ... */ @Override protected void finalize() throws Throwable { - destroy(); + try { + nativeDestroy(); + } finally { + super.finalize(); + } + } + + /** + * Forcibly detach native resources associated with this object. + * Unlike destroy(), after this call any surfaces that were created + * from the session will no longer work. The session itself is destroyed. + */ + public void kill() { + nativeKill(); } - - private native void init(); - private native void destroy(); - - private int mClient; } diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index bada329..c302b23 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -23,6 +23,7 @@ #include <binder/IMemory.h> +#include <gui/ISurfaceComposer.h> #include <gui/Surface.h> #include <gui/SurfaceComposerClient.h> #include <gui/SurfaceTexture.h> @@ -107,14 +108,14 @@ static no_t no; // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- -static void SurfaceSession_init(JNIEnv* env, jobject clazz) +static void SurfaceSession_nativeInit(JNIEnv* env, jobject clazz) { sp<SurfaceComposerClient> client = new SurfaceComposerClient; client->incStrong(clazz); env->SetIntField(clazz, sso.client, (int)client.get()); } -static void SurfaceSession_destroy(JNIEnv* env, jobject clazz) +static void SurfaceSession_nativeDestroy(JNIEnv* env, jobject clazz) { SurfaceComposerClient* client = (SurfaceComposerClient*)env->GetIntField(clazz, sso.client); @@ -124,7 +125,7 @@ static void SurfaceSession_destroy(JNIEnv* env, jobject clazz) } } -static void SurfaceSession_kill(JNIEnv* env, jobject clazz) +static void SurfaceSession_nativeKill(JNIEnv* env, jobject clazz) { SurfaceComposerClient* client = (SurfaceComposerClient*)env->GetIntField(clazz, sso.client); @@ -221,7 +222,7 @@ void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface) static void Surface_init( JNIEnv* env, jobject clazz, jobject session, - jint, jstring jname, jint layerStack, jint w, jint h, jint format, jint flags) + jstring jname, jint w, jint h, jint format, jint flags) { if (session == NULL) { doThrowNPE(env); @@ -231,15 +232,10 @@ static void Surface_init( SurfaceComposerClient* client = (SurfaceComposerClient*)env->GetIntField(session, sso.client); - sp<SurfaceControl> surface; - if (jname == NULL) { - surface = client->createSurface(layerStack, w, h, format, flags); - } else { - const jchar* str = env->GetStringCritical(jname, 0); - const String8 name(str, env->GetStringLength(jname)); - env->ReleaseStringCritical(jname, str); - surface = client->createSurface(name, layerStack, w, h, format, flags); - } + const jchar* str = env->GetStringCritical(jname, 0); + const String8 name(str, env->GetStringLength(jname)); + env->ReleaseStringCritical(jname, str); + sp<SurfaceControl> surface = client->createSurface(name, w, h, format, flags); if (surface == 0) { jniThrowException(env, OutOfResourcesException, NULL); @@ -473,12 +469,11 @@ static void Surface_closeTransaction( } static void Surface_setOrientation( - JNIEnv* env, jobject clazz, jint display, jint orientation) + JNIEnv* env, jobject clazz, jint, jint orientation) { - int err = SurfaceComposerClient::setOrientation(display, orientation, 0); - if (err < 0) { - doThrowIAE(env); - } + sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay( + ISurfaceComposer::eDisplayIdMain); + SurfaceComposerClient::setDisplayOrientation(display, orientation); } class ScreenshotPixelRef : public SkPixelRef { @@ -492,12 +487,13 @@ public: SkSafeUnref(fCTable); } - status_t update(int width, int height, int minLayer, int maxLayer, bool allLayers) { + status_t update(const sp<IBinder>& display, int width, int height, + int minLayer, int maxLayer, bool allLayers) { status_t res = (width > 0 && height > 0) ? (allLayers - ? mScreenshot.update(width, height) - : mScreenshot.update(width, height, minLayer, maxLayer)) - : mScreenshot.update(); + ? mScreenshot.update(display, width, height) + : mScreenshot.update(display, width, height, minLayer, maxLayer)) + : mScreenshot.update(display); if (res != NO_ERROR) { return res; } @@ -538,11 +534,15 @@ private: typedef SkPixelRef INHERITED; }; -static jobject doScreenshot(JNIEnv* env, jobject clazz, jint width, jint height, +static jobject doScreenshot(JNIEnv* env, jobject clazz, + jint width, jint height, jint minLayer, jint maxLayer, bool allLayers) { + sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay( + ISurfaceComposer::eDisplayIdMain); ScreenshotPixelRef* pixels = new ScreenshotPixelRef(NULL); - if (pixels->update(width, height, minLayer, maxLayer, allLayers) != NO_ERROR) { + if (pixels->update(display, width, height, + minLayer, maxLayer, allLayers) != NO_ERROR) { delete pixels; return 0; } @@ -721,8 +721,10 @@ static void Surface_setLayerStack(JNIEnv* env, jobject thiz, jint layerStack) { const sp<SurfaceControl>& surface(getSurfaceControl(env, thiz)); if (surface == 0) return; - - // TODO(mathias): Everything. + status_t err = surface->setLayerStack(layerStack); + if (err<0 && err!=NO_INIT) { + doThrowIAE(env); + } } // ---------------------------------------------------------------------------- @@ -826,14 +828,14 @@ static void Surface_writeToParcel( static void nativeClassInit(JNIEnv* env, jclass clazz); static JNINativeMethod gSurfaceSessionMethods[] = { - {"init", "()V", (void*)SurfaceSession_init }, - {"destroy", "()V", (void*)SurfaceSession_destroy }, - {"kill", "()V", (void*)SurfaceSession_kill }, + {"nativeInit", "()V", (void*)SurfaceSession_nativeInit }, + {"nativeDestroy", "()V", (void*)SurfaceSession_nativeDestroy }, + {"nativeKill", "()V", (void*)SurfaceSession_nativeKill }, }; static JNINativeMethod gSurfaceMethods[] = { {"nativeClassInit", "()V", (void*)nativeClassInit }, - {"init", "(Landroid/view/SurfaceSession;ILjava/lang/String;IIIII)V", (void*)Surface_init }, + {"init", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)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 }, |
