Skip to content

Commit 0b722fe

Browse files
author
Jeff Brown
committed
Use new surface flinger API.
Change-Id: Ic888577408a59a36481a48010e19c5e77c24e211
1 parent d59db50 commit 0b722fe

File tree

7 files changed

+95
-56
lines changed

7 files changed

+95
-56
lines changed

cmds/bootanimation/BootAnimation.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <ui/DisplayInfo.h>
3939
#include <ui/FramebufferNativeWindow.h>
4040

41+
#include <gui/ISurfaceComposer.h>
4142
#include <gui/Surface.h>
4243
#include <gui/SurfaceComposerClient.h>
4344

@@ -216,14 +217,16 @@ status_t BootAnimation::initTexture(void* buffer, size_t len)
216217
status_t BootAnimation::readyToRun() {
217218
mAssets.addDefaultAssets();
218219

220+
sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
221+
ISurfaceComposer::eDisplayIdMain));
219222
DisplayInfo dinfo;
220-
status_t status = SurfaceComposerClient::getDisplayInfo(0, &dinfo);
223+
status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
221224
if (status)
222225
return -1;
223226

224227
// create the native surface
225-
sp<SurfaceControl> control = session()->createSurface(
226-
0, dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
228+
sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
229+
dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
227230

228231
SurfaceComposerClient::openGlobalTransaction();
229232
control->setLayer(0x40000000);

cmds/screencap/screencap.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <binder/IMemory.h>
2727
#include <gui/SurfaceComposerClient.h>
28+
#include <gui/ISurfaceComposer.h>
2829

2930
#include <SkImageEncoder.h>
3031
#include <SkBitmap.h>
@@ -33,15 +34,18 @@
3334

3435
using namespace android;
3536

37+
static uint32_t DEFAULT_DISPLAY_ID = ISurfaceComposer::eDisplayIdMain;
38+
3639
static void usage(const char* pname)
3740
{
3841
fprintf(stderr,
39-
"usage: %s [-hp] [FILENAME]\n"
42+
"usage: %s [-hp] [-d display-id] [FILENAME]\n"
4043
" -h: this message\n"
4144
" -p: save the file as a png.\n"
45+
" -d: specify the display id to capture, default %d.\n"
4246
"If FILENAME ends with .png it will be saved as a png.\n"
4347
"If FILENAME is not given, the results will be printed to stdout.\n",
44-
pname
48+
pname, DEFAULT_DISPLAY_ID
4549
);
4650
}
4751

@@ -87,12 +91,16 @@ int main(int argc, char** argv)
8791
{
8892
const char* pname = argv[0];
8993
bool png = false;
94+
int32_t displayId = DEFAULT_DISPLAY_ID;
9095
int c;
91-
while ((c = getopt(argc, argv, "ph")) != -1) {
96+
while ((c = getopt(argc, argv, "phd:")) != -1) {
9297
switch (c) {
9398
case 'p':
9499
png = true;
95100
break;
101+
case 'd':
102+
displayId = atoi(optarg);
103+
break;
96104
case '?':
97105
case 'h':
98106
usage(pname);
@@ -131,7 +139,8 @@ int main(int argc, char** argv)
131139
size_t size = 0;
132140

133141
ScreenshotClient screenshot;
134-
if (screenshot.update() == NO_ERROR) {
142+
sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(displayId);
143+
if (display != NULL && screenshot.update(display) == NO_ERROR) {
135144
base = screenshot.getPixels();
136145
w = screenshot.getWidth();
137146
h = screenshot.getHeight();

core/java/android/view/Surface.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
package android.view;
1818

1919
import android.content.res.CompatibilityInfo.Translator;
20-
import android.graphics.*;
20+
import android.graphics.Bitmap;
21+
import android.graphics.Canvas;
22+
import android.graphics.Matrix;
23+
import android.graphics.Rect;
24+
import android.graphics.Region;
25+
import android.graphics.SurfaceTexture;
2126
import android.os.Parcelable;
2227
import android.os.Parcel;
28+
import android.os.Process;
2329
import android.os.SystemProperties;
2430
import android.util.Log;
2531

@@ -250,13 +256,20 @@ public OutOfResourcesException(String name) {
250256
public Surface(SurfaceSession s,
251257
int pid, String name, int layerStack, int w, int h, int format, int flags)
252258
throws OutOfResourcesException {
259+
// FIXME: remove pid and layerstack arguments
253260
checkHeadless();
254261

255262
if (DEBUG_RELEASE) {
256263
mCreationStack = new Exception();
257264
}
265+
266+
if (name == null) {
267+
name = "<pid " + Process.myPid() + ">";
268+
}
269+
258270
mCanvas = new CompatibleCanvas();
259-
init(s, pid, name, layerStack, w, h, format, flags);
271+
init(s, name, w, h, format, flags);
272+
setLayerStack(layerStack);
260273
mName = name;
261274
}
262275

@@ -496,8 +509,8 @@ protected void finalize() throws Throwable {
496509
}
497510
}
498511

499-
private native void init(SurfaceSession s,
500-
int pid, String name, int layerStack, int w, int h, int format, int flags)
512+
private native void init(SurfaceSession s, String name,
513+
int w, int h, int format, int flags)
501514
throws OutOfResourcesException;
502515

503516
private native void init(Parcel source) throws OutOfResourcesException;

core/java/android/view/SurfaceSession.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,34 @@
2424
* {@hide}
2525
*/
2626
public class SurfaceSession {
27+
private int mClient;
28+
29+
private native void nativeInit();
30+
private native void nativeDestroy();
31+
private native void nativeKill();
32+
2733
/** Create a new connection with the surface flinger. */
2834
public SurfaceSession() {
29-
init();
35+
nativeInit();
3036
}
3137

32-
/** Forcibly detach native resources associated with this object.
33-
* Unlike destroy(), after this call any surfaces that were created
34-
* from the session will no longer work. The session itself is destroyed.
35-
*/
36-
public native void kill();
37-
3838
/* no user serviceable parts here ... */
3939
@Override
4040
protected void finalize() throws Throwable {
41-
destroy();
41+
try {
42+
nativeDestroy();
43+
} finally {
44+
super.finalize();
45+
}
46+
}
47+
48+
/**
49+
* Forcibly detach native resources associated with this object.
50+
* Unlike destroy(), after this call any surfaces that were created
51+
* from the session will no longer work. The session itself is destroyed.
52+
*/
53+
public void kill() {
54+
nativeKill();
4255
}
43-
44-
private native void init();
45-
private native void destroy();
46-
47-
private int mClient;
4856
}
4957

core/jni/android_view_Surface.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
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)
221222
static 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

475471
static 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

484479
class 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(
826828
static void nativeClassInit(JNIEnv* env, jclass clazz);
827829

828830
static 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

834836
static 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 },

services/input/SpriteController.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ sp<SurfaceControl> SpriteController::obtainSurface(int32_t width, int32_t height
369369
ensureSurfaceComposerClient();
370370

371371
sp<SurfaceControl> surfaceControl = mSurfaceComposerClient->createSurface(
372-
String8("Sprite"), 0, width, height, PIXEL_FORMAT_RGBA_8888);
372+
String8("Sprite"), width, height, PIXEL_FORMAT_RGBA_8888);
373373
if (surfaceControl == NULL || !surfaceControl->isValid()
374374
|| !surfaceControl->getSurface()->isValid()) {
375375
ALOGE("Error creating sprite surface.");

services/jni/com_android_server_display_SurfaceFlingerDisplayAdapter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "jni.h"
2121
#include <android_runtime/AndroidRuntime.h>
2222

23+
#include <gui/ISurfaceComposer.h>
2324
#include <gui/SurfaceComposerClient.h>
2425
#include <ui/DisplayInfo.h>
2526

@@ -38,8 +39,11 @@ static struct {
3839

3940

4041
static void nativeGetDefaultDisplayDeviceInfo(JNIEnv* env, jclass clazz, jobject infoObj) {
42+
sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(
43+
ISurfaceComposer::eDisplayIdMain));
44+
4145
DisplayInfo info;
42-
status_t err = SurfaceComposerClient::getDisplayInfo(0, &info);
46+
status_t err = SurfaceComposerClient::getDisplayInfo(display, &info);
4347
if (err < 0) {
4448
jniThrowExceptionFmt(env, "java/lang/RuntimeException",
4549
"Could not get display info. err=%d", err);

0 commit comments

Comments
 (0)