Durgesh O Mishra
Durgesh O Mishra

Reputation: 61

surfaceflinger test program

I want to write a native application in Android for testing surfaceflinger. Is there any simple program that shows how to create surface, register buffers and post buffers on Surfaceflinger.

Upvotes: 2

Views: 11031

Answers (5)

Mukesh
Mukesh

Reputation: 242

I am also looking for some similar application in Jelly bean but I am no able to get a standalone application which I can build and run and can see some output on the screen. There are some applications but they are not building in Jellybean as few of the APIs would have got modified at lower level. Please provide some pointers. I want to use this app to understand the surface flinger and the display sub system of Android.

Thanks, Vibgyor

Upvotes: 2

Zoli_K
Zoli_K

Reputation: 992

If you are looking for how to interact directly with the SurfaceFlinger, the best start is to look into the SurfaceComposerClient code in /frameworks/base/libs/gui.

Upvotes: 1

leesei
leesei

Reputation: 6070

frameworks/base/libs/surfaceflinger/tests/resize/resize.cpp is a good place to start. But my version (Eclair from vendor) of the test app is out-dated, some Surface API has been moved to SurfaceControl and you have to:
SurfaceComposerClient::createSurface() => SurfaceControl
SurfaceControl->getSurface() => Surface

Secondly use SurfaceComposerClient::openTransaction()/closeTransaction() to bound all transactions to SurfaceFlinger surface, eg:
Surface::lock()/unlockAndPost() and SurfaceControl::setLayer()/setSize()

Here're some sample codes (hope this compiles :P)

sp<SurfaceComposerClient> client;
sp<SurfaceControl> control;
sp<Surface> surface;
SurfaceID sid = 0;
Surface::SurfaceInfo sinfo;
// set up the thread-pool, needed for Binder
sp<ProcessState> proc(ProcessState::self());
ProcessState::self()->startThreadPool();
client = new SurfaceComposerClient();
control = client->createSurface(getpid(), sid, 160, 240, PIXEL_FORMAT_RGB_565);
surface = control->getSurface();

// global transaction sometimes cannot trigger a redraw
//client->openGlobalTransaction();

printf("setLayer...\n");
client->openTransaction();
control->setLayer(100000);
client->closeTransaction();
printf("setLayer done\n");

printf("memset 0xF800...\n");
client->openTransaction();
surface->lock(&sinfo);
android_memset16((uint16_t*)sinfo.bits, 0xF800, sinfo.s*pfInfo.bytesPerPixel*sinfo.h);
surface->unlockAndPost();
client->closeTransaction();
printf("memset 0xF800 done\n");
sleep(2);

printf("setSize...\n");
client->openTransaction();
control->setSize(80, 120);
client->closeTransaction();
printf("setSize done\n");
sleep(2);

printf("memset 0x07E0...\n");
client->openTransaction();
surface->lock(&sinfo);
android_memset16((uint16_t*)sinfo.bits, 0x07E0, sinfo.s*pfInfo.bytesPerPixel*sinfo.h);
surface->unlockAndPost();
printf("memset 0x07E0 done\n");
client->closeTransaction();
sleep(2);

printf("setPosition...\n");
client->openTransaction();
control->setPosition(100, 100);
client->closeTransaction();
printf("setPosition done\n");
sleep(2);

// global transaction sometimes cannot trigger a redraw
//client->closeGlobalTransaction();

printf("bye\n");

Upvotes: 3

VikasKM
VikasKM

Reputation: 224

For gingerbread the code is in /frameworks/base/services/surfaceflinger

Checkout this site for some info on Surfaceflinger http://kcchao.wikidot.com/surfaceflinger

Upvotes: 2

csanta
csanta

Reputation: 512

Look in the source code for SurfaceFlinger(of the platform you're interested in).

../frameworks/base/libs/surfaceflinger/tests/resize/resize.cpp

[platform/frameworks/base.git]/opengl/tests/gralloc/gralloc.cpp

It basically does what you describe, realize though, that these are low level native APIs and are constantly evolving in Android.

Upvotes: 1

Related Questions