2014-11-06 08:26:16 +00:00
|
|
|
//========================================================================
|
2015-06-01 20:55:06 +00:00
|
|
|
// GLFW 3.2 Mir - www.glfw.org
|
2014-11-06 08:26:16 +00:00
|
|
|
//------------------------------------------------------------------------
|
2015-07-30 17:59:32 +00:00
|
|
|
// Copyright (c) 2014-2015 Brandon Schaefer <brandon.schaefer@canonical.com>
|
2014-11-06 08:26:16 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2014-11-06 08:21:12 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
_GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
|
|
|
{
|
2014-11-06 22:52:38 +00:00
|
|
|
int i, found = 0;
|
2014-11-06 08:27:24 +00:00
|
|
|
_GLFWmonitor** monitors = NULL;
|
2014-11-06 22:52:38 +00:00
|
|
|
MirDisplayConfiguration* displayConfig =
|
|
|
|
mir_connection_create_display_config(_glfw.mir.connection);
|
|
|
|
|
|
|
|
*count = 0;
|
2014-11-06 08:26:39 +00:00
|
|
|
|
2014-11-06 22:52:38 +00:00
|
|
|
for (i = 0; i < displayConfig->num_outputs; i++)
|
2014-11-06 08:26:39 +00:00
|
|
|
{
|
2014-11-06 22:52:38 +00:00
|
|
|
const MirDisplayOutput* out = displayConfig->outputs + i;
|
2014-11-06 08:26:39 +00:00
|
|
|
|
|
|
|
if (out->used &&
|
|
|
|
out->connected &&
|
|
|
|
out->num_modes &&
|
|
|
|
out->current_mode < out->num_modes)
|
|
|
|
{
|
2014-11-10 20:12:03 +00:00
|
|
|
found++;
|
2014-11-10 17:26:20 +00:00
|
|
|
monitors = realloc(monitors, sizeof(_GLFWmonitor*) * found);
|
2014-11-10 20:12:03 +00:00
|
|
|
monitors[i] = _glfwAllocMonitor("Unknown",
|
2014-11-06 22:52:38 +00:00
|
|
|
out->physical_width_mm,
|
|
|
|
out->physical_height_mm);
|
2014-11-06 22:41:29 +00:00
|
|
|
|
2014-11-10 20:12:03 +00:00
|
|
|
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;
|
2014-11-10 17:26:20 +00:00
|
|
|
|
2014-11-10 20:12:03 +00:00
|
|
|
monitors[i]->modes = _glfwPlatformGetVideoModes(monitors[i],
|
|
|
|
&monitors[i]->modeCount);
|
2014-11-06 08:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:52:38 +00:00
|
|
|
mir_display_config_destroy(displayConfig);
|
2014-11-06 08:26:39 +00:00
|
|
|
|
2014-11-06 22:52:38 +00:00
|
|
|
*count = found;
|
2014-11-06 08:26:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-31 12:01:33 +00:00
|
|
|
void FillInRGBBitsFromPixelFormat(GLFWvidmode* mode, const MirPixelFormat pf)
|
2015-07-30 17:59:32 +00:00
|
|
|
{
|
|
|
|
switch (pf)
|
|
|
|
{
|
|
|
|
case mir_pixel_format_rgb_565:
|
|
|
|
mode->redBits = 5;
|
|
|
|
mode->greenBits = 6;
|
|
|
|
mode->blueBits = 5;
|
|
|
|
break;
|
|
|
|
case mir_pixel_format_rgba_5551:
|
|
|
|
mode->redBits = 5;
|
|
|
|
mode->greenBits = 5;
|
|
|
|
mode->blueBits = 5;
|
|
|
|
break;
|
|
|
|
case mir_pixel_format_rgba_4444:
|
|
|
|
mode->redBits = 4;
|
|
|
|
mode->greenBits = 4;
|
|
|
|
mode->blueBits = 4;
|
|
|
|
break;
|
|
|
|
case mir_pixel_format_abgr_8888:
|
|
|
|
case mir_pixel_format_xbgr_8888:
|
|
|
|
case mir_pixel_format_argb_8888:
|
|
|
|
case mir_pixel_format_xrgb_8888:
|
|
|
|
case mir_pixel_format_bgr_888:
|
|
|
|
case mir_pixel_format_rgb_888:
|
|
|
|
default:
|
2015-07-30 18:32:32 +00:00
|
|
|
mode->redBits = 8;
|
|
|
|
mode->greenBits = 8;
|
|
|
|
mode->blueBits = 8;
|
|
|
|
break;
|
2015-07-30 17:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 08:21:12 +00:00
|
|
|
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
|
|
|
|
{
|
2014-11-06 22:45:56 +00:00
|
|
|
int i;
|
2014-11-06 08:28:17 +00:00
|
|
|
GLFWvidmode* modes = NULL;
|
2014-11-06 22:52:38 +00:00
|
|
|
MirDisplayConfiguration* displayConfig =
|
2014-11-06 22:45:56 +00:00
|
|
|
mir_connection_create_display_config(_glfw.mir.connection);
|
2014-11-06 08:28:17 +00:00
|
|
|
|
2014-11-06 22:52:38 +00:00
|
|
|
for (i = 0; i < displayConfig->num_outputs; i++)
|
2014-11-06 22:45:56 +00:00
|
|
|
{
|
2014-11-06 22:52:38 +00:00
|
|
|
const MirDisplayOutput* out = displayConfig->outputs + i;
|
2014-11-06 22:45:56 +00:00
|
|
|
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;
|
2015-07-30 17:59:32 +00:00
|
|
|
|
|
|
|
FillInRGBBitsFromPixelFormat(&modes[*found], out->output_formats[*found]);
|
2014-11-06 22:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:52:38 +00:00
|
|
|
mir_display_config_destroy(displayConfig);
|
2014-11-06 08:28:17 +00:00
|
|
|
|
|
|
|
return modes;
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
|
|
|
|
{
|
2014-11-06 22:52:38 +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,
|
2015-03-10 18:51:14 +00:00
|
|
|
"Mir: Unsupported function %s", __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,
|
2015-03-10 18:51:14 +00:00
|
|
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
2014-11-06 22:52:38 +00:00
|
|
|
|