1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00
glfw/src/mir_monitor.c

139 lines
4.6 KiB
C
Raw Normal View History

2014-11-06 03:26:16 -05:00
//========================================================================
// GLFW 3.1 Mir - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) 2014 Brandon Schaefer <brandon.schaefer@canonical.com>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
#include <stdlib.h>
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{
2014-11-06 17:52:38 -05:00
int i, found = 0;
_GLFWmonitor** monitors = NULL;
2014-11-06 17:52:38 -05:00
MirDisplayConfiguration* displayConfig =
mir_connection_create_display_config(_glfw.mir.connection);
*count = 0;
2014-11-06 17:52:38 -05:00
for (i = 0; i < displayConfig->num_outputs; i++)
{
2014-11-06 17:52:38 -05:00
const MirDisplayOutput* out = displayConfig->outputs + i;
if (out->used &&
out->connected &&
out->num_modes &&
out->current_mode < out->num_modes)
{
found++;
monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found);
monitors[i] = _glfwAllocMonitor("Unknown",
2014-11-06 17:52:38 -05:00
out->physical_width_mm,
out->physical_height_mm);
monitors[i]->mir.x = out->position_x;
monitors[i]->mir.y = out->position_y;
monitors[i]->mir.output_id = out->output_id;
monitors[i]->mir.cur_mode = out->current_mode;
monitors[i]->modes = _glfwPlatformGetVideoModes(monitors[i],
&monitors[i]->modeCount);
}
}
2014-11-06 17:52:38 -05:00
mir_display_config_destroy(displayConfig);
2014-11-06 17:52:38 -05:00
*count = found;
return monitors;
}
GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second)
{
return first->mir.output_id == second->mir.output_id;
}
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
if (xpos)
*xpos = monitor->mir.x;
if (ypos)
*ypos = monitor->mir.y;
}
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
{
int i;
2014-11-06 03:28:17 -05:00
GLFWvidmode* modes = NULL;
2014-11-06 17:52:38 -05:00
MirDisplayConfiguration* displayConfig =
mir_connection_create_display_config(_glfw.mir.connection);
2014-11-06 03:28:17 -05:00
2014-11-06 17:52:38 -05:00
for (i = 0; i < displayConfig->num_outputs; i++)
{
2014-11-06 17:52:38 -05:00
const MirDisplayOutput* out = displayConfig->outputs + i;
if (out->output_id != monitor->mir.output_id)
continue;
modes = calloc(out->num_modes, sizeof(GLFWvidmode));
for (*found = 0; *found < out->num_modes; (*found)++)
{
modes[*found].width = out->modes[*found].horizontal_resolution;
modes[*found].height = out->modes[*found].vertical_resolution;
modes[*found].refreshRate = out->modes[*found].refresh_rate;
modes[*found].redBits = 8;
modes[*found].greenBits = 8;
modes[*found].blueBits = 8;
}
break;
}
2014-11-06 17:52:38 -05:00
mir_display_config_destroy(displayConfig);
2014-11-06 03:28:17 -05:00
return modes;
}
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
2014-11-06 17:52:38 -05:00
*mode = monitor->modes[monitor->mir.cur_mode];
}
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{
2014-11-06 03:26:16 -05:00
_glfwInputError(GLFW_PLATFORM_ERROR,
2014-11-06 17:52:38 -05:00
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{
2014-11-06 03:26:16 -05:00
_glfwInputError(GLFW_PLATFORM_ERROR,
2014-11-06 17:52:38 -05:00
"Mir: Unsupported Function %s!", __PRETTY_FUNCTION__);
}
2014-11-06 17:52:38 -05:00