2014-11-06 08:26:16 +00: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.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
2014-11-06 08:21:12 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
2014-11-06 08:23:02 +00:00
|
|
|
#include <stdlib.h>
|
2014-11-06 08:21:12 +00:00
|
|
|
|
2014-11-06 20:07:20 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-06 08:21:12 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
|
|
|
{
|
2014-11-06 08:26:39 +00:00
|
|
|
int d, found = 0;
|
|
|
|
MirDisplayConfiguration* display_config = mir_connection_create_display_config(_glfw.mir.connection);
|
|
|
|
|
2014-11-06 08:27:24 +00:00
|
|
|
_GLFWmonitor** monitors = NULL;
|
2014-11-06 20:07:20 +00:00
|
|
|
_GLFWmonitor* monitor = NULL;
|
2014-11-06 08:26:39 +00:00
|
|
|
|
|
|
|
for (d = 0; d < display_config->num_outputs; d++)
|
|
|
|
{
|
|
|
|
MirDisplayOutput const* out = display_config->outputs + d;
|
|
|
|
|
|
|
|
if (out->used &&
|
|
|
|
out->connected &&
|
|
|
|
out->num_modes &&
|
|
|
|
out->current_mode < out->num_modes)
|
|
|
|
{
|
2014-11-06 08:27:24 +00:00
|
|
|
found++;
|
2014-11-06 20:07:20 +00:00
|
|
|
monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found);
|
|
|
|
monitor = createNewMonitor(out);
|
2014-11-06 08:26:39 +00:00
|
|
|
monitors[d] = monitor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*count = found;
|
|
|
|
mir_display_config_destroy(display_config);
|
|
|
|
|
|
|
|
return monitors;
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second)
|
|
|
|
{
|
2014-11-06 08:26:39 +00:00
|
|
|
return first->mir.output_id == second->mir.output_id;
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
|
|
|
|
{
|
2014-11-06 08:26:39 +00:00
|
|
|
if (xpos)
|
|
|
|
*xpos = monitor->mir.x;
|
|
|
|
if (ypos)
|
|
|
|
*ypos = monitor->mir.y;
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
|
|
|
|
{
|
2014-11-06 08:28:17 +00:00
|
|
|
GLFWvidmode* modes = NULL;
|
|
|
|
int i, count = monitor->modeCount;
|
|
|
|
|
|
|
|
modes = calloc(count, sizeof(GLFWvidmode));
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
modes[i] = monitor->modes[i];
|
|
|
|
|
|
|
|
*found = count;
|
|
|
|
return modes;
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
|
|
|
|
{
|
2014-11-06 08:28:17 +00:00
|
|
|
*mode = monitor->modes[monitor->mir.cur_mode];
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
|
|
|
|
{
|
2014-11-06 08:26:16 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
|
|
|
|
{
|
2014-11-06 08:26:16 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Unsupported Function %s!\n", __PRETTY_FUNCTION__);
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|