master
ブランチ master
Snake / deps / raylib / src / external / glfw / src / null_monitor.c
5.1 KB、160行 生 Blame 履歴
1//========================================================================
2// GLFW 3.4 - www.glfw.org
3//------------------------------------------------------------------------
4// Copyright (c) 2016 Google Inc.
5// Copyright (c) 2016-2019 Camilla Löwy <elmindreda@glfw.org>
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10//
11// Permission is granted to anyone to use this software for any purpose,
12// including commercial applications, and to alter it and redistribute it
13// freely, subject to the following restrictions:
14//
15// 1. The origin of this software must not be misrepresented; you must not
16// claim that you wrote the original software. If you use this software
17// in a product, an acknowledgment in the product documentation would
18// be appreciated but is not required.
19//
20// 2. Altered source versions must be plainly marked as such, and must not
21// be misrepresented as being the original software.
22//
23// 3. This notice may not be removed or altered from any source
24// distribution.
25//
26//========================================================================
27
28#include "internal.h"
29
30#include <stdlib.h>
31#include <string.h>
32#include <math.h>
33
34// The the sole (fake) video mode of our (sole) fake monitor
35//
36static GLFWvidmode getVideoMode(void)
37{
38 GLFWvidmode mode;
39 mode.width = 1920;
40 mode.height = 1080;
41 mode.redBits = 8;
42 mode.greenBits = 8;
43 mode.blueBits = 8;
44 mode.refreshRate = 60;
45 return mode;
46}
47
48//////////////////////////////////////////////////////////////////////////
49////// GLFW internal API //////
50//////////////////////////////////////////////////////////////////////////
51
52void _glfwPollMonitorsNull(void)
53{
54 const float dpi = 141.f;
55 const GLFWvidmode mode = getVideoMode();
56 _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0",
57 (int) (mode.width * 25.4f / dpi),
58 (int) (mode.height * 25.4f / dpi));
59 _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST);
60}
61
62//////////////////////////////////////////////////////////////////////////
63////// GLFW platform API //////
64//////////////////////////////////////////////////////////////////////////
65
66void _glfwFreeMonitorNull(_GLFWmonitor* monitor)
67{
68 _glfwFreeGammaArrays(&monitor->null.ramp);
69}
70
71void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos)
72{
73 if (xpos)
74 *xpos = 0;
75 if (ypos)
76 *ypos = 0;
77}
78
79void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor,
80 float* xscale, float* yscale)
81{
82 if (xscale)
83 *xscale = 1.f;
84 if (yscale)
85 *yscale = 1.f;
86}
87
88void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor,
89 int* xpos, int* ypos,
90 int* width, int* height)
91{
92 const GLFWvidmode mode = getVideoMode();
93
94 if (xpos)
95 *xpos = 0;
96 if (ypos)
97 *ypos = 10;
98 if (width)
99 *width = mode.width;
100 if (height)
101 *height = mode.height - 10;
102}
103
104GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found)
105{
106 GLFWvidmode* mode = _glfw_calloc(1, sizeof(GLFWvidmode));
107 *mode = getVideoMode();
108 *found = 1;
109 return mode;
110}
111
112GLFWbool _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode)
113{
114 *mode = getVideoMode();
115 return GLFW_TRUE;
116}
117
118GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
119{
120 if (!monitor->null.ramp.size)
121 {
122 unsigned int i;
123
124 _glfwAllocGammaArrays(&monitor->null.ramp, 256);
125
126 for (i = 0; i < monitor->null.ramp.size; i++)
127 {
128 const float gamma = 2.2f;
129 float value;
130 value = i / (float) (monitor->null.ramp.size - 1);
131 value = powf(value, 1.f / gamma) * 65535.f + 0.5f;
132 value = fminf(value, 65535.f);
133
134 monitor->null.ramp.red[i] = (unsigned short) value;
135 monitor->null.ramp.green[i] = (unsigned short) value;
136 monitor->null.ramp.blue[i] = (unsigned short) value;
137 }
138 }
139
140 _glfwAllocGammaArrays(ramp, monitor->null.ramp.size);
141 memcpy(ramp->red, monitor->null.ramp.red, sizeof(short) * ramp->size);
142 memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size);
143 memcpy(ramp->blue, monitor->null.ramp.blue, sizeof(short) * ramp->size);
144 return GLFW_TRUE;
145}
146
147void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
148{
149 if (monitor->null.ramp.size != ramp->size)
150 {
151 _glfwInputError(GLFW_PLATFORM_ERROR,
152 "Null: Gamma ramp size must match current ramp size");
153 return;
154 }
155
156 memcpy(monitor->null.ramp.red, ramp->red, sizeof(short) * ramp->size);
157 memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size);
158 memcpy(monitor->null.ramp.blue, ramp->blue, sizeof(short) * ramp->size);
159}
160