From 4674ed367d226adf8fdbbfe55faf6a47bdb570bf Mon Sep 17 00:00:00 2001 From: BrandonSchaefer Date: Thu, 6 Nov 2014 12:07:20 -0800 Subject: [PATCH] Fix some memory leaks. One in wl_init.c, need to clean up Joysticks. Finish getting the monitor modes set up. Finish adding Unsupported error messages. --- src/mir_init.c | 5 ++-- src/mir_monitor.c | 63 +++++++++++++++++++++++++++++------------------ src/mir_window.c | 32 +++++++++++++++++++++--- src/wl_init.c | 1 + 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/src/mir_init.c b/src/mir_init.c index f28f8e37..d50796f0 100644 --- a/src/mir_init.c +++ b/src/mir_init.c @@ -43,9 +43,6 @@ int _glfwPlatformInit(void) _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. - if (!_glfwInitContextAPI()) return GL_FALSE; @@ -57,6 +54,8 @@ int _glfwPlatformInit(void) void _glfwPlatformTerminate(void) { + _glfwTerminateContextAPI(); + _glfwTerminateJoysticks(); mir_connection_release(_glfw.mir.connection); } diff --git a/src/mir_monitor.c b/src/mir_monitor.c index e18c7041..9d16dd0f 100644 --- a/src/mir_monitor.c +++ b/src/mir_monitor.c @@ -28,6 +28,42 @@ #include +GLFWvidmode* createMonitorModes(MirDisplayOutput const* out) +{ + GLFWvidmode* modes = calloc(out->num_modes, sizeof(GLFWvidmode)); + + int n_mode; + for (n_mode = 0; n_mode < out->num_modes; n_mode++) + { + modes[n_mode].width = out->modes[n_mode].horizontal_resolution; + modes[n_mode].height = out->modes[n_mode].vertical_resolution; + modes[n_mode].refreshRate = out->modes[n_mode].refresh_rate; + modes[n_mode].redBits = 8; + modes[n_mode].greenBits = 8; + modes[n_mode].blueBits = 8; + } + + return modes; +} + +_GLFWmonitor* createNewMonitor(MirDisplayOutput const* out) +{ + _GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor)); + + monitor->mir.x = out->position_x; + monitor->mir.y = out->position_y; + monitor->mir.output_id = out->output_id; + monitor->mir.cur_mode = out->current_mode; + monitor->modeCount = out->num_modes; + monitor->widthMM = out->physical_width_mm; + monitor->heightMM = out->physical_height_mm; + monitor->modes = createMonitorModes(out); + + _glfwPlatformGetVideoMode(monitor, &monitor->currentMode); + + return monitor; +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -38,6 +74,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) MirDisplayConfiguration* display_config = mir_connection_create_display_config(_glfw.mir.connection); _GLFWmonitor** monitors = NULL; + _GLFWmonitor* monitor = NULL; for (d = 0; d < display_config->num_outputs; d++) { @@ -49,30 +86,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) out->current_mode < out->num_modes) { found++; - monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); - - _GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor)); - - monitor->mir.x = out->position_x; - monitor->mir.y = out->position_y; - monitor->mir.output_id = out->output_id; - monitor->mir.cur_mode = out->current_mode; - monitor->modeCount = out->num_modes; - monitor->widthMM = out->physical_width_mm; - monitor->heightMM = out->physical_height_mm; - - monitor->modes = calloc(out->num_modes, sizeof(GLFWvidmode)); - - int n_mode; - for (n_mode = 0; n_mode < out->num_modes; n_mode++) - { - monitor->modes[n_mode].width = out->modes[n_mode].horizontal_resolution; - monitor->modes[n_mode].height = out->modes[n_mode].vertical_resolution; - monitor->modes[n_mode].refreshRate = out->modes[n_mode].refresh_rate; - } - - _glfwPlatformGetVideoMode(monitor, &monitor->currentMode); - + monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); + monitor = createNewMonitor(out); monitors[d] = monitor; } } diff --git a/src/mir_window.c b/src/mir_window.c index a26e873c..e21f319a 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -371,7 +371,21 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!_glfwCreateContext(window, ctxconfig, fbconfig)) return GL_FALSE; - // FIXME Add a check here to ensure we are within our max width/height + if (wndconfig->monitor) + { + mir_surface_set_type(window->mir.surface, mir_surface_state_fullscreen); + + if (wndconfig->width > wndconfig->monitor->currentMode.width || + wndconfig->height > wndconfig->monitor->currentMode.height) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Requested surface size is to large (%i %i)\n", + wndconfig->width, wndconfig->height); + + return GL_FALSE; + } + } + window->mir.width = wndconfig->width; window->mir.height = wndconfig->height; @@ -390,6 +404,8 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) mir_surface_release_sync(window->mir.surface); window->mir.surface = NULL; } + + _glfwDestroyContext(window); } void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) @@ -430,8 +446,7 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) void _glfwPlatformIconifyWindow(_GLFWwindow* window) { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__); + mir_surface_set_type(window->mir.surface, mir_surface_state_minimized); } void _glfwPlatformRestoreWindow(_GLFWwindow* window) @@ -441,15 +456,20 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window) { - mir_surface_set_type(window->mir.surface, mir_surface_state_minimized); + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__); } void _glfwPlatformShowWindow(_GLFWwindow* window) { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__); } void _glfwPlatformUnhideWindow(_GLFWwindow* window) { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__); } // Mir does event handling in a different thread, so windows get events directly as they happen @@ -481,6 +501,8 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, const GLFWimage* image, int x void _glfwPlatformDestroyCursor(_GLFWcursor* cursor) { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__); } void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) @@ -497,6 +519,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos) void _glfwPlatformApplyCursorMode(_GLFWwindow* window) { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__); } void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) diff --git a/src/wl_init.c b/src/wl_init.c index 9105df7a..0269ee34 100644 --- a/src/wl_init.c +++ b/src/wl_init.c @@ -600,6 +600,7 @@ int _glfwPlatformInit(void) void _glfwPlatformTerminate(void) { _glfwTerminateContextAPI(); + _glfwTerminateJoysticks(); if (_glfw.wl.cursorTheme) wl_cursor_theme_destroy(_glfw.wl.cursorTheme);