2

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.

Oak Bytes
  • 4,649
  • 4
  • 36
  • 53
Durgesh O Mishra
  • 51
  • 1
  • 2
  • 8

5 Answers5

3

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");
leesei
  • 6,020
  • 2
  • 29
  • 51
2

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

Mukesh
  • 242
  • 1
  • 7
2

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

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

VikasKM
  • 212
  • 3
  • 7
1

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.

Zoli_K
  • 916
  • 7
  • 7
1

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.

csanta
  • 512
  • 4
  • 5
  • Is it possible to build and run this program independently from Android console to get a feel? – Midson Dec 31 '10 at 04:24
  • Yes, it's possible although probably not what you want to do anyways. Remember, these are low level native APIs and as such might not be portable across releases. One way I can think of is using the Android's NDK to have all the dependencies met (includes, libraries, etc). The NDK does come with sample code one can simply replace. The correct/expected way would be to build Android from source and then modify/build from within the source tree. – csanta Jan 02 '11 at 20:12