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.
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");