null_monitor.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include "internal.h"
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <math.h>
  33. // The sole (fake) video mode of our (sole) fake monitor
  34. //
  35. static GLFWvidmode getVideoMode(void)
  36. {
  37. GLFWvidmode mode;
  38. mode.width = 1920;
  39. mode.height = 1080;
  40. mode.redBits = 8;
  41. mode.greenBits = 8;
  42. mode.blueBits = 8;
  43. mode.refreshRate = 60;
  44. return mode;
  45. }
  46. //////////////////////////////////////////////////////////////////////////
  47. ////// GLFW internal API //////
  48. //////////////////////////////////////////////////////////////////////////
  49. void _glfwPollMonitorsNull(void)
  50. {
  51. const float dpi = 141.f;
  52. const GLFWvidmode mode = getVideoMode();
  53. _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0",
  54. (int) (mode.width * 25.4f / dpi),
  55. (int) (mode.height * 25.4f / dpi));
  56. _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST);
  57. }
  58. //////////////////////////////////////////////////////////////////////////
  59. ////// GLFW platform API //////
  60. //////////////////////////////////////////////////////////////////////////
  61. void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor)
  62. {
  63. _glfwFreeGammaArrays(&monitor->null.ramp);
  64. }
  65. void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor UNUSED, int* xpos, int* ypos)
  66. {
  67. if (xpos)
  68. *xpos = 0;
  69. if (ypos)
  70. *ypos = 0;
  71. }
  72. void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor UNUSED,
  73. float* xscale, float* yscale)
  74. {
  75. if (xscale)
  76. *xscale = 1.f;
  77. if (yscale)
  78. *yscale = 1.f;
  79. }
  80. void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor UNUSED,
  81. int* xpos, int* ypos,
  82. int* width, int* height)
  83. {
  84. const GLFWvidmode mode = getVideoMode();
  85. if (xpos)
  86. *xpos = 0;
  87. if (ypos)
  88. *ypos = 10;
  89. if (width)
  90. *width = mode.width;
  91. if (height)
  92. *height = mode.height - 10;
  93. }
  94. GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor UNUSED, int* found)
  95. {
  96. GLFWvidmode* mode = calloc(1, sizeof(GLFWvidmode));
  97. *mode = getVideoMode();
  98. *found = 1;
  99. return mode;
  100. }
  101. void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor UNUSED, GLFWvidmode* mode)
  102. {
  103. *mode = getVideoMode();
  104. }
  105. bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
  106. {
  107. if (!monitor->null.ramp.size)
  108. {
  109. _glfwAllocGammaArrays(&monitor->null.ramp, 256);
  110. for (unsigned int i = 0; i < monitor->null.ramp.size; i++)
  111. {
  112. const float gamma = 2.2f;
  113. float value;
  114. value = i / (float) (monitor->null.ramp.size - 1);
  115. value = powf(value, 1.f / gamma) * 65535.f + 0.5f;
  116. value = _glfw_fminf(value, 65535.f);
  117. monitor->null.ramp.red[i] = (unsigned short) value;
  118. monitor->null.ramp.green[i] = (unsigned short) value;
  119. monitor->null.ramp.blue[i] = (unsigned short) value;
  120. }
  121. }
  122. _glfwAllocGammaArrays(ramp, monitor->null.ramp.size);
  123. memcpy(ramp->red, monitor->null.ramp.red, sizeof(short) * ramp->size);
  124. memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size);
  125. memcpy(ramp->blue, monitor->null.ramp.blue, sizeof(short) * ramp->size);
  126. return true;
  127. }
  128. void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
  129. {
  130. if (monitor->null.ramp.size != ramp->size)
  131. {
  132. _glfwInputError(GLFW_PLATFORM_ERROR,
  133. "Null: Gamma ramp size must match current ramp size");
  134. return;
  135. }
  136. memcpy(monitor->null.ramp.red, ramp->red, sizeof(short) * ramp->size);
  137. memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size);
  138. memcpy(monitor->null.ramp.blue, ramp->blue, sizeof(short) * ramp->size);
  139. }