]> git.sesse.net Git - pistorm/blob - raylib/external/glfw/src/null_monitor.c
Update raylib files and Makefile for Pi 4 testing
[pistorm] / raylib / external / glfw / src / null_monitor.c
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 // It is fine to use C99 in this file because it will not be built with VS
28 //========================================================================
29
30 #include "internal.h"
31
32 #include <stdlib.h>
33 #include <string.h>
34 #include <math.h>
35
36 // The the sole (fake) video mode of our (sole) fake monitor
37 //
38 static GLFWvidmode getVideoMode(void)
39 {
40     GLFWvidmode mode;
41     mode.width = 1920;
42     mode.height = 1080;
43     mode.redBits = 8;
44     mode.greenBits = 8;
45     mode.blueBits = 8;
46     mode.refreshRate = 60;
47     return mode;
48 }
49
50 //////////////////////////////////////////////////////////////////////////
51 //////                       GLFW internal API                      //////
52 //////////////////////////////////////////////////////////////////////////
53
54 void _glfwPollMonitorsNull(void)
55 {
56     const float dpi = 141.f;
57     const GLFWvidmode mode = getVideoMode();
58     _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0",
59                                               (int) (mode.width * 25.4f / dpi),
60                                               (int) (mode.height * 25.4f / dpi));
61     _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST);
62 }
63
64 //////////////////////////////////////////////////////////////////////////
65 //////                       GLFW platform API                      //////
66 //////////////////////////////////////////////////////////////////////////
67
68 void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor)
69 {
70     _glfwFreeGammaArrays(&monitor->null.ramp);
71 }
72
73 void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
74 {
75     if (xpos)
76         *xpos = 0;
77     if (ypos)
78         *ypos = 0;
79 }
80
81 void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
82                                          float* xscale, float* yscale)
83 {
84     if (xscale)
85         *xscale = 1.f;
86     if (yscale)
87         *yscale = 1.f;
88 }
89
90 void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
91                                      int* xpos, int* ypos,
92                                      int* width, int* height)
93 {
94     const GLFWvidmode mode = getVideoMode();
95
96     if (xpos)
97         *xpos = 0;
98     if (ypos)
99         *ypos = 10;
100     if (width)
101         *width = mode.width;
102     if (height)
103         *height = mode.height - 10;
104 }
105
106 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
107 {
108     GLFWvidmode* mode = calloc(1, sizeof(GLFWvidmode));
109     *mode = getVideoMode();
110     *found = 1;
111     return mode;
112 }
113
114 void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
115 {
116     *mode = getVideoMode();
117 }
118
119 GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
120 {
121     if (!monitor->null.ramp.size)
122     {
123         _glfwAllocGammaArrays(&monitor->null.ramp, 256);
124
125         for (unsigned int i = 0;  i < monitor->null.ramp.size;  i++)
126         {
127             const float gamma = 2.2f;
128             float value;
129             value = i / (float) (monitor->null.ramp.size - 1);
130             value = powf(value, 1.f / gamma) * 65535.f + 0.5f;
131             value = _glfw_fminf(value, 65535.f);
132
133             monitor->null.ramp.red[i]   = (unsigned short) value;
134             monitor->null.ramp.green[i] = (unsigned short) value;
135             monitor->null.ramp.blue[i]  = (unsigned short) value;
136         }
137     }
138
139     _glfwAllocGammaArrays(ramp, monitor->null.ramp.size);
140     memcpy(ramp->red,   monitor->null.ramp.red,   sizeof(short) * ramp->size);
141     memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size);
142     memcpy(ramp->blue,  monitor->null.ramp.blue,  sizeof(short) * ramp->size);
143     return GLFW_TRUE;
144 }
145
146 void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
147 {
148     if (monitor->null.ramp.size != ramp->size)
149     {
150         _glfwInputError(GLFW_PLATFORM_ERROR,
151                         "Null: Gamma ramp size must match current ramp size");
152         return;
153     }
154
155     memcpy(monitor->null.ramp.red,   ramp->red,   sizeof(short) * ramp->size);
156     memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size);
157     memcpy(monitor->null.ramp.blue,  ramp->blue,  sizeof(short) * ramp->size);
158 }
159