Display by SurfaceComposerClient

#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();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章