[Mesa-dev] [PATCH 11/12] Haiku: Remove DRI2 code as it doesn't support Haiku yet.

Alexander von Gluck IV kallisti5 at unixzen.com
Mon Dec 22 06:36:10 PST 2014


From: Adrián Arroyo Calle <adrian.arroyocalle at gmail.com>

* EGL on Haiku now working
---
 src/SConscript                          |    5 +-
 src/egl/drivers/dri2/egl_dri2.c         |    5 -
 src/egl/drivers/dri2/egl_dri2.h         |    5 -
 src/egl/drivers/dri2/platform_haiku.cpp |  300 ----------------------
 src/egl/drivers/haiku/SConscript        |   35 +++
 src/egl/drivers/haiku/egl_haiku.cpp     |  412 +++++++++++++++++++++++++++++++
 src/egl/main/SConscript                 |   16 +-
 src/egl/main/egldriver.c                |   14 +-
 8 files changed, 470 insertions(+), 322 deletions(-)
 delete mode 100644 src/egl/drivers/dri2/platform_haiku.cpp
 create mode 100644 src/egl/drivers/haiku/SConscript
 create mode 100644 src/egl/drivers/haiku/egl_haiku.cpp

diff --git a/src/SConscript b/src/SConscript
index 9c69b42..0db4611 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -32,9 +32,12 @@ SConscript('mapi/vgapi/SConscript')
 if not env['embedded']:
     if env['platform'] not in ('cygwin', 'darwin', 'freebsd', 'haiku', 'windows'):
         SConscript('glx/SConscript')
-    if env['platform'] not in ['darwin', 'sunos']:
+    if env['platform'] not in ['darwin', 'sunos','haiku']:
         SConscript('egl/drivers/dri2/SConscript')
         SConscript('egl/main/SConscript')
