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.
This commit is contained in:
BrandonSchaefer 2014-11-06 12:07:20 -08:00 committed by Camilla Berglund
parent f4f525549c
commit 4674ed367d
4 changed files with 70 additions and 31 deletions

View File

@ -43,9 +43,6 @@ int _glfwPlatformInit(void)
_glfw.mir.native_display = mir_connection_get_egl_native_display(_glfw.mir.connection); _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()) if (!_glfwInitContextAPI())
return GL_FALSE; return GL_FALSE;
@ -57,6 +54,8 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
_glfwTerminateContextAPI();
_glfwTerminateJoysticks();
mir_connection_release(_glfw.mir.connection); mir_connection_release(_glfw.mir.connection);
} }

View File

@ -28,6 +28,42 @@
#include <stdlib.h> #include <stdlib.h>
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 ////// ////// GLFW platform API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -38,6 +74,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
MirDisplayConfiguration* display_config = mir_connection_create_display_config(_glfw.mir.connection); MirDisplayConfiguration* display_config = mir_connection_create_display_config(_glfw.mir.connection);
_GLFWmonitor** monitors = NULL; _GLFWmonitor** monitors = NULL;
_GLFWmonitor* monitor = NULL;
for (d = 0; d < display_config->num_outputs; d++) for (d = 0; d < display_config->num_outputs; d++)
{ {
@ -50,29 +87,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{ {
found++; found++;
monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found); monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found);
monitor = createNewMonitor(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 = 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[d] = monitor; monitors[d] = monitor;
} }
} }

View File

@ -371,7 +371,21 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
if (!_glfwCreateContext(window, ctxconfig, fbconfig)) if (!_glfwCreateContext(window, ctxconfig, fbconfig))
return GL_FALSE; 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.width = wndconfig->width;
window->mir.height = wndconfig->height; window->mir.height = wndconfig->height;
@ -390,6 +404,8 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
mir_surface_release_sync(window->mir.surface); mir_surface_release_sync(window->mir.surface);
window->mir.surface = NULL; window->mir.surface = NULL;
} }
_glfwDestroyContext(window);
} }
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title)
@ -430,8 +446,7 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height)
void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, mir_surface_set_type(window->mir.surface, mir_surface_state_minimized);
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
} }
void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window)
@ -441,15 +456,20 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformHideWindow(_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) void _glfwPlatformShowWindow(_GLFWwindow* window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
} }
void _glfwPlatformUnhideWindow(_GLFWwindow* window) 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 // 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) void _glfwPlatformDestroyCursor(_GLFWcursor* cursor)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
} }
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor) void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
@ -497,6 +519,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
void _glfwPlatformApplyCursorMode(_GLFWwindow* window) void _glfwPlatformApplyCursorMode(_GLFWwindow* window)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR,
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
} }
void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)

View File

@ -600,6 +600,7 @@ int _glfwPlatformInit(void)
void _glfwPlatformTerminate(void) void _glfwPlatformTerminate(void)
{ {
_glfwTerminateContextAPI(); _glfwTerminateContextAPI();
_glfwTerminateJoysticks();
if (_glfw.wl.cursorTheme) if (_glfw.wl.cursorTheme)
wl_cursor_theme_destroy(_glfw.wl.cursorTheme); wl_cursor_theme_destroy(_glfw.wl.cursorTheme);