Search
lxdream.org :: lxdream/src/drivers/video_egl.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_egl.c
changeset 1287:dac8f363f1fe
prev1275:83b15705cdde
author nkeynes
date Sun Jul 01 13:20:34 2012 +1000 (8 years ago)
permissions -rw-r--r--
last change Add support for Nokia N900
- Generic support for EGL with GTK
- Workaround for nokia bug with egl config
Based on patch from guinux, thanks!
file annotate diff log raw
1.1 --- a/src/drivers/video_egl.c Tue Mar 20 08:29:38 2012 +1000
1.2 +++ b/src/drivers/video_egl.c Sun Jul 01 13:20:34 2012 +1000
1.3 @@ -72,6 +72,13 @@
1.4 EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
1.5 EGL_NONE, EGL_NONE };
1.6
1.7 +static const EGLint alt_attributes[] = {
1.8 + EGL_DEPTH_SIZE, 16,
1.9 + EGL_STENCIL_SIZE, 8,
1.10 + EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
1.11 + EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
1.12 + EGL_NONE, EGL_NONE };
1.13 +
1.14 static const EGLint context_attributes[] = {
1.15 EGL_CONTEXT_CLIENT_VERSION, 2,
1.16 EGL_NONE, EGL_NONE };
1.17 @@ -81,60 +88,79 @@
1.18 static EGLSurface surface = EGL_NO_SURFACE;
1.19 static gboolean fbo_created = FALSE;
1.20
1.21 -gboolean video_egl_set_window(EGLNativeWindowType window, int width, int height, int format)
1.22 +static void video_egl_swap_buffers();
1.23 +static int video_egl_major = 0, video_egl_minor = 0;
1.24 +
1.25 +gboolean video_egl_init()
1.26 {
1.27 - EGLConfig config;
1.28 - EGLint num_config, major = 0, minor = 0;
1.29 - const EGLint *attribute_list;
1.30 -
1.31 display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
1.32 - if( eglInitialize(display, &major, &minor) != EGL_TRUE ) {
1.33 + if( eglInitialize(display, &video_egl_major, &video_egl_minor) != EGL_TRUE ) {
1.34 logEGLError( "Unable to initialise EGL display" );
1.35 return FALSE;
1.36 }
1.37 + return TRUE;
1.38 +}
1.39 +
1.40 +gboolean video_egl_init_context( EGLNativeWindowType window, int format )
1.41 +{
1.42 + EGLConfig config;
1.43 + EGLint num_config;
1.44 + const EGLint *attribute_list;
1.45
1.46 if( format == COLFMT_RGB565 || format == COLFMT_BGRA1555 ) {
1.47 attribute_list = RGB565_attributes;
1.48 } else {
1.49 attribute_list = RGB888_attributes;
1.50 }
1.51 + eglChooseConfig(display, attribute_list, &config, 1, &num_config);
1.52
1.53 + surface = eglCreateWindowSurface(display, config, window, NULL);
1.54 + if( surface == EGL_NO_SURFACE ) {
1.55 + /* Try alternate config in case of failure. This provides a workaround for
1.56 + * the Nokia N900 where eglCreateWindowSurface fails when color attributes
1.57 + * are specified. (bug report: https://bugs.maemo.org/show_bug.cgi?id=9335)
1.58 + */
1.59 + eglChooseConfig(display, alt_attributes, &config, 1, &num_config);
1.60 + surface = eglCreateWindowSurface(display, config, window, NULL);
1.61
1.62 - eglChooseConfig(display, attribute_list, &config, 1, &num_config);
1.63 + if( surface == EGL_NO_SURFACE ) {
1.64 + logEGLError( "Unable to create EGL surface" );
1.65 + video_egl_shutdown();
1.66 + return FALSE;
1.67 + }
1.68 + }
1.69
1.70 context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attributes);
1.71 if( context == EGL_NO_CONTEXT ) {
1.72 logEGLError( "Unable to create EGL context" );
1.73 - video_egl_clear_window();
1.74 + video_egl_shutdown();
1.75 return FALSE;
1.76 }
1.77
1.78 - surface = eglCreateWindowSurface(display, config, window, NULL);
1.79 - if( surface == EGL_NO_SURFACE ) {
1.80 - logEGLError( "Unable to create EGL surface" );
1.81 - video_egl_clear_window();
1.82 +
1.83 +
1.84 + if( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE ) {
1.85 + logEGLError( "Unable to make EGL context current" );
1.86 + video_egl_shutdown();
1.87 return FALSE;
1.88 }
1.89
1.90 - if( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE ) {
1.91 - logEGLError( "Unable to make EGL context current" );
1.92 - video_egl_clear_window();
1.93 - return FALSE;
1.94 - }
1.95 + return TRUE;
1.96 +}
1.97
1.98 - display_egl_driver.capabilities.depth_bits = 16; /* TODO: get from config info */
1.99 - if( !gl_init_driver(&display_egl_driver, TRUE) ) {
1.100 - video_egl_clear_window();
1.101 +gboolean video_egl_init_driver( display_driver_t driver )
1.102 +{
1.103 + driver->swap_buffers = video_egl_swap_buffers;
1.104 + driver->capabilities.depth_bits = 16; /* TODO: get from config info */
1.105 + if( !gl_init_driver(driver, TRUE) ) {
1.106 + video_egl_shutdown();
1.107 return FALSE;
1.108 }
1.109 fbo_created = TRUE;
1.110 - gl_set_video_size(width, height, 0);
1.111 - pvr2_setup_gl_context();
1.112 - INFO( "Initialised EGL %d.%d", major, minor );
1.113 return TRUE;
1.114 }
1.115
1.116 -void video_egl_clear_window()
1.117 +void video_egl_shutdown()
1.118 {
1.119 if( fbo_created ) {
1.120 pvr2_shutdown_gl_context();
1.121 @@ -154,6 +180,24 @@
1.122 eglTerminate(display);
1.123 display = EGL_NO_DISPLAY;
1.124 }
1.125 +}
1.126 +
1.127 +gboolean video_egl_set_window(EGLNativeWindowType window, int width, int height, int format)
1.128 +{
1.129 + if( ! video_egl_init() ||
1.130 + ! video_egl_init_context( window, format ) ||
1.131 + ! video_egl_init_driver( &display_egl_driver ) ) {
1.132 + return FALSE;
1.133 + }
1.134 + gl_set_video_size(width, height, 0);
1.135 + pvr2_setup_gl_context();
1.136 + INFO( "Initialised EGL %d.%d", video_egl_major, video_egl_minor );
1.137 + return TRUE;
1.138 +}
1.139 +
1.140 +void video_egl_clear_window()
1.141 +{
1.142 + video_egl_shutdown();
1.143 INFO( "Terminated EGL" );
1.144 }
1.145
.