mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
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:
parent
f4f525549c
commit
4674ed367d
@ -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);
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,42 @@
|
||||
|
||||
#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 //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -600,6 +600,7 @@ int _glfwPlatformInit(void)
|
||||
void _glfwPlatformTerminate(void)
|
||||
{
|
||||
_glfwTerminateContextAPI();
|
||||
_glfwTerminateJoysticks();
|
||||
|
||||
if (_glfw.wl.cursorTheme)
|
||||
wl_cursor_theme_destroy(_glfw.wl.cursorTheme);
|
||||
|
Loading…
Reference in New Issue
Block a user