egl: move alloc & init out of _eglBuiltInDriver{DRI2,Haiku}
[mesa.git] / src / egl / drivers / haiku / egl_haiku.cpp
index 3d00e47c8e63f06b1faffc11325f5e9c9cbe8559..590e43f00fb96b051fb4d610e4761280425fe058 100644 (file)
 _EGL_DRIVER_STANDARD_TYPECASTS(haiku_egl)
 
 
-struct haiku_egl_driver
-{
-       _EGLDriver base;
-};
-
 struct haiku_egl_config
 {
        _EGLConfig         base;
@@ -92,8 +87,11 @@ haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
                return NULL;
        }
 
-       if (!_eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT, conf, attrib_list))
-               goto cleanup_surface;
+       if (!_eglInitSurface(&surface->surf, disp, EGL_WINDOW_BIT,
+               conf, attrib_list)) {
+               free(surface);
+               return NULL;
+       }
 
        (&surface->surf)->SwapInterval = 1;
 
@@ -110,10 +108,6 @@ haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
        TRACE("Showing window\n");
        win->Show();
        return &surface->surf;
-
-cleanup_surface:
-       free(surface);
-       return NULL;
 }
 
 
@@ -139,7 +133,7 @@ haiku_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
        if (_eglPutSurface(surf)) {
                // XXX: detach haiku_egl_surface::gl from the native window and destroy it
                free(surf);
-        }
+       }
        return EGL_TRUE;
 }
 
@@ -151,10 +145,8 @@ haiku_add_configs_for_visuals(_EGLDisplay *dpy)
 
        struct haiku_egl_config* conf;
        conf = (struct haiku_egl_config*) calloc(1, sizeof (*conf));
-       if (!conf) {
-               _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals");
-               return NULL;
-       }
+       if (!conf)
+               return _eglError(EGL_BAD_ALLOC, "haiku_add_configs_for_visuals");
 
        _eglInitConfig(&conf->base, dpy, 1);
        TRACE("Config inited\n");
@@ -165,7 +157,7 @@ haiku_add_configs_for_visuals(_EGLDisplay *dpy)
        _eglSetConfigKey(&conf->base, EGL_LUMINANCE_SIZE, 0);
        _eglSetConfigKey(&conf->base, EGL_ALPHA_SIZE, 8);
        _eglSetConfigKey(&conf->base, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER);
-       EGLint r = (_eglGetConfigKey(&conf->base, EGL_RED_SIZE) 
+       EGLint r = (_eglGetConfigKey(&conf->base, EGL_RED_SIZE)
                + _eglGetConfigKey(&conf->base, EGL_GREEN_SIZE)
                + _eglGetConfigKey(&conf->base, EGL_BLUE_SIZE)
                + _eglGetConfigKey(&conf->base, EGL_ALPHA_SIZE));
@@ -195,7 +187,7 @@ haiku_add_configs_for_visuals(_EGLDisplay *dpy)
                goto cleanup;
        }
        TRACE("Validated config\n");
-   
+
        _eglLinkConfig(&conf->base);
        if (!_eglGetArraySize(dpy->Configs)) {
                _eglLog(_EGL_WARNING, "Haiku: failed to create any config");
@@ -210,6 +202,7 @@ cleanup:
        return EGL_FALSE;
 }
 
+
 extern "C"
 EGLBoolean
 init_haiku(_EGLDriver *drv, _EGLDisplay *dpy)
@@ -221,7 +214,7 @@ init_haiku(_EGLDriver *drv, _EGLDisplay *dpy)
                return EGL_FALSE;
 
        dpy->Version = 14;
-   
+
        TRACE("Initialization finished\n");
 
        return EGL_TRUE;
@@ -271,7 +264,7 @@ haiku_destroy_context(_EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx)
        if (_eglPutContext(ctx)) {
                // XXX: teardown the context ?
                free(context);
-               ctx = NULL
+               ctx = NULL;
        }
        return EGL_TRUE;
 }
@@ -280,7 +273,7 @@ haiku_destroy_context(_EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx)
 extern "C"
 EGLBoolean
 haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf,
-                 _EGLSurface *rsurf, _EGLContext *ctx)
+       _EGLSurface *rsurf, _EGLContext *ctx)
 {
        CALLED();
 
@@ -310,48 +303,29 @@ haiku_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 }
 
 
-extern "C"
-void
-haiku_unload(_EGLDriver* drv)
-{
-       
-}
-
-
 /**
  * This is the main entrypoint into the driver, called by libEGL.
- * Create a new _EGLDriver object and init its dispatch table.
+ * Gets an _EGLDriver object and init its dispatch table.
  */
 extern "C"
-_EGLDriver*
-_eglBuiltInDriverHaiku(const char *args)
+void
+_eglInitDriver(_EGLDriver *driver)
 {
        CALLED();
 
-       struct haiku_egl_driver* driver;
-       driver = (struct haiku_egl_driver*) calloc(1, sizeof(*driver));
-       if (!driver) {
-               _eglError(EGL_BAD_ALLOC, "_eglBuiltInDriverHaiku");
-               return NULL;
-       }
-
-       _eglInitDriverFallbacks(&driver->base);
-       driver->base.API.Initialize = init_haiku;
-       driver->base.API.Terminate = haiku_terminate;
-       driver->base.API.CreateContext = haiku_create_context;
-       driver->base.API.DestroyContext = haiku_destroy_context;
-       driver->base.API.MakeCurrent = haiku_make_current;
-       driver->base.API.CreateWindowSurface = haiku_create_window_surface;
-       driver->base.API.CreatePixmapSurface = haiku_create_pixmap_surface;
-       driver->base.API.CreatePbufferSurface = haiku_create_pbuffer_surface;
-       driver->base.API.DestroySurface = haiku_destroy_surface;
+       driver->API.Initialize = init_haiku;
+       driver->API.Terminate = haiku_terminate;
+       driver->API.CreateContext = haiku_create_context;
+       driver->API.DestroyContext = haiku_destroy_context;
+       driver->API.MakeCurrent = haiku_make_current;
+       driver->API.CreateWindowSurface = haiku_create_window_surface;
+       driver->API.CreatePixmapSurface = haiku_create_pixmap_surface;
+       driver->API.CreatePbufferSurface = haiku_create_pbuffer_surface;
+       driver->API.DestroySurface = haiku_destroy_surface;
 
-       driver->base.API.SwapBuffers = haiku_swap_buffers;
+       driver->API.SwapBuffers = haiku_swap_buffers;
 
-       driver->base.Name = "Haiku";
-       driver->base.Unload = haiku_unload;
+       driver->Name = "Haiku";
 
        TRACE("API Calls defined\n");
-
-       return &driver->base;
 }