surfaceflinger test program

和自甴很熟 提交于 2019-12-07 19:30:03

问题


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.


回答1:


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



回答2:


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

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




回答3:


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




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/3076529/surfaceflinger-test-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!