[Mesa-dev] [PATCH 02/12] egl: More functions for Haiku

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


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

---
 src/egl/drivers/dri2/egl_dri2.h         |   13 ++++
 src/egl/drivers/dri2/platform_haiku.cpp |  117 +++++++++++++++++++++++++++++--
 2 files changed, 123 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 52f05fb..6f5fd17 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -197,6 +197,11 @@ struct dri2_egl_display
    int			     formats;
    uint32_t                  capabilities;
 #endif
+
+#ifdef HAVE_EGL_PLATFORM_HAIKU
+	void					*bwindow;
+	void					*glview;
+#endif
 };
 
 struct dri2_egl_context
@@ -332,4 +337,12 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 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
index d182663..f31e458 100644
--- a/src/egl/drivers/dri2/platform_haiku.cpp
+++ b/src/egl/drivers/dri2/platform_haiku.cpp
@@ -24,19 +24,122 @@
  
 #include <errno.h>
 #include <dlfcn.h>
+#include <stdio.h>
 
-/*#include "loader.h"
 #include "egl_dri2.h"
 #include "egl_dri2_fallbacks.h"
-#include "gralloc_drm.h"
+#include "../../../loader/loader.h"
+//#include "gralloc_drm.h"
+
+#include <InterfaceKit.h>
+
+static void
+haiku_log(EGLint level, const char *msg)
+{
+   switch (level) {
+   case _EGL_DEBUG:
+      printf("%s", msg);
+      break;
+   case _EGL_INFO:
+      printf("%s", msg);
+      break;
+   case _EGL_WARNING:
+      printf("%s", msg);
+      break;
+   case _EGL_FATAL:
+      fprintf(stderr,"%s", msg);
+      break;
+   default:
+      break;
+   }
+}
+
+BWindow* 
+haiku_create_window()
+{
+	BWindow* win=new BWindow(BRect(100,100,500,500),"EGL Test",B_TITLED_WINDOW,0);
+	return win;
+}
 
 static EGLBoolean
-haiku_window_dequeue_buffer(struct dri2_egl_surface* dri2_surf)
+dri2_haiku_add_configs_for_visuals(struct dri2_egl_display *dri2_dpy, _EGLDisplay *disp)
 {
-	if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer))
+	if (!_eglGetArraySize(disp->Configs)) {
+      _eglLog(_EGL_WARNING, "DRI2: failed to create any config");
       return EGL_FALSE;
+   }
 
-   dri2_surf->buffer->common.incRef(&dri2_surf->buffer->common);
-   dri2_surf->window->lockBuffer(dri2_surf->window, dri2_surf->buffer);
    return EGL_TRUE;
-}*/
+}
+
+extern "C"
+EGLBoolean
+dri2_initialize_haiku(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+	printf("INITIALIZING HAIKU");
+	struct dri2_egl_display_vtbl dri2_haiku_display_vtbl;
+	dri2_haiku_display_vtbl={};
+	dri2_haiku_display_vtbl.authenticate = NULL;
+   dri2_haiku_display_vtbl.create_window_surface = NULL;
+   dri2_haiku_display_vtbl.create_pixmap_surface = NULL;
+   dri2_haiku_display_vtbl.create_pbuffer_surface = NULL;
+   dri2_haiku_display_vtbl.destroy_surface = NULL;
+   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;
+	
+	struct dri2_egl_display *dri2_dpy;
+	const char *err;
+	
+	_eglSetLogProc(haiku_log);
+	
+	//loader_set_logger(_eglLog);
+	
+	dri2_dpy =(struct dri2_egl_display*) calloc(1, sizeof(*dri2_dpy));
+	if (!dri2_dpy)
+		return _eglError(EGL_BAD_ALLOC, "eglInitialize");
+	dpy->DriverData=(void*) dri2_dpy;
+	if(dpy->PlatformDisplay == NULL)
+	{
+		/* OPEN DEVICE */
+		dri2_dpy->bwindow=(void*)haiku_create_window();
+		dri2_dpy->own_device=true;	
+	}else{
+		BWindow* win=(BWindow*)dpy->PlatformDisplay;
+		dri2_dpy->bwindow=win;
+	}
+	
+	dri2_dpy->driver_name = strdup("Haiku OpenGL");
+	if (!dri2_load_driver_swrast(dpy))
+		return EGL_FALSE;
+	
+	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))
+      	return EGL_FALSE;
+    }
+	
+	
+	dpy->VersionMajor=1;
+	dpy->VersionMinor=4;
+	
+	dri2_dpy->vtbl = &dri2_haiku_display_vtbl;
+	
+	return EGL_TRUE;
+	
+}
-- 
1.7.1



More information about the mesa-dev mailing list