+    if env['platform'] == 'haiku':
+       SConscript('egl/drivers/haiku/SConscript')
+       SConscript('egl/main/SConscript')
 
     if env['gles']:
         SConscript('mapi/shared-glapi/SConscript')
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 5bda4fd..4538905 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -401,13 +401,8 @@ dri2_open_driver(_EGLDisplay *disp)
 
 
       if (dri2_dpy->driver == NULL) {
-#ifndef HAVE_HAIKU_PLATFORM
 	 snprintf(path, sizeof path,
 		  "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name);
-#else
-	 snprintf(path, sizeof path,
-		  "lib%s.so",len,p,dri2_dpy->driver_name);
-#endif
 	 dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
 	 if (dri2_dpy->driver == NULL)
 	    _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror());
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 0486b4f..90a25cc 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -339,10 +339,5 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
 #ifdef __cplusplus
 
-extern "C"
-EGLBoolean
-dri2_initialize_haiku(_EGLDriver *drv, _EGLDisplay *disp);
-#endif
-
 
 #endif /* EGL_DRI2_INCLUDED */
diff --git a/src/egl/drivers/dri2/platform_haiku.cpp b/src/egl/drivers/dri2/platform_haiku.cpp
deleted file mode 100644
index f62e8ed..0000000
--- a/src/egl/drivers/dri2/platform_haiku.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 2014 Adrián Arroyo Calle <adrian.arroyocalle at gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#include <errno.h>
-#include <dlfcn.h>
-#include <stdio.h>
-
-extern "C" {
-
-#include "loader.h"
-#include "egl_dri2.h"
-#include "egl_dri2_fallbacks.h"
-
-}
-
-#include <InterfaceKit.h>
-static void
-swrastCreateDrawable(struct dri2_egl_display * dri2_dpy,
-                     struct dri2_egl_surface * dri2_surf,
-                     int depth)
-{
-
-}
-
-static void
-swrastDestroyDrawable(struct dri2_egl_display * dri2_dpy,
-                      struct dri2_egl_surface * dri2_surf)
-{
-
-}
-
-static void
-swrastGetDrawableInfo(__DRIdrawable * draw,
-                      int *x, int *y, int *w, int *h,
-                      void *loaderPrivate)
-{
-
-}
-
-static void
-swrastPutImage(__DRIdrawable * draw, int op,
-               int x, int y, int w, int h,
-               char *data, void *loaderPrivate)
-{
-
-}
-
-static void
-swrastGetImage(__DRIdrawable * read,
-               int x, int y, int w, int h,
-               char *data, void *loaderPrivate)
-{
-
-}
-
-static void
-haiku_log(EGLint level, const char *msg)
-{
-   switch (level) {
-   case _EGL_DEBUG:
-      fprintf(stderr,"%s", msg);
-      break;
-   case _EGL_INFO:
-      fprintf(stderr,"%s", msg);
-      break;
-   case _EGL_WARNING:
-      fprintf(stderr,"%s", msg);
-      break;
-   case _EGL_FATAL:
-      fprintf(stderr,"%s", msg);
-      break;
-   default:
-      break;
-   }
-}
-
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-dri2_haiku_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
-                        _EGLConfig *conf, void *native_surface,
-                        const EGLint *attrib_list)
-{
-
-   return NULL;
-}
-
-/**
- * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
- */
-static _EGLSurface *
-dri2_haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
-                               _EGLConfig *conf, void *native_window,
-                               const EGLint *attrib_list)
-{
-	//BWindow* win=new BWindow(BRect(100,100,500,500),NULL);
-	//win->Show();
-   return NULL;
-}
-
-static _EGLSurface *
-dri2_haiku_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp,
-                               _EGLConfig *conf, void *native_pixmap,
-                               const EGLint *attrib_list)
-{
-   return NULL;
-}
-
-static _EGLSurface *
-dri2_haiku_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
-                                _EGLConfig *conf, const EGLint *attrib_list)
-{
-   return NULL;
-}
-
-static EGLBoolean
-dri2_haiku_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
-{
-	return EGL_TRUE;
-}
-static EGLBoolean
-dri2_haiku_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy,
-                                   _EGLDisplay *dpy)
-{
-	printf("Adding configs\n");
-	/*EGLint config_attrs[] = {
-	   EGL_NATIVE_VISUAL_ID,   0,
-	   EGL_NATIVE_VISUAL_TYPE, 0,
-	   EGL_NONE
-   };
-	static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 };
-	dri2_add_config(dpy,dri2_dpy->driver_configs[0],1,
-		EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | 
-		EGL_SWAP_BEHAVIOR_PRESERVED_BIT,config_attrs,rgb_masks);*/
-	struct dri2_egl_config *conf;
-	_EGLConfig base;
-	_eglInitConfig(&base, dpy, 0x8);
-	printf("Config inited\n");
-	_eglSetConfigKey(&base, EGL_RED_SIZE ,8);
-	_eglSetConfigKey(&base, EGL_BLUE_SIZE ,8);
-	_eglSetConfigKey(&base, EGL_GREEN_SIZE ,8);
-	_eglSetConfigKey(&base, EGL_LUMINANCE_SIZE ,0);
-	_eglSetConfigKey(&base, EGL_ALPHA_SIZE ,8);
-	_eglSetConfigKey(&base, EGL_COLOR_BUFFER_TYPE ,EGL_RGB_BUFFER);
-	EGLint r = (_eglGetConfigKey(&base, EGL_RED_SIZE) 
-		+ _eglGetConfigKey(&base, EGL_GREEN_SIZE)
-		+ _eglGetConfigKey(&base, EGL_BLUE_SIZE)
-		+ _eglGetConfigKey(&base, EGL_ALPHA_SIZE));
-	_eglSetConfigKey(&base, EGL_BUFFER_SIZE, r);
-	_eglSetConfigKey(&base, EGL_CONFIG_CAVEAT, EGL_NONE);
-	_eglSetConfigKey(&base, EGL_CONFIG_ID, 0x8);
-	_eglSetConfigKey(&base, EGL_BIND_TO_TEXTURE_RGB ,EGL_FALSE);
-	_eglSetConfigKey(&base, EGL_BIND_TO_TEXTURE_RGBA ,EGL_FALSE);
-	_eglSetConfigKey(&base, EGL_STENCIL_SIZE ,0);
-	_eglSetConfigKey(&base, EGL_TRANSPARENT_TYPE ,EGL_NONE);
-	 _eglSetConfigKey(&base, EGL_NATIVE_RENDERABLE ,EGL_TRUE); // Let's say yes
-	_eglSetConfigKey(&base, EGL_NATIVE_VISUAL_ID ,0); // No visual
-	_eglSetConfigKey(&base, EGL_NATIVE_VISUAL_TYPE ,EGL_NONE); // No visual
-	//_eglSetConfigKey(&base, EGL_RENDERABLE_TYPE ,glv);
-	_eglSetConfigKey(&base, EGL_SAMPLE_BUFFERS ,0); // TODO: How to get the right value ?
-	_eglSetConfigKey(&base, EGL_SAMPLES ,_eglGetConfigKey(&base, EGL_SAMPLE_BUFFERS) == 0 ? 0 : 0);
-	_eglSetConfigKey(&base, EGL_DEPTH_SIZE ,24); // TODO: How to get the right value ?
-	_eglSetConfigKey(&base, EGL_LEVEL ,0);
-	_eglSetConfigKey(&base, EGL_MAX_PBUFFER_WIDTH ,0); // TODO: How to get the right value ?
-	_eglSetConfigKey(&base, EGL_MAX_PBUFFER_HEIGHT ,0); // TODO: How to get the right value ?
-	_eglSetConfigKey(&base, EGL_MAX_PBUFFER_PIXELS ,0); // TODO: How to get the right value ?
-	
-	base.NativeRenderable = EGL_TRUE;
-	base.SurfaceType = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT;
-	
-   base.RenderableType = dpy->ClientAPIs;
-   base.Conformant = dpy->ClientAPIs;
-
-   base.MinSwapInterval = dri2_dpy->min_swap_interval;
-   base.MaxSwapInterval = dri2_dpy->max_swap_interval;
-   printf("Config configurated\n");
-	if (!_eglValidateConfig(&base, EGL_FALSE)) {
-      _eglLog(_EGL_DEBUG, "DRI2: failed to validate config");
-      return NULL;
-   }
-   printf("Validated config\n");
-   conf =(struct dri2_egl_config*) malloc(sizeof *conf);
-   memcpy(&conf->base, &base, sizeof base);
-   conf->base.ConfigID = base.ConfigID;
-   base.ConfigID    = EGL_DONT_CARE;
-   base.SurfaceType = EGL_DONT_CARE;
-   
-   _eglLinkConfig(&conf->base);
-	if (!_eglGetArraySize(dpy->Configs)) {
-      _eglLog(_EGL_WARNING, "DRI2: failed to create any config");
-      return EGL_FALSE;
-   }
-   printf("Config succesfull\n");
-   
-   return EGL_TRUE;
-}
-
-extern "C"
-EGLBoolean
-dri2_initialize_haiku(_EGLDriver *drv, _EGLDisplay *dpy)
-{
-	printf("\nINITIALIZING HAIKU\n");
-   struct dri2_egl_display_vtbl dri2_haiku_display_vtbl;
-   struct dri2_egl_display *dri2_dpy;
-
-   dri2_haiku_display_vtbl.authenticate = NULL;
-   dri2_haiku_display_vtbl.create_window_surface = dri2_haiku_create_window_surface;
-   dri2_haiku_display_vtbl.create_pixmap_surface = dri2_haiku_create_pixmap_surface;
-   dri2_haiku_display_vtbl.create_pbuffer_surface = dri2_haiku_create_pbuffer_surface;
-   dri2_haiku_display_vtbl.destroy_surface = dri2_haiku_destroy_surface;
-   dri2_haiku_display_vtbl.create_image = NULL;
-   dri2_haiku_display_vtbl.swap_interval = dri2_fallback_swap_interval;
-   dri2_haiku_display_vtbl.swap_buffers = NULL;
-   dri2_haiku_display_vtbl.swap_buffers_region = dri2_fallback_swap_buffers_region;
-   dri2_haiku_display_vtbl.post_sub_buffer = dri2_fallback_post_sub_buffer;
-   dri2_haiku_display_vtbl.copy_buffers = NULL;
-   dri2_haiku_display_vtbl.query_buffer_age = dri2_fallback_query_buffer_age,
-   dri2_haiku_display_vtbl.create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image;
-   dri2_haiku_display_vtbl.get_sync_values = dri2_fallback_get_sync_values;
-
-   printf("INITIALIZING HAIKU\n");
-   _eglSetLogProc(haiku_log);
-
-   loader_set_logger(_eglLog);
-
-   dri2_dpy = (struct dri2_egl_display*) calloc(1, sizeof(struct dri2_egl_display));
-   if (!dri2_dpy)
-      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
-	
-   dpy->DriverData=(void*) dri2_dpy;
-   if (!dpy->PlatformDisplay) {
-      // OPEN DEVICE 
-      //dri2_dpy->bwindow = (void*)haiku_create_window();
-      //dri2_dpy->own_device = true;
-   } else {
-      //dri2_dpy->bwindow = (BWindow*)dpy->PlatformDisplay;
-   }
-	
-   //dri2_dpy->driver_name = strdup("swrast");
-   //if (!dri2_load_driver_swrast(dpy))
-   //   goto cleanup_conn;
-
-   dri2_dpy->swrast_loader_extension.base.name = __DRI_SWRAST_LOADER;
-   dri2_dpy->swrast_loader_extension.base.version = __DRI_SWRAST_LOADER_VERSION;
-   dri2_dpy->swrast_loader_extension.getDrawableInfo = swrastGetDrawableInfo;
-   dri2_dpy->swrast_loader_extension.putImage = swrastPutImage;
-   dri2_dpy->swrast_loader_extension.getImage = swrastGetImage;
-
-   dri2_dpy->extensions[0] = &dri2_dpy->swrast_loader_extension.base;
-   dri2_dpy->extensions[1] = NULL;
-   dri2_dpy->extensions[2] = NULL;
-
-   /*if (dri2_dpy->bwindow) {
-      if (!dri2_haiku_add_configs_for_visuals(dri2_dpy, dpy))
-         goto cleanup_configs;
-    }*/
-    dri2_haiku_add_configs_for_visuals(dri2_dpy,dpy);
-
-   dpy->VersionMajor=1;
-   dpy->VersionMinor=4;
-
-   dri2_dpy->vtbl = &dri2_haiku_display_vtbl;
-   
-
-   return EGL_TRUE;
-   
-  cleanup_configs:
-   _eglCleanupDisplay(dpy);
-   dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen);
- cleanup_driver:
-   dlclose(dri2_dpy->driver);
- cleanup_conn:
-   free(dri2_dpy->driver_name);
- cleanup_dpy:
-   free(dri2_dpy);
-   
-   return EGL_FALSE;
-}
diff --git a/src/egl/drivers/haiku/SConscript b/src/egl/drivers/haiku/SConscript
new file mode 100644
index 0000000..2c38599
--- /dev/null
+++ b/src/egl/drivers/haiku/SConscript
@@ -0,0 +1,35 @@
+Import('*')
+
+env = env.Clone()
+
+env.Append(CPPDEFINES = [
+    'DEFAULT_DRIVER_DIR=\\"\\"',
+])
+
+env.Append(CPPPATH = [
+    '#/include',
+    '#/src/egl/main',
+    '#/src/loader',
+])
+
+sources = [
+    'egl_haiku.cpp'
+]
+
+if env['platform'] == 'haiku':
+    env.Append(CPPDEFINES = [
+        'HAVE_HAIKU_PLATFORM',
+        '_EGL_NATIVE_PLATFORM=haiku',
+    ])
+
+env.Prepend(LIBS = [
+    libloader,
+])
+
+egl_haiku = env.ConvenienceLibrary(
+#egl_dri2 = env.SharedLibrary(
+    target = 'egl_haiku',
+    source = sources,
+)
+
+Export('egl_haiku')
diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp
new file mode 100644
index 0000000..eaee11e
--- /dev/null
+++ b/src/egl/drivers/haiku/egl_haiku.cpp
@@ -0,0 +1,412 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2014 Adrián Arroyo Calle <adrian.arroyocalle at gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <errno.h>
+#include <dlfcn.h>
+#include <stdio.h>
+
+extern "C" {
+
+#include "loader.h"
+#include "eglconfig.h"
+#include "eglcontext.h"
+#include "egldisplay.h"
+#include "egldriver.h"
+#include "eglcurrent.h"
+#include "egllog.h"
+#include "eglsurface.h"
+#include "eglimage.h"
+
+}
+
+#include <InterfaceKit.h>
+
+struct haiku_egl_driver
+{
+   _EGLDriver base;
+
+   void *handle;
+   _EGLProc (*get_proc_address)(const char *procname);
+   void (*glFlush)(void);
+};
+struct haiku_egl_config
+{
+   _EGLConfig         base;
+};
+struct haiku_egl_context
+{
+	_EGLContext	ctx;
+};
+/*static void
+swrastCreateDrawable(struct dri2_egl_display * dri2_dpy,
+                     struct dri2_egl_surface * dri2_surf,
+                     int depth)
+{
+
+}
+
+static void
+swrastDestroyDrawable(struct dri2_egl_display * dri2_dpy,
+                      struct dri2_egl_surface * dri2_surf)
+{
+
+}
+
+static void
+swrastGetDrawableInfo(__DRIdrawable * draw,
+                      int *x, int *y, int *w, int *h,
+                      void *loaderPrivate)
+{
+
+}
+
+static void
+swrastPutImage(__DRIdrawable * draw, int op,
+               int x, int y, int w, int h,
+               char *data, void *loaderPrivate)
+{
+
+}
+
+static void
+swrastGetImage(__DRIdrawable * read,
+               int x, int y, int w, int h,
+               char *data, void *loaderPrivate)
+{
+
+}*/
+
+static void
+haiku_log(EGLint level, const char *msg)
+{
+   switch (level) {
+   case _EGL_DEBUG:
+      fprintf(stderr,"%s", msg);
+      break;
+   case _EGL_INFO:
+      fprintf(stderr,"%s", msg);
+      break;
+   case _EGL_WARNING:
+      fprintf(stderr,"%s", msg);
+      break;
+   case _EGL_FATAL:
+      fprintf(stderr,"%s", msg);
+      break;
+   default:
+      break;
+   }
+}
+
+/**
+ * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
+ */
+static _EGLSurface *
+haiku_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
+                        _EGLConfig *conf, void *native_surface,
+                        const EGLint *attrib_list)
+{
+
+   return NULL;
+}
+
+/**
+ * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
+ */
+static _EGLSurface *
+haiku_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp,
+                               _EGLConfig *conf, void *native_window,
+                               const EGLint *attrib_list)
+{
+	//BWindow* win=new BWindow(BRect(100,100,500,500),NULL);
+	//win->Show();
+   return NULL;
+}
+
+static _EGLSurface *
+haiku_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *disp,
+                               _EGLConfig *conf, void *native_pixmap,
+                               const EGLint *attrib_list)
+{
+   return NULL;
+}
+
+static _EGLSurface *
+haiku_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *disp,
+                                _EGLConfig *conf, const EGLint *attrib_list)
+{
+   return NULL;
+}
+
+static EGLBoolean
+haiku_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
+{
+	return EGL_TRUE;
+}
+static EGLBoolean
+haiku_add_configs_for_visuals(_EGLDisplay *dpy)
+{
+	printf("Adding configs\n");
+	/*EGLint config_attrs[] = {
+	   EGL_NATIVE_VISUAL_ID,   0,
+	   EGL_NATIVE_VISUAL_TYPE, 0,
+	   EGL_NONE
+   };
+	static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 };
+	dri2_add_config(dpy,dri2_dpy->driver_configs[0],1,
+		EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | 
+		EGL_SWAP_BEHAVIOR_PRESERVED_BIT,config_attrs,rgb_masks);*/
+	struct haiku_egl_config* conf;
+	conf=(struct haiku_egl_config*)calloc(1,sizeof (*conf));
+	_eglInitConfig(&conf->base, dpy, 1);
+	_eglLog(_EGL_DEBUG,"Config inited\n");
+	_eglSetConfigKey(&conf->base, EGL_RED_SIZE ,8);
+	_eglSetConfigKey(&conf->base, EGL_BLUE_SIZE ,8);
+	_eglSetConfigKey(&conf->base, EGL_GREEN_SIZE ,8);
+	_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) 
+		+ _eglGetConfigKey(&conf->base, EGL_GREEN_SIZE)
+		+ _eglGetConfigKey(&conf->base, EGL_BLUE_SIZE)
+		+ _eglGetConfigKey(&conf->base, EGL_ALPHA_SIZE));
+	_eglSetConfigKey(&conf->base, EGL_BUFFER_SIZE, r);
+	_eglSetConfigKey(&conf->base, EGL_CONFIG_CAVEAT, EGL_NONE);
+	_eglSetConfigKey(&conf->base, EGL_CONFIG_ID, 1);
+	_eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGB ,EGL_FALSE);
+	_eglSetConfigKey(&conf->base, EGL_BIND_TO_TEXTURE_RGBA ,EGL_FALSE);
+	_eglSetConfigKey(&conf->base, EGL_STENCIL_SIZE ,0);
+	_eglSetConfigKey(&conf->base, EGL_TRANSPARENT_TYPE ,EGL_NONE);
+	 _eglSetConfigKey(&conf->base, EGL_NATIVE_RENDERABLE ,EGL_TRUE); // Let's say yes
+	_eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_ID ,0); // No visual
+	_eglSetConfigKey(&conf->base, EGL_NATIVE_VISUAL_TYPE ,EGL_NONE); // No visual
+	_eglSetConfigKey(&conf->base, EGL_RENDERABLE_TYPE ,0x8);
+	_eglSetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS ,0); // TODO: How to get the right value ?
+	_eglSetConfigKey(&conf->base, EGL_SAMPLES ,_eglGetConfigKey(&conf->base, EGL_SAMPLE_BUFFERS) == 0 ? 0 : 0);
+	_eglSetConfigKey(&conf->base, EGL_DEPTH_SIZE ,24); // TODO: How to get the right value ?
+	_eglSetConfigKey(&conf->base, EGL_LEVEL ,0);
+	_eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_WIDTH ,0); // TODO: How to get the right value ?
+	_eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_HEIGHT ,0); // TODO: How to get the right value ?
+	_eglSetConfigKey(&conf->base, EGL_MAX_PBUFFER_PIXELS ,0); // TODO: How to get the right value ?
+	_eglSetConfigKey(&conf->base, EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT);
+	
+   //base.RenderableType = dpy->ClientAPIs;
+   //base.Conformant = dpy->ClientAPIs;
+
+   //base->MinSwapInterval = dri2_dpy->min_swap_interval;
+   //base->MaxSwapInterval = dri2_dpy->max_swap_interval;
+   printf("Config configurated\n");
+	if (!_eglValidateConfig(&conf->base, EGL_FALSE)) {
+      _eglLog(_EGL_DEBUG, "HAIKU: failed to validate config");
+      return EGL_FALSE;
+   }
+   printf("Validated config\n");
+   /*conf =(struct dri2_egl_config*) malloc(sizeof *conf);
+   memcpy(&conf->base, &base, sizeof base);
+   conf->base.ConfigID = base.ConfigID;
+   base.ConfigID    = EGL_DONT_CARE;*/
+   //base->SurfaceType = EGL_DONT_CARE;
+   
+   _eglLinkConfig(&conf->base);
+	if (!_eglGetArraySize(dpy->Configs)) {
+      _eglLog(_EGL_WARNING, "HAIKU: failed to create any config");
+      return EGL_FALSE;
+   }
+   printf("Config succesfull\n");
+   
+   return EGL_TRUE;
+}
+
+extern "C"
+EGLBoolean
+init_haiku(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+	_eglLog(_EGL_DEBUG,"\nINITIALIZING HAIKU\n");
+	_EGLDisplay* egl_dpy;
+   /*struct dri2_egl_display_vtbl dri2_haiku_display_vtbl;
+   struct dri2_egl_display *dri2_dpy;
+
+   dri2_haiku_display_vtbl.authenticate = NULL;
+   dri2_haiku_display_vtbl.create_window_surface = dri2_haiku_create_window_surface;
+   dri2_haiku_display_vtbl.create_pixmap_surface = dri2_haiku_create_pixmap_surface;
+   dri2_haiku_display_vtbl.create_pbuffer_surface = dri2_haiku_create_pbuffer_surface;
+   dri2_haiku_display_vtbl.destroy_surface = dri2_haiku_destroy_surface;
+   dri2_haiku_display_vtbl.create_image = NULL;
+   dri2_haiku_display_vtbl.swap_interval = dri2_fallback_swap_interval;
+   dri2_haiku_display_vtbl.swap_buffers = NULL;
+   dri2_haiku_display_vtbl.swap_buffers_region = dri2_fallback_swap_buffers_region;
+   dri2_haiku_display_vtbl.post_sub_buffer = dri2_fallback_post_sub_buffer;
+   dri2_haiku_display_vtbl.copy_buffers = NULL;
+   dri2_haiku_display_vtbl.query_buffer_age = dri2_fallback_query_buffer_age,
+   dri2_haiku_display_vtbl.create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image;
+   dri2_haiku_display_vtbl.get_sync_values = dri2_fallback_get_sync_values;
+	*/
+   printf("INITIALIZING HAIKU\n");
+   _eglSetLogProc(haiku_log);
+
+   loader_set_logger(_eglLog);
+
+   /*egl_dpy = (_EGLDisplay*) calloc(1, sizeof(_EGLDisplay));
+   if (!egl_dpy)
+      return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+	
+   dpy->DriverData=(void*) egl_dpy;
+   if (!dpy->PlatformDisplay) {
+      // OPEN DEVICE 
+      //dri2_dpy->bwindow = (void*)haiku_create_window();
+      //dri2_dpy->own_device = true;
+   } else {
+      //dri2_dpy->bwindow = (BWindow*)dpy->PlatformDisplay;
+   }*/
+	
+   //dri2_dpy->driver_name = strdup("swrast");
+   //if (!dri2_load_driver_swrast(dpy))
+   //   goto cleanup_conn;
+
+   /*dri2_dpy->swrast_loader_extension.base.name = __DRI_SWRAST_LOADER;
+   dri2_dpy->swrast_loader_extension.base.version = __DRI_SWRAST_LOADER_VERSION;
+   dri2_dpy->swrast_loader_extension.getDrawableInfo = swrastGetDrawableInfo;
+   dri2_dpy->swrast_loader_extension.putImage = swrastPutImage;
+   dri2_dpy->swrast_loader_extension.getImage = swrastGetImage;
+
+   dri2_dpy->extensions[0] = &dri2_dpy->swrast_loader_extension.base;
+   dri2_dpy->extensions[1] = NULL;
+   dri2_dpy->extensions[2] = NULL;*/
+
+   /*if (dri2_dpy->bwindow) {
+      if (!dri2_haiku_add_configs_for_visuals(dri2_dpy, dpy))
+         goto cleanup_configs;
+    }*/
+    _eglLog(_EGL_DEBUG,"Add configs");
+    haiku_add_configs_for_visuals(dpy);
+
+   dpy->VersionMajor=1;
+   dpy->VersionMinor=4;
+   
+   //dpy->Extensions.KHR_create_context = true;
+
+   //dri2_dpy->vtbl = &dri2_haiku_display_vtbl;
+   _eglLog(_EGL_DEBUG, "Initialization finished");
+
+   return EGL_TRUE;
+   
+  cleanup_configs:
+   _eglCleanupDisplay(dpy);
+   //dri2_dpy->core->destroyScreen(dri2_dpy->dri_screen);
+ cleanup_driver:
+   //dlclose(dri2_dpy->driver);
+ cleanup_conn:
+   //free(dri2_dpy->driver_name);
+ cleanup_dpy:
+   //free(dri2_dpy);
+   
+   return EGL_FALSE;
+}
+
+extern "C"
+EGLBoolean
+haiku_terminate(_EGLDriver* drv,_EGLDisplay* dpy)
+{
+	return EGL_TRUE;
+}
+
+extern "C"
+_EGLContext*
+haiku_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
+		    _EGLContext *share_list, const EGLint *attrib_list)
+{
+	_eglLog(_EGL_DEBUG,"Creating context");
+	struct haiku_egl_context* context;
+	context=(struct haiku_egl_context*)calloc(1,sizeof (*context));
+	if(!_eglInitContext(&context->ctx, disp, conf, attrib_list))
+		printf("ERROR creating context");
+	_eglLog(_EGL_DEBUG, "Context created");
+	return &context->ctx;
+}
+extern "C"
+EGLBoolean
+haiku_destroy_context(_EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx)
+{
+	ctx=NULL;
+	return EGL_TRUE;
+}
+
+extern "C"
+EGLBoolean
+haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf,
+		  _EGLSurface *rsurf, _EGLContext *ctx)
+{
+	return EGL_TRUE;
+}
+
+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.
+ */
+extern "C"
+_EGLDriver*
+_eglBuiltInDriverHaiku(const char *args)
+{
+	_eglLog(_EGL_DEBUG,"Driver loaded");
+	struct haiku_egl_driver* driver;
+	driver=(struct haiku_egl_driver*)calloc(1,sizeof(*driver));
+   _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.GetProcAddress = dri2_get_proc_address;
+   driver->API.WaitClient = dri2_wait_client;
+   driver->API.WaitNative = dri2_wait_native;
+   driver->API.BindTexImage = dri2_bind_tex_image;
+   driver->API.ReleaseTexImage = dri2_release_tex_image;
+   driver->API.SwapInterval = dri2_swap_interval;
+   driver->API.SwapBuffers = dri2_swap_buffers;
+   driver->API.SwapBuffersWithDamageEXT = dri2_swap_buffers_with_damage;
+   driver->API.SwapBuffersRegionNOK = dri2_swap_buffers_region;
+   driver->API.PostSubBufferNV = dri2_post_sub_buffer;
+   driver->API.CopyBuffers = dri2_copy_buffers,
+   driver->API.QueryBufferAge = dri2_query_buffer_age;
+   driver->API.CreateImageKHR = dri2_create_image;
+   driver->API.DestroyImageKHR = dri2_destroy_image_khr;
+   driver->API.CreateWaylandBufferFromImageWL = dri2_create_wayland_buffer_from_image;
+   driver->API.GetSyncValuesCHROMIUM = dri2_get_sync_values_chromium;*/
+
+   driver->base.Name = "HAIKU";
+   driver->base.Unload = haiku_unload;
+
+	_eglLog(_EGL_DEBUG, "API Calls defined");
+	
+   return &driver->base;
+}
diff --git a/src/egl/main/SConscript b/src/egl/main/SConscript
index 9bf463b..74a1545 100644
--- a/src/egl/main/SConscript
+++ b/src/egl/main/SConscript
@@ -7,7 +7,7 @@ Import('*')
 env = env.Clone()
 
 env.Append(CPPDEFINES = [
-    '_EGL_BUILT_IN_DRIVER_DRI2',
+    '_EGL_BUILT_IN_DRIVER_HAIKU',
     '_EGL_DRIVER_SEARCH_DIR=\\"\\"',
 ])
 
