2323
2424#include < binder/IMemory.h>
2525
26+ #include < gui/ISurfaceComposer.h>
2627#include < gui/Surface.h>
2728#include < gui/SurfaceComposerClient.h>
2829#include < gui/SurfaceTexture.h>
@@ -107,14 +108,14 @@ static no_t no;
107108// ----------------------------------------------------------------------------
108109// ----------------------------------------------------------------------------
109110
110- static void SurfaceSession_init (JNIEnv* env, jobject clazz)
111+ static void SurfaceSession_nativeInit (JNIEnv* env, jobject clazz)
111112{
112113 sp<SurfaceComposerClient> client = new SurfaceComposerClient;
113114 client->incStrong (clazz);
114115 env->SetIntField (clazz, sso.client , (int )client.get ());
115116}
116117
117- static void SurfaceSession_destroy (JNIEnv* env, jobject clazz)
118+ static void SurfaceSession_nativeDestroy (JNIEnv* env, jobject clazz)
118119{
119120 SurfaceComposerClient* client =
120121 (SurfaceComposerClient*)env->GetIntField (clazz, sso.client );
@@ -124,7 +125,7 @@ static void SurfaceSession_destroy(JNIEnv* env, jobject clazz)
124125 }
125126}
126127
127- static void SurfaceSession_kill (JNIEnv* env, jobject clazz)
128+ static void SurfaceSession_nativeKill (JNIEnv* env, jobject clazz)
128129{
129130 SurfaceComposerClient* client =
130131 (SurfaceComposerClient*)env->GetIntField (clazz, sso.client );
@@ -221,7 +222,7 @@ void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)
221222static void Surface_init (
222223 JNIEnv* env, jobject clazz,
223224 jobject session,
224- jint, jstring jname, jint layerStack , jint w, jint h, jint format, jint flags)
225+ jstring jname, jint w, jint h, jint format, jint flags)
225226{
226227 if (session == NULL ) {
227228 doThrowNPE (env);
@@ -231,15 +232,10 @@ static void Surface_init(
231232 SurfaceComposerClient* client =
232233 (SurfaceComposerClient*)env->GetIntField (session, sso.client );
233234
234- sp<SurfaceControl> surface;
235- if (jname == NULL ) {
236- surface = client->createSurface (layerStack, w, h, format, flags);
237- } else {
238- const jchar* str = env->GetStringCritical (jname, 0 );
239- const String8 name (str, env->GetStringLength (jname));
240- env->ReleaseStringCritical (jname, str);
241- surface = client->createSurface (name, layerStack, w, h, format, flags);
242- }
235+ const jchar* str = env->GetStringCritical (jname, 0 );
236+ const String8 name (str, env->GetStringLength (jname));
237+ env->ReleaseStringCritical (jname, str);
238+ sp<SurfaceControl> surface = client->createSurface (name, w, h, format, flags);
243239
244240 if (surface == 0 ) {
245241 jniThrowException (env, OutOfResourcesException, NULL );
@@ -473,12 +469,11 @@ static void Surface_closeTransaction(
473469}
474470
475471static void Surface_setOrientation (
476- JNIEnv* env, jobject clazz, jint display , jint orientation)
472+ JNIEnv* env, jobject clazz, jint, jint orientation)
477473{
478- int err = SurfaceComposerClient::setOrientation (display, orientation, 0 );
479- if (err < 0 ) {
480- doThrowIAE (env);
481- }
474+ sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay (
475+ ISurfaceComposer::eDisplayIdMain);
476+ SurfaceComposerClient::setDisplayOrientation (display, orientation);
482477}
483478
484479class ScreenshotPixelRef : public SkPixelRef {
@@ -492,12 +487,13 @@ class ScreenshotPixelRef : public SkPixelRef {
492487 SkSafeUnref (fCTable );
493488 }
494489
495- status_t update (int width, int height, int minLayer, int maxLayer, bool allLayers) {
490+ status_t update (const sp<IBinder>& display, int width, int height,
491+ int minLayer, int maxLayer, bool allLayers) {
496492 status_t res = (width > 0 && height > 0 )
497493 ? (allLayers
498- ? mScreenshot .update (width, height)
499- : mScreenshot .update (width, height, minLayer, maxLayer))
500- : mScreenshot .update ();
494+ ? mScreenshot .update (display, width, height)
495+ : mScreenshot .update (display, width, height, minLayer, maxLayer))
496+ : mScreenshot .update (display );
501497 if (res != NO_ERROR) {
502498 return res;
503499 }
@@ -538,11 +534,15 @@ class ScreenshotPixelRef : public SkPixelRef {
538534 typedef SkPixelRef INHERITED;
539535};
540536
541- static jobject doScreenshot (JNIEnv* env, jobject clazz, jint width, jint height,
537+ static jobject doScreenshot (JNIEnv* env, jobject clazz,
538+ jint width, jint height,
542539 jint minLayer, jint maxLayer, bool allLayers)
543540{
541+ sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay (
542+ ISurfaceComposer::eDisplayIdMain);
544543 ScreenshotPixelRef* pixels = new ScreenshotPixelRef (NULL );
545- if (pixels->update (width, height, minLayer, maxLayer, allLayers) != NO_ERROR) {
544+ if (pixels->update (display, width, height,
545+ minLayer, maxLayer, allLayers) != NO_ERROR) {
546546 delete pixels;
547547 return 0 ;
548548 }
@@ -721,8 +721,10 @@ static void Surface_setLayerStack(JNIEnv* env, jobject thiz, jint layerStack)
721721{
722722 const sp<SurfaceControl>& surface (getSurfaceControl (env, thiz));
723723 if (surface == 0 ) return ;
724-
725- // TODO(mathias): Everything.
724+ status_t err = surface->setLayerStack (layerStack);
725+ if (err<0 && err!=NO_INIT) {
726+ doThrowIAE (env);
727+ }
726728}
727729
728730// ----------------------------------------------------------------------------
@@ -826,14 +828,14 @@ static void Surface_writeToParcel(
826828static void nativeClassInit (JNIEnv* env, jclass clazz);
827829
828830static JNINativeMethod gSurfaceSessionMethods [] = {
829- {" init " , " ()V" , (void *)SurfaceSession_init },
830- {" destroy " , " ()V" , (void *)SurfaceSession_destroy },
831- {" kill " , " ()V" , (void *)SurfaceSession_kill },
831+ {" nativeInit " , " ()V" , (void *)SurfaceSession_nativeInit },
832+ {" nativeDestroy " , " ()V" , (void *)SurfaceSession_nativeDestroy },
833+ {" nativeKill " , " ()V" , (void *)SurfaceSession_nativeKill },
832834};
833835
834836static JNINativeMethod gSurfaceMethods [] = {
835837 {" nativeClassInit" , " ()V" , (void *)nativeClassInit },
836- {" init" , " (Landroid/view/SurfaceSession;ILjava /lang/String;IIIII )V" , (void *)Surface_init },
838+ {" init" , " (Landroid/view/SurfaceSession;Ljava /lang/String;IIII )V" , (void *)Surface_init },
837839 {" init" , " (Landroid/os/Parcel;)V" , (void *)Surface_initParcel },
838840 {" initFromSurfaceTexture" , " (Landroid/graphics/SurfaceTexture;)V" , (void *)Surface_initFromSurfaceTexture },
839841 {" getIdentity" , " ()I" , (void *)Surface_getIdentity },
0 commit comments