From 4295b77582a0ee57ce79e207cfab03ecfd0503ef Mon Sep 17 00:00:00 2001 From: BrandonSchaefer Date: Thu, 6 Nov 2014 00:23:02 -0800 Subject: [PATCH] Set up the Mir connection. Set up the first of the Mir surface. --- src/mir_init.c | 17 +++++++++++- src/mir_monitor.c | 6 +++- src/mir_platform.h | 12 ++++++-- src/mir_window.c | 69 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/mir_init.c b/src/mir_init.c index 7702b8fe..139757e3 100644 --- a/src/mir_init.c +++ b/src/mir_init.c @@ -6,11 +6,26 @@ int _glfwPlatformInit(void) { - return 0; + _glfw.mir.connection = mir_connect_sync(NULL, __PRETTY_FUNCTION__); + + if (!mir_connection_is_valid(_glfw.mir.connection)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unable to connect to Server\n"); + return GL_FALSE; + } + + _glfw.mir.native_display = mir_connection_get_egl_native_display(_glfw.mir.connection); + + // TODO Add in bits to get the correct monitors and screen sizes... + // Ill just hard code in my own right now to jump ahead to surface and events. + + return GL_TRUE; } void _glfwPlatformTerminate(void) { + mir_connection_release(_glfw.mir.connection); } const char* _glfwPlatformGetVersionString(void) diff --git a/src/mir_monitor.c b/src/mir_monitor.c index e744b496..13fd3d50 100644 --- a/src/mir_monitor.c +++ b/src/mir_monitor.c @@ -1,6 +1,7 @@ #include "internal.h" #include +#include ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// @@ -8,7 +9,10 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) { - return NULL; + // FIXME Work out the best way to get this from mir, as we'll end up looping + // through all of that info... best to store it before we get here. + _GLFWmonitor** monitors = calloc(1, sizeof(_GLFWmonitor*)); + return monitors; } GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) diff --git a/src/mir_platform.h b/src/mir_platform.h index c00c8c65..882240d4 100644 --- a/src/mir_platform.h +++ b/src/mir_platform.h @@ -13,8 +13,8 @@ #error "The Mir backend depends on EGL platform support" #endif -#define _GLFW_EGL_NATIVE_WINDOW NULL -#define _GLFW_EGL_NATIVE_DISPLAY NULL +#define _GLFW_EGL_NATIVE_WINDOW window->mir.native_window +#define _GLFW_EGL_NATIVE_DISPLAY _glfw.mir.native_display #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowMir mir; #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorMir mir; @@ -23,6 +23,11 @@ typedef struct _GLFWwindowMir { + MirSurface* surface; + + EGLSurface egl_surface; + MirEGLNativeWindowType native_window; + } _GLFWwindowMir; typedef struct _GLFWmonitorMir @@ -33,6 +38,9 @@ typedef struct _GLFWlibraryMir { MirConnection* connection; + MirEGLNativeDisplayType native_display; + + } _GLFWlibraryMir; typedef struct _GLFWcursorMir diff --git a/src/mir_window.c b/src/mir_window.c index eb7bd4c6..7c742d61 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -1,5 +1,31 @@ #include "internal.h" +MirPixelFormat FindValidPixelFormat() +{ + unsigned int pf_size = 32; + unsigned int valid_formats; + unsigned int f; + + MirPixelFormat formats[pf_size]; + mir_connection_get_available_surface_formats(_glfw.mir.connection, formats, + pf_size, &valid_formats); + + for (f = 0; f < valid_formats; f++) + { + MirPixelFormat cur_pf = formats[f]; + + if (cur_pf == mir_pixel_format_abgr_8888 || + cur_pf == mir_pixel_format_xbgr_8888 || + cur_pf == mir_pixel_format_argb_8888 || + cur_pf == mir_pixel_format_xrgb_8888) + { + return cur_pf; + } + } + + return mir_pixel_format_invalid; +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -9,7 +35,48 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig) { - return 0; + if (!_glfwCreateContext(window, ctxconfig, fbconfig)) + return GL_FALSE; + + MirSurfaceParameters params = + { + .name = "MirSurface", + .width = 1600, + .height = 900, + .pixel_format = mir_pixel_format_invalid, + .buffer_usage = mir_buffer_usage_hardware, + .output_id = mir_display_output_id_invalid + }; + +/* // Add the HandleInput function somewhere... to handle events from the windows + MirEventDelegate delegate = + { + HandleInput, + NULL + }; + + mir_surface_set_event_handler(window->mir.surface, &delegate); +*/ + + params.pixel_format = FindValidPixelFormat(); + if (params.pixel_format == mir_pixel_format_invalid) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unable to find a correct pixel format!\n"); + return GL_FALSE; + } + + window->mir.surface = mir_connection_create_surface_sync(_glfw.mir.connection, ¶ms); + if (!mir_surface_is_valid(window->mir.surface)) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unable to create surface!\n"); + return GL_FALSE; + } + + window->mir.native_window = mir_surface_get_egl_native_window(window->mir.surface); + + return GL_TRUE; } void _glfwPlatformDestroyWindow(_GLFWwindow* window)