Display by SurfaceComposerClient

来源:互联网 发布:多核处理器编程的艺术 编辑:程序博客网 时间:2024/06/05 09:25
#include <binder/IServiceManager.h>#include <binder/ProcessState.h>#include <binder/IPCThreadState.h>#include <android/native_window.h>#include <gui/Surface.h>#include <gui/SurfaceComposerClient.h>#include <gui/ISurfaceComposer.h>#include <ui/DisplayStatInfo.h>int main (int argc, char *argv[]) {    long tOSDWidth = 0;    long tOSDHeight = 0;    sp<IServiceManager> sm = defaultServiceManager();    sp<ISurfaceComposer> composer = interface_cast<ISurfaceComposer>(sm->checkService(String16("SurfaceFlinger")));    //FIXME    tOSDWidth = 1920;    tOSDHeight = 1080;    if (composer != NULL){        DisplayStatInfo stats;        status_t res = composer->getDisplayStats(NULL , &stats);        if (res == NO_ERROR){            ALOGI("OSD width=%d height=%d", stats.displayWidth, stats.displayHeight);            tOSDWidth = stats.displayWidth;            tOSDHeight = stats.displayHeight;        }        else            ALOGW("getDisplayStats returned %d", res);    }    else        ALOGW("could not get surface Composer service");    sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient;    sp<SurfaceControl> surfaceControl = composerClient->createSurface( String8("video"), tOSDWidth, tOSDHeight, HAL_PIXEL_FORMAT_YV12, 0);    sp<Surface> surface = surfaceControl->getSurface();    SurfaceComposerClient::openGlobalTransaction();    surfaceControl->setLayer(INT_MAX);    SurfaceComposerClient::closeGlobalTransaction();    ANativeWindow* window = surface.get();    native_window_set_buffers_dimensions(window, tWidth, tHeight);    native_window_set_buffers_format(window, HAL_PIXEL_FORMAT_YV12);    native_window_set_scaling_mode(window, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);    ANativeWindow_Buffer outBuffer;    surface->lock(&outBuffer, NULL);    //pBuffer point to graphic data  FIXME    memcpy(outBuffer.bits, pBuffer, outBuffer.width * outBuffer.height * 3/2);    surface->unlockAndPost();}

原创粉丝点击