@@ -23,21 +23,27 @@ else:
         env.Append(CPPDEFINES = [
         	'_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_HAIKU',
         	'_EGL_OS_UNIX',
+        	'_EGL_BUILT_IN_DRIVER_HAIKU',
     	])
+    	env.Prepend(LIBS = [
+            egl_haiku,
+            libloader,
+        ])
     else:
         env.Append(CPPDEFINES = [
         	'_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_X11',
         	'_EGL_OS_UNIX',
     	])
+    	env.Prepend(LIBS = [
+            egl_dri2,
+            libloader,
+        ])
 
 env.Append(CPPPATH = [
     '#/include',
 ])
 
-env.Prepend(LIBS = [
-    egl_dri2,
-    libloader,
-])
+
 
 # parse Makefile.sources
 egl_sources = env.ParseSourceList('Makefile.sources', 'LIBEGL_C_FILES')
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 8cf777d..18712c6 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -52,6 +52,9 @@
 #include <unistd.h>
 #endif
 
+#ifdef _EGL_BUILT_IN_DRIVER_HAIKU
+_EGLDriver* _eglBuiltInDriverHaiku(const char* args);
+#endif
 
 typedef struct _egl_module {
    char *Path;
@@ -73,6 +76,9 @@ const struct {
 #ifdef _EGL_BUILT_IN_DRIVER_DRI2
    { "egl_dri2", _eglBuiltInDriverDRI2 },
 #endif
+#ifdef _EGL_BUILT_IN_DRIVER_HAIKU
+   { "egl_haiku", _eglBuiltInDriverHaiku },
+#endif
    { NULL, NULL }
 };
 
@@ -196,7 +202,6 @@ _eglLoadModule(_EGLModule *mod)
    _EGLMain_t mainFunc;
    lib_handle lib;
    _EGLDriver *drv;
-
    if (mod->Driver)
       return EGL_TRUE;
 
@@ -292,7 +297,8 @@ _eglAddModule(const char *path)
       _eglAppendArray(_eglModules, (void *) mod);
       _eglLog(_EGL_DEBUG, "added %s to module array", mod->Path);
    }
-
+	
+	
    return mod;
 }
 
@@ -570,7 +576,6 @@ _eglMatchAndInitialize(_EGLDisplay *dpy)
       _eglLog(_EGL_WARNING, "failed to find any driver");
       return NULL;
    }
-
    if (dpy->Driver) {
       drv = dpy->Driver;
       /* no re-matching? */
@@ -578,16 +583,13 @@ _eglMatchAndInitialize(_EGLDisplay *dpy)
          drv = NULL;
       return drv;
    }
-
    while (i < _eglModules->Size) {
       _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i];
-
       if (!_eglLoadModule(mod)) {
          /* remove invalid modules */
          _eglEraseArray(_eglModules, i, _eglFreeModule);
          continue;
       }
-
       if (mod->Driver->API.Initialize(mod->Driver, dpy)) {
          drv = mod->Driver;
          break;
-- 
1.7.1



More information about the mesa-dev mailing list