2014-11-06 08:26:16 +00:00
|
|
|
//========================================================================
|
2016-08-18 21:42:15 +00:00
|
|
|
// GLFW 3.3 Mir - www.glfw.org
|
2014-11-06 08:26:16 +00:00
|
|
|
//------------------------------------------------------------------------
|
2017-03-29 02:03:29 +00:00
|
|
|
// Copyright (c) 2014-2017 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
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-12-05 00:19:48 +00:00
|
|
|
////// GLFW internal API //////
|
2014-11-06 08:21:12 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-05 00:19:48 +00:00
|
|
|
// Poll for changes in the set of connected monitors
|
|
|
|
//
|
|
|
|
void _glfwPollMonitorsMir(void)
|
2014-11-06 08:21:12 +00:00
|
|
|
{
|
2016-12-05 00:19:48 +00:00
|
|
|
int i;
|
2017-03-29 02:03:29 +00:00
|
|
|
MirDisplayConfig* displayConfig =
|
|
|
|
mir_connection_create_display_configuration(_glfw.mir.connection);
|
2014-11-06 22:52:38 +00:00
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
int numOutputs = mir_display_config_get_num_outputs(displayConfig);
|
|
|
|
|
|
|
|
for (i = 0; i < numOutputs; i++)
|
2014-11-06 08:26:39 +00:00
|
|
|
{
|
2017-03-29 02:03:29 +00:00
|
|
|
const MirOutput* output = mir_display_config_get_output(displayConfig, i);
|
|
|
|
MirOutputConnectionState state = mir_output_get_connection_state(output);
|
|
|
|
bool enabled = mir_output_is_enabled(output);
|
2014-11-06 08:26:39 +00:00
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
if (enabled && state == mir_output_connection_state_connected)
|
2014-11-06 08:26:39 +00:00
|
|
|
{
|
2017-03-29 02:03:29 +00:00
|
|
|
int widthMM = mir_output_get_physical_width_mm(output);
|
|
|
|
int heightMM = mir_output_get_physical_height_mm(output);
|
|
|
|
int x = mir_output_get_position_x(output);
|
|
|
|
int y = mir_output_get_position_y(output);
|
|
|
|
int id = mir_output_get_id(output);
|
|
|
|
size_t currentMode = mir_output_get_current_mode_index(output);
|
|
|
|
const char* name = mir_output_type_name(mir_output_get_type(output));
|
|
|
|
|
|
|
|
_GLFWmonitor* monitor = _glfwAllocMonitor(name,
|
|
|
|
widthMM,
|
|
|
|
heightMM);
|
|
|
|
monitor->mir.x = x;
|
|
|
|
monitor->mir.y = y;
|
|
|
|
monitor->mir.outputId = id;
|
|
|
|
monitor->mir.curMode = currentMode;
|
2016-12-05 00:19:48 +00:00
|
|
|
monitor->modes = _glfwPlatformGetVideoModes(monitor, &monitor->modeCount);
|
2014-11-10 17:26:20 +00:00
|
|
|
|
2016-12-05 00:19:48 +00:00
|
|
|
_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
|
2014-11-06 08:26:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
mir_display_config_release(displayConfig);
|
2014-11-06 08:21:12 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 00:19:48 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
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
|
|
|
}
|
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
static 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;
|
2017-03-29 02:03:29 +00:00
|
|
|
MirDisplayConfig* displayConfig =
|
|
|
|
mir_connection_create_display_configuration(_glfw.mir.connection);
|
|
|
|
|
|
|
|
int numOutputs = mir_display_config_get_num_outputs(displayConfig);
|
2014-11-06 08:28:17 +00:00
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
for (i = 0; i < numOutputs; i++)
|
2014-11-06 22:45:56 +00:00
|
|
|
{
|
2017-03-29 02:03:29 +00:00
|
|
|
const MirOutput* output = mir_display_config_get_output(displayConfig, i);
|
|
|
|
int id = mir_output_get_id(output);
|
|
|
|
|
|
|
|
if (id != monitor->mir.outputId)
|
2014-11-06 22:45:56 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
MirOutputConnectionState state = mir_output_get_connection_state(output);
|
|
|
|
bool enabled = mir_output_is_enabled(output);
|
2014-11-06 22:45:56 +00:00
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
// We must have been disconnected
|
|
|
|
if (!enabled || state != mir_output_connection_state_connected)
|
2014-11-06 22:45:56 +00:00
|
|
|
{
|
2017-03-29 02:03:29 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Mir: Monitor no longer connected");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int numModes = mir_output_get_num_modes(output);
|
|
|
|
modes = calloc(numModes, sizeof(GLFWvidmode));
|
2015-07-30 17:59:32 +00:00
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
for (*found = 0; *found < numModes; (*found)++)
|
|
|
|
{
|
|
|
|
const MirOutputMode* mode = mir_output_get_mode(output, *found);
|
|
|
|
int width = mir_output_mode_get_width(mode);
|
|
|
|
int height = mir_output_mode_get_height(mode);
|
|
|
|
double refreshRate = mir_output_mode_get_refresh_rate(mode);
|
|
|
|
MirPixelFormat currentFormat = mir_output_get_current_pixel_format(output);
|
|
|
|
|
|
|
|
modes[*found].width = width;
|
|
|
|
modes[*found].height = height;
|
|
|
|
modes[*found].refreshRate = refreshRate;
|
|
|
|
|
|
|
|
FillInRGBBitsFromPixelFormat(&modes[*found], currentFormat);
|
2014-11-06 22:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-29 02:03:29 +00:00
|
|
|
mir_display_config_release(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)
|
|
|
|
{
|
2016-08-16 22:26:07 +00:00
|
|
|
*mode = monitor->modes[monitor->mir.curMode];
|
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
|
|
|
|
2015-08-16 20:02:31 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI int glfwGetMirMonitor(GLFWmonitor* handle)
|
|
|
|
{
|
|
|
|
_GLFWmonitor* monitor = (_GLFWmonitor*) handle;
|
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(0);
|
2016-08-16 22:26:07 +00:00
|
|
|
return monitor->mir.outputId;
|
2015-08-16 20:02:31 +00:00
|
|
|
}
|