#include #include #include #include #include #include #include #include #include #include #include #include #include "directfb/directfb.h" #include "directfb/directfb_util.h" #define PRINT_LOG(...) printf( __VA_ARGS__ ) #define DFBCHECK(x...) \ { \ DFBResult err = x; \ \ if (err != DFB_OK) \ { \ fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ DirectFBErrorFatal(#x, err); \ } \ } static IDirectFB *_pDFB = NULL; static IDirectFBSurface *_pDFB_surface = NULL; static EGLDisplay eglDisplay = EGL_NO_DISPLAY; static EGLConfig eglConfig = 0; static EGLSurface eglSurface = EGL_NO_SURFACE; static EGLContext eglContext = EGL_NO_CONTEXT; void getDFBSurface() { DFBDisplayLayerConfig dlc; DFBSurfaceDescription dsc; DFBCHECK(DirectFBInit(0, NULL)); DFBCHECK(DirectFBCreate(&_pDFB)); DFBCHECK(_pDFB->SetCooperativeLevel(_pDFB, DFSCL_FULLSCREEN)); memset(&dsc, 0, sizeof(dsc)); dsc.flags = (DFBSurfaceDescriptionFlags)(DSDESC_CAPS); dsc.caps = (DFBSurfaceCapabilities)(DSCAPS_PRIMARY | DSCAPS_DOUBLE); DFBCHECK(_pDFB->CreateSurface(_pDFB, &dsc, &_pDFB_surface)); } int main(int argc, char **argv) { EGLint iMajorVersion, iMinorVersion; unsigned int uiRet = 0; EGLint configAttribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_STENCIL_SIZE, 8, EGL_SAMPLES, 0, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE }; EGLint iConfigs = 0; EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; getDFBSurface(); eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if(eglDisplay == EGL_NO_DISPLAY) { goto exit; } uiRet = eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion); if(uiRet != EGL_TRUE) { goto exit; } eglBindAPI(EGL_OPENGL_ES_API); uiRet = eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &iConfigs); if(uiRet != EGL_TRUE) { goto exit; } eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)_pDFB_surface, NULL); if(eglSurface == EGL_NO_SURFACE) { goto exit; } eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, contextAttrs); if(eglContext == EGL_NO_CONTEXT) { goto exit; } eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); exit: eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if(eglContext != EGL_NO_CONTEXT) { eglDestroyContext(eglDisplay , eglContext); eglContext = EGL_NO_CONTEXT; } if(eglSurface != EGL_NO_SURFACE) { eglDestroySurface(eglDisplay, eglSurface); eglSurface = EGL_NO_SURFACE; } eglTerminate(eglDisplay); if(_pDFB_surface != NULL) { _pDFB_surface->Release(_pDFB_surface); _pDFB_surface = NULL; } if(_pDFB != NULL) { _pDFB->Release(_pDFB); _pDFB = NULL; } return 0; }