internal.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. //========================================================================
  2. // GLFW 3.4 - www.glfw.org
  3. //------------------------------------------------------------------------
  4. // Copyright (c) 2002-2006 Marcus Geelnard
  5. // Copyright (c) 2006-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. #pragma once
  28. #include "../kitty/monotonic.h"
  29. #if defined(_GLFW_USE_CONFIG_H)
  30. #include "glfw_config.h"
  31. #endif
  32. #define arraysz(x) (sizeof(x)/sizeof(x[0]))
  33. #define MAX(x, y) __extension__ ({ \
  34. __typeof__ (x) a = (x); __typeof__ (y) b = (y); \
  35. a > b ? a : b;})
  36. #if defined(GLFW_INCLUDE_GLCOREARB) || \
  37. defined(GLFW_INCLUDE_ES1) || \
  38. defined(GLFW_INCLUDE_ES2) || \
  39. defined(GLFW_INCLUDE_ES3) || \
  40. defined(GLFW_INCLUDE_ES31) || \
  41. defined(GLFW_INCLUDE_ES32) || \
  42. defined(GLFW_INCLUDE_NONE) || \
  43. defined(GLFW_INCLUDE_GLEXT) || \
  44. defined(GLFW_INCLUDE_GLU) || \
  45. defined(GLFW_INCLUDE_VULKAN) || \
  46. defined(GLFW_DLL)
  47. #error "You must not define any header option macros when compiling GLFW"
  48. #endif
  49. #define GLFW_INCLUDE_NONE
  50. #include "glfw3.h"
  51. #define EGL_PRESENT_OPAQUE_EXT 0x31df
  52. #define _GLFW_INSERT_FIRST 0
  53. #define _GLFW_INSERT_LAST 1
  54. #define _GLFW_POLL_PRESENCE 0
  55. #define _GLFW_POLL_AXES 1
  56. #define _GLFW_POLL_BUTTONS 2
  57. #define _GLFW_POLL_ALL (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS)
  58. #define _GLFW_MESSAGE_SIZE 1024
  59. typedef unsigned long long GLFWid;
  60. typedef struct _GLFWerror _GLFWerror;
  61. typedef struct _GLFWinitconfig _GLFWinitconfig;
  62. typedef struct _GLFWwndconfig _GLFWwndconfig;
  63. typedef struct _GLFWctxconfig _GLFWctxconfig;
  64. typedef struct _GLFWfbconfig _GLFWfbconfig;
  65. typedef struct _GLFWcontext _GLFWcontext;
  66. typedef struct _GLFWwindow _GLFWwindow;
  67. typedef struct _GLFWlibrary _GLFWlibrary;
  68. typedef struct _GLFWmonitor _GLFWmonitor;
  69. typedef struct _GLFWcursor _GLFWcursor;
  70. typedef struct _GLFWmapelement _GLFWmapelement;
  71. typedef struct _GLFWmapping _GLFWmapping;
  72. typedef struct _GLFWjoystick _GLFWjoystick;
  73. typedef struct _GLFWtls _GLFWtls;
  74. typedef struct _GLFWmutex _GLFWmutex;
  75. typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
  76. typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
  77. typedef void (* _GLFWswapintervalfun)(int);
  78. typedef int (* _GLFWextensionsupportedfun)(const char*);
  79. typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
  80. typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
  81. #define GL_VERSION 0x1F02
  82. #define GL_NONE 0
  83. #define GL_COLOR_BUFFER_BIT 0x00004000
  84. #define GL_UNSIGNED_BYTE 0x1401
  85. #define GL_EXTENSIONS 0x1F03
  86. #define GL_NUM_EXTENSIONS 0x821d
  87. #define GL_CONTEXT_FLAGS 0x821e
  88. #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
  89. #define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
  90. #define GL_CONTEXT_PROFILE_MASK 0x9126
  91. #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
  92. #define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
  93. #define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
  94. #define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
  95. #define GL_NO_RESET_NOTIFICATION_ARB 0x8261
  96. #define GL_CONTEXT_RELEASE_BEHAVIOR 0x82fb
  97. #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
  98. #define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
  99. #define MAX(x, y) __extension__ ({ \
  100. __typeof__ (x) a = (x); __typeof__ (y) b = (y); \
  101. a > b ? a : b;})
  102. #define MIN(x, y) __extension__ ({ \
  103. __typeof__ (x) a = (x); __typeof__ (y) b = (y); \
  104. a < b ? a : b;})
  105. typedef int GLint;
  106. typedef unsigned int GLuint;
  107. typedef unsigned int GLenum;
  108. typedef unsigned int GLbitfield;
  109. typedef unsigned char GLubyte;
  110. typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
  111. typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
  112. typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
  113. typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
  114. #define VK_NULL_HANDLE 0
  115. typedef void* VkInstance;
  116. typedef void* VkPhysicalDevice;
  117. typedef uint64_t VkSurfaceKHR;
  118. typedef uint32_t VkFlags;
  119. typedef uint32_t VkBool32;
  120. typedef enum VkStructureType
  121. {
  122. VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
  123. VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
  124. VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
  125. VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
  126. VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
  127. VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
  128. VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
  129. } VkStructureType;
  130. typedef enum VkResult
  131. {
  132. VK_SUCCESS = 0,
  133. VK_NOT_READY = 1,
  134. VK_TIMEOUT = 2,
  135. VK_EVENT_SET = 3,
  136. VK_EVENT_RESET = 4,
  137. VK_INCOMPLETE = 5,
  138. VK_ERROR_OUT_OF_HOST_MEMORY = -1,
  139. VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
  140. VK_ERROR_INITIALIZATION_FAILED = -3,
  141. VK_ERROR_DEVICE_LOST = -4,
  142. VK_ERROR_MEMORY_MAP_FAILED = -5,
  143. VK_ERROR_LAYER_NOT_PRESENT = -6,
  144. VK_ERROR_EXTENSION_NOT_PRESENT = -7,
  145. VK_ERROR_FEATURE_NOT_PRESENT = -8,
  146. VK_ERROR_INCOMPATIBLE_DRIVER = -9,
  147. VK_ERROR_TOO_MANY_OBJECTS = -10,
  148. VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
  149. VK_ERROR_SURFACE_LOST_KHR = -1000000000,
  150. VK_SUBOPTIMAL_KHR = 1000001003,
  151. VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
  152. VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
  153. VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
  154. VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
  155. VK_RESULT_MAX_ENUM = 0x7FFFFFFF
  156. } VkResult;
  157. typedef struct VkAllocationCallbacks VkAllocationCallbacks;
  158. typedef struct VkExtensionProperties
  159. {
  160. char extensionName[256];
  161. uint32_t specVersion;
  162. } VkExtensionProperties;
  163. typedef void (APIENTRY * PFN_vkVoidFunction)(void);
  164. #if defined(_GLFW_VULKAN_STATIC)
  165. PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance,const char*);
  166. VkResult vkEnumerateInstanceExtensionProperties(const char*,uint32_t*,VkExtensionProperties*);
  167. #else
  168. typedef PFN_vkVoidFunction (APIENTRY * PFN_vkGetInstanceProcAddr)(VkInstance,const char*);
  169. typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const char*,uint32_t*,VkExtensionProperties*);
  170. #define vkEnumerateInstanceExtensionProperties _glfw.vk.EnumerateInstanceExtensionProperties
  171. #define vkGetInstanceProcAddr _glfw.vk.GetInstanceProcAddr
  172. #endif
  173. #if defined(_GLFW_COCOA)
  174. #include "cocoa_platform.h"
  175. #elif defined(_GLFW_WIN32)
  176. #include "win32_platform.h"
  177. #elif defined(_GLFW_X11)
  178. #include "x11_platform.h"
  179. #elif defined(_GLFW_WAYLAND)
  180. #include "wl_platform.h"
  181. #elif defined(_GLFW_OSMESA)
  182. #include "null_platform.h"
  183. #else
  184. #error "No supported window creation API selected"
  185. #endif
  186. #include "egl_context.h"
  187. #include "osmesa_context.h"
  188. #define remove_i_from_array(array, i, count) { \
  189. (count)--; \
  190. if ((i) < (count)) { \
  191. memmove((array) + (i), (array) + (i) + 1, sizeof((array)[0]) * ((count) - (i))); /* NOLINT(bugprone-sizeof-expression) */ \
  192. }}
  193. // Constructs a version number string from the public header macros
  194. #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
  195. #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
  196. #define _GLFW_VERSION_NUMBER _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, \
  197. GLFW_VERSION_MINOR, \
  198. GLFW_VERSION_REVISION)
  199. // Checks for whether the library has been initialized
  200. #define _GLFW_REQUIRE_INIT() \
  201. if (!_glfw.initialized) \
  202. { \
  203. _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
  204. return; \
  205. }
  206. #define _GLFW_REQUIRE_INIT_OR_RETURN(x) \
  207. if (!_glfw.initialized) \
  208. { \
  209. _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
  210. return x; \
  211. }
  212. // Swaps the provided pointers
  213. #define _GLFW_SWAP_POINTERS(x, y) \
  214. do{ \
  215. __typeof__(x) t; \
  216. t = x; \
  217. x = y; \
  218. y = t; \
  219. }while(0)
  220. // Suppress some pedantic warnings
  221. #ifdef __clang__
  222. #define START_ALLOW_CASE_RANGE _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wpedantic\"")
  223. #define END_ALLOW_CASE_RANGE _Pragma("clang diagnostic pop")
  224. #define ALLOW_UNUSED_RESULT _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wunused-result\"")
  225. #define END_ALLOW_UNUSED_RESULT _Pragma("clang diagnostic pop")
  226. #else
  227. #define START_ALLOW_CASE_RANGE _Pragma("GCC diagnostic ignored \"-Wpedantic\"")
  228. #define END_ALLOW_CASE_RANGE _Pragma("GCC diagnostic pop")
  229. #define ALLOW_UNUSED_RESULT _Pragma("GCC diagnostic ignored \"-Wunused-result\"")
  230. #define END_ALLOW_UNUSED_RESULT _Pragma("GCC diagnostic pop")
  231. #endif
  232. // dlsym that works with -Wpedantic
  233. #define glfw_dlsym(dest, handle, name) do {*(void **)&(dest) = _glfw_dlsym(handle, name);}while (0)
  234. // Mark function arguments as unused
  235. #define UNUSED __attribute__ ((unused))
  236. // Per-thread error structure
  237. //
  238. struct _GLFWerror
  239. {
  240. _GLFWerror* next;
  241. int code;
  242. char description[_GLFW_MESSAGE_SIZE];
  243. };
  244. // Initialization configuration
  245. //
  246. // Parameters relating to the initialization of the library
  247. //
  248. struct _GLFWinitconfig
  249. {
  250. bool hatButtons;
  251. int angleType;
  252. bool debugKeyboard;
  253. bool debugRendering;
  254. struct {
  255. bool menubar;
  256. bool chdir;
  257. } ns;
  258. struct {
  259. bool ime;
  260. } wl;
  261. };
  262. // Window configuration
  263. //
  264. // Parameters relating to the creation of the window but not directly related
  265. // to the framebuffer. This is used to pass window creation parameters from
  266. // shared code to the platform API.
  267. //
  268. struct _GLFWwndconfig
  269. {
  270. int width;
  271. int height;
  272. const char* title;
  273. bool resizable;
  274. bool visible;
  275. bool decorated;
  276. bool focused;
  277. bool autoIconify;
  278. bool floating;
  279. bool maximized;
  280. bool centerCursor;
  281. bool focusOnShow;
  282. bool mousePassthrough;
  283. bool scaleToMonitor;
  284. int blur_radius;
  285. struct {
  286. bool retina;
  287. int color_space;
  288. char frameName[256];
  289. } ns;
  290. struct {
  291. char className[256];
  292. char instanceName[256];
  293. } x11;
  294. struct {
  295. char appId[256];
  296. uint32_t bgcolor;
  297. } wl;
  298. };
  299. // Context configuration
  300. //
  301. // Parameters relating to the creation of the context but not directly related
  302. // to the framebuffer. This is used to pass context creation parameters from
  303. // shared code to the platform API.
  304. //
  305. struct _GLFWctxconfig
  306. {
  307. int client;
  308. int source;
  309. int major;
  310. int minor;
  311. bool forward;
  312. bool debug;
  313. bool noerror;
  314. int profile;
  315. int robustness;
  316. int release;
  317. _GLFWwindow* share;
  318. struct {
  319. bool offline;
  320. } nsgl;
  321. };
  322. // Framebuffer configuration
  323. //
  324. // This describes buffers and their sizes. It also contains
  325. // a platform-specific ID used to map back to the backend API object.
  326. //
  327. // It is used to pass framebuffer parameters from shared code to the platform
  328. // API and also to enumerate and select available framebuffer configs.
  329. //
  330. struct _GLFWfbconfig
  331. {
  332. int redBits;
  333. int greenBits;
  334. int blueBits;
  335. int alphaBits;
  336. int depthBits;
  337. int stencilBits;
  338. int accumRedBits;
  339. int accumGreenBits;
  340. int accumBlueBits;
  341. int accumAlphaBits;
  342. int auxBuffers;
  343. bool stereo;
  344. int samples;
  345. bool sRGB;
  346. bool doublebuffer;
  347. bool transparent;
  348. uintptr_t handle;
  349. };
  350. // Context structure
  351. //
  352. struct _GLFWcontext
  353. {
  354. int client;
  355. int source;
  356. int major, minor, revision;
  357. bool forward, debug, noerror;
  358. int profile;
  359. int robustness;
  360. int release;
  361. PFNGLGETSTRINGIPROC GetStringi;
  362. PFNGLGETINTEGERVPROC GetIntegerv;
  363. PFNGLGETSTRINGPROC GetString;
  364. _GLFWmakecontextcurrentfun makeCurrent;
  365. _GLFWswapbuffersfun swapBuffers;
  366. _GLFWswapintervalfun swapInterval;
  367. _GLFWextensionsupportedfun extensionSupported;
  368. _GLFWgetprocaddressfun getProcAddress;
  369. _GLFWdestroycontextfun destroy;
  370. // This is defined in the context API's context.h
  371. _GLFW_PLATFORM_CONTEXT_STATE
  372. // This is defined in egl_context.h
  373. _GLFWcontextEGL egl;
  374. // This is defined in osmesa_context.h
  375. _GLFWcontextOSMesa osmesa;
  376. };
  377. // Window and context structure
  378. //
  379. struct _GLFWwindow
  380. {
  381. struct _GLFWwindow* next;
  382. // Window settings and state
  383. bool resizable;
  384. bool decorated;
  385. bool autoIconify;
  386. bool floating;
  387. bool focusOnShow;
  388. bool mousePassthrough;
  389. bool shouldClose;
  390. void* userPointer;
  391. GLFWid id;
  392. GLFWvidmode videoMode;
  393. _GLFWmonitor* monitor;
  394. _GLFWcursor* cursor;
  395. int minwidth, minheight;
  396. int maxwidth, maxheight;
  397. int numer, denom;
  398. int widthincr, heightincr;
  399. bool stickyKeys;
  400. bool stickyMouseButtons;
  401. bool lockKeyMods;
  402. int cursorMode;
  403. char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
  404. GLFWkeyevent activated_keys[16];
  405. // Virtual cursor position when cursor is disabled
  406. double virtualCursorPosX, virtualCursorPosY;
  407. bool rawMouseMotion;
  408. _GLFWcontext context;
  409. #ifdef _GLFW_WAYLAND
  410. bool swaps_disallowed;
  411. #else
  412. const bool swaps_disallowed;
  413. #endif
  414. struct {
  415. GLFWwindowposfun pos;
  416. GLFWwindowsizefun size;
  417. GLFWwindowclosefun close;
  418. GLFWwindowrefreshfun refresh;
  419. GLFWwindowfocusfun focus;
  420. GLFWwindowocclusionfun occlusion;
  421. GLFWwindowiconifyfun iconify;
  422. GLFWwindowmaximizefun maximize;
  423. GLFWframebuffersizefun fbsize;
  424. GLFWwindowcontentscalefun scale;
  425. GLFWmousebuttonfun mouseButton;
  426. GLFWcursorposfun cursorPos;
  427. GLFWcursorenterfun cursorEnter;
  428. GLFWscrollfun scroll;
  429. GLFWkeyboardfun keyboard;
  430. GLFWdropfun drop;
  431. GLFWliveresizefun liveResize;
  432. } callbacks;
  433. // This is defined in the window API's platform.h
  434. _GLFW_PLATFORM_WINDOW_STATE;
  435. };
  436. // Monitor structure
  437. //
  438. struct _GLFWmonitor
  439. {
  440. char* name;
  441. void* userPointer;
  442. // Physical dimensions in millimeters.
  443. int widthMM, heightMM;
  444. // The window whose video mode is current on this monitor
  445. _GLFWwindow* window;
  446. GLFWvidmode* modes;
  447. int modeCount;
  448. GLFWvidmode currentMode;
  449. GLFWgammaramp originalRamp;
  450. GLFWgammaramp currentRamp;
  451. // This is defined in the window API's platform.h
  452. _GLFW_PLATFORM_MONITOR_STATE;
  453. };
  454. // Cursor structure
  455. //
  456. struct _GLFWcursor
  457. {
  458. _GLFWcursor* next;
  459. // This is defined in the window API's platform.h
  460. _GLFW_PLATFORM_CURSOR_STATE;
  461. };
  462. // Gamepad mapping element structure
  463. //
  464. struct _GLFWmapelement
  465. {
  466. uint8_t type;
  467. uint8_t index;
  468. int8_t axisScale;
  469. int8_t axisOffset;
  470. };
  471. // Gamepad mapping structure
  472. //
  473. struct _GLFWmapping
  474. {
  475. char name[128];
  476. char guid[33];
  477. _GLFWmapelement buttons[15];
  478. _GLFWmapelement axes[6];
  479. };
  480. // Joystick structure
  481. //
  482. struct _GLFWjoystick
  483. {
  484. bool present;
  485. float* axes;
  486. int axisCount;
  487. unsigned char* buttons;
  488. int buttonCount;
  489. unsigned char* hats;
  490. int hatCount;
  491. char* name;
  492. void* userPointer;
  493. char guid[33];
  494. _GLFWmapping* mapping;
  495. // This is defined in the joystick API's joystick.h
  496. _GLFW_PLATFORM_JOYSTICK_STATE;
  497. };
  498. // Thread local storage structure
  499. //
  500. struct _GLFWtls
  501. {
  502. // This is defined in the platform's thread.h
  503. _GLFW_PLATFORM_TLS_STATE;
  504. };
  505. // Mutex structure
  506. //
  507. struct _GLFWmutex
  508. {
  509. // This is defined in the platform's thread.h
  510. _GLFW_PLATFORM_MUTEX_STATE;
  511. };
  512. typedef struct _GLFWClipboardData {
  513. const char** mime_types;
  514. size_t num_mime_types;
  515. GLFWclipboarditerfun get_data;
  516. GLFWClipboardType ctype;
  517. } _GLFWClipboardData;
  518. // Library global data
  519. //
  520. struct _GLFWlibrary
  521. {
  522. bool initialized;
  523. struct {
  524. _GLFWinitconfig init;
  525. _GLFWfbconfig framebuffer;
  526. _GLFWwndconfig window;
  527. _GLFWctxconfig context;
  528. int refreshRate;
  529. } hints;
  530. _GLFWClipboardData primary, clipboard;
  531. _GLFWerror* errorListHead;
  532. _GLFWcursor* cursorListHead;
  533. _GLFWwindow* windowListHead;
  534. GLFWid focusedWindowId;
  535. _GLFWmonitor** monitors;
  536. int monitorCount;
  537. bool joysticksInitialized;
  538. _GLFWjoystick joysticks[GLFW_JOYSTICK_LAST + 1];
  539. _GLFWmapping* mappings;
  540. int mappingCount;
  541. _GLFWtls errorSlot;
  542. _GLFWtls contextSlot;
  543. _GLFWmutex errorLock;
  544. bool ignoreOSKeyboardProcessing;
  545. struct {
  546. bool available;
  547. void* handle;
  548. char* extensions[2];
  549. #if !defined(_GLFW_VULKAN_STATIC)
  550. PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
  551. PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
  552. #endif
  553. bool KHR_surface;
  554. #if defined(_GLFW_WIN32)
  555. bool KHR_win32_surface;
  556. #elif defined(_GLFW_COCOA)
  557. bool MVK_macos_surface;
  558. bool EXT_metal_surface;
  559. #elif defined(_GLFW_X11)
  560. bool KHR_xlib_surface;
  561. bool KHR_xcb_surface;
  562. #elif defined(_GLFW_WAYLAND)
  563. bool KHR_wayland_surface;
  564. #endif
  565. } vk;
  566. struct {
  567. GLFWmonitorfun monitor;
  568. GLFWjoystickfun joystick;
  569. GLFWapplicationclosefun application_close;
  570. GLFWsystemcolorthemechangefun system_color_theme_change;
  571. GLFWdrawtextfun draw_text;
  572. GLFWcurrentselectionfun get_current_selection;
  573. GLFWhascurrentselectionfun has_current_selection;
  574. GLFWimecursorpositionfun get_ime_cursor_position;
  575. } callbacks;
  576. // This is defined in the window API's platform.h
  577. _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
  578. // This is defined in the context API's context.h
  579. _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE
  580. // This is defined in the platform's joystick.h
  581. _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE
  582. // This is defined in egl_context.h
  583. _GLFWlibraryEGL egl;
  584. // This is defined in osmesa_context.h
  585. _GLFWlibraryOSMesa osmesa;
  586. };
  587. // Global state shared between compilation units of GLFW
  588. //
  589. extern _GLFWlibrary _glfw;
  590. //////////////////////////////////////////////////////////////////////////
  591. ////// GLFW platform API //////
  592. //////////////////////////////////////////////////////////////////////////
  593. int _glfwPlatformInit(void);
  594. void _glfwPlatformTerminate(void);
  595. const char* _glfwPlatformGetVersionString(void);
  596. void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
  597. void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
  598. void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
  599. void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, bool enabled);
  600. bool _glfwPlatformRawMouseMotionSupported(void);
  601. int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
  602. const GLFWimage* image, int xhot, int yhot, int count);
  603. int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, GLFWCursorShape shape);
  604. void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
  605. void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
  606. const char* _glfwPlatformGetNativeKeyName(int native_key);
  607. int _glfwPlatformGetNativeKeyForKey(uint32_t key);
  608. void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor);
  609. void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
  610. void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
  611. float* xscale, float* yscale);
  612. void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos, int *width, int *height);
  613. GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
  614. bool _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
  615. bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
  616. void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
  617. void _glfwPlatformSetClipboard(GLFWClipboardType t);
  618. void _glfwPlatformGetClipboard(GLFWClipboardType clipboard_type, const char* mime_type, GLFWclipboardwritedatafun write_data, void *object);
  619. bool _glfwPlatformInitJoysticks(void);
  620. void _glfwPlatformTerminateJoysticks(void);
  621. int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode);
  622. void _glfwPlatformUpdateGamepadGUID(char* guid);
  623. int _glfwPlatformCreateWindow(_GLFWwindow* window,
  624. const _GLFWwndconfig* wndconfig,
  625. const _GLFWctxconfig* ctxconfig,
  626. const _GLFWfbconfig* fbconfig);
  627. void _glfwPlatformDestroyWindow(_GLFWwindow* window);
  628. void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
  629. void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
  630. int count, const GLFWimage* images);
  631. void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
  632. void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
  633. void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
  634. void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
  635. void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
  636. int minwidth, int minheight,
  637. int maxwidth, int maxheight);
  638. void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
  639. void _glfwPlatformSetWindowSizeIncrements(_GLFWwindow* window, int widthincr, int heightincr);
  640. void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
  641. void _glfwInputLiveResize(_GLFWwindow* window, bool started);
  642. void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
  643. int* left, int* top,
  644. int* right, int* bottom);
  645. void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
  646. float* xscale, float* yscale);
  647. monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window);
  648. void _glfwPlatformIconifyWindow(_GLFWwindow* window);
  649. void _glfwPlatformRestoreWindow(_GLFWwindow* window);
  650. void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
  651. void _glfwPlatformShowWindow(_GLFWwindow* window);
  652. void _glfwPlatformHideWindow(_GLFWwindow* window);
  653. void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
  654. int _glfwPlatformWindowBell(_GLFWwindow* window);
  655. void _glfwPlatformFocusWindow(_GLFWwindow* window);
  656. void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor,
  657. int xpos, int ypos, int width, int height,
  658. int refreshRate);
  659. bool _glfwPlatformToggleFullscreen(_GLFWwindow *w, unsigned int flags);
  660. bool _glfwPlatformIsFullscreen(_GLFWwindow *w, unsigned int flags);
  661. int _glfwPlatformWindowFocused(_GLFWwindow* window);
  662. int _glfwPlatformWindowOccluded(_GLFWwindow* window);
  663. int _glfwPlatformWindowIconified(_GLFWwindow* window);
  664. int _glfwPlatformWindowVisible(_GLFWwindow* window);
  665. int _glfwPlatformWindowMaximized(_GLFWwindow* window);
  666. int _glfwPlatformWindowHovered(_GLFWwindow* window);
  667. int _glfwPlatformFramebufferTransparent(_GLFWwindow* window);
  668. float _glfwPlatformGetWindowOpacity(_GLFWwindow* window);
  669. void _glfwPlatformSetWindowResizable(_GLFWwindow* window, bool enabled);
  670. void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, bool enabled);
  671. void _glfwPlatformSetWindowFloating(_GLFWwindow* window, bool enabled);
  672. void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, bool enabled);
  673. void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity);
  674. void _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev);
  675. void _glfwPlatformChangeCursorTheme(void);
  676. void _glfwPlatformPollEvents(void);
  677. void _glfwPlatformWaitEvents(void);
  678. void _glfwPlatformWaitEventsTimeout(monotonic_t timeout);
  679. void _glfwPlatformPostEmptyEvent(void);
  680. EGLenum _glfwPlatformGetEGLPlatform(EGLint** attribs);
  681. EGLNativeDisplayType _glfwPlatformGetEGLNativeDisplay(void);
  682. EGLNativeWindowType _glfwPlatformGetEGLNativeWindow(_GLFWwindow* window);
  683. void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
  684. int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
  685. VkPhysicalDevice device,
  686. uint32_t queuefamily);
  687. VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
  688. _GLFWwindow* window,
  689. const VkAllocationCallbacks* allocator,
  690. VkSurfaceKHR* surface);
  691. bool _glfwPlatformCreateTls(_GLFWtls* tls);
  692. void _glfwPlatformDestroyTls(_GLFWtls* tls);
  693. void* _glfwPlatformGetTls(_GLFWtls* tls);
  694. void _glfwPlatformSetTls(_GLFWtls* tls, void* value);
  695. bool _glfwPlatformCreateMutex(_GLFWmutex* mutex);
  696. void _glfwPlatformDestroyMutex(_GLFWmutex* mutex);
  697. void _glfwPlatformLockMutex(_GLFWmutex* mutex);
  698. void _glfwPlatformUnlockMutex(_GLFWmutex* mutex);
  699. //////////////////////////////////////////////////////////////////////////
  700. ////// GLFW event API //////
  701. //////////////////////////////////////////////////////////////////////////
  702. void _glfwInputWindowFocus(_GLFWwindow* window, bool focused);
  703. void _glfwInputWindowOcclusion(_GLFWwindow* window, bool occluded);
  704. void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
  705. void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
  706. void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);
  707. void _glfwInputWindowContentScale(_GLFWwindow* window,
  708. float xscale, float yscale);
  709. void _glfwInputWindowIconify(_GLFWwindow* window, bool iconified);
  710. void _glfwInputWindowMaximize(_GLFWwindow* window, bool maximized);
  711. void _glfwInputWindowDamage(_GLFWwindow* window);
  712. void _glfwInputWindowCloseRequest(_GLFWwindow* window);
  713. void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor);
  714. void _glfwInputKeyboard(_GLFWwindow *window, GLFWkeyevent *ev);
  715. void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags, int mods);
  716. void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
  717. void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
  718. void _glfwInputCursorEnter(_GLFWwindow* window, bool entered);
  719. int _glfwInputDrop(_GLFWwindow* window, const char *mime, const char *text, size_t sz);
  720. void _glfwInputColorScheme(GLFWColorScheme, bool);
  721. void _glfwPlatformInputColorScheme(GLFWColorScheme);
  722. void _glfwInputJoystick(_GLFWjoystick* js, int event);
  723. void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
  724. void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
  725. void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
  726. void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
  727. void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
  728. #if defined(__GNUC__) || defined(__clang__)
  729. void _glfwInputError(int code, const char* format, ...)
  730. __attribute__((format(printf, 2, 3)));
  731. void _glfwDebug(const char* format, ...)
  732. __attribute__((format(printf, 1, 2)));
  733. #else
  734. void _glfwInputError(int code, const char* format, ...);
  735. void _glfwDebug(const char* format, ...);
  736. #endif
  737. #ifdef DEBUG_EVENT_LOOP
  738. #define EVDBG(...) _glfwDebug(__VA_ARGS__)
  739. #else
  740. #define EVDBG(...)
  741. #endif
  742. //////////////////////////////////////////////////////////////////////////
  743. ////// GLFW internal API //////
  744. //////////////////////////////////////////////////////////////////////////
  745. bool _glfwStringInExtensionString(const char* string, const char* extensions);
  746. bool _glfwRefreshContextAttribs(_GLFWwindow* window,
  747. const _GLFWctxconfig* ctxconfig);
  748. bool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig);
  749. const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
  750. const GLFWvidmode* desired);
  751. int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
  752. _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM);
  753. void _glfwFreeMonitor(_GLFWmonitor* monitor);
  754. void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
  755. void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
  756. void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
  757. _GLFWjoystick* _glfwAllocJoystick(const char* name,
  758. const char* guid,
  759. int axisCount,
  760. int buttonCount,
  761. int hatCount);
  762. void _glfwFreeJoystick(_GLFWjoystick* js);
  763. const char* _glfwGetKeyName(int key);
  764. void _glfwCenterCursorInContentArea(_GLFWwindow* window);
  765. bool _glfwInitVulkan(int mode);
  766. void _glfwTerminateVulkan(void);
  767. const char* _glfwGetVulkanResultString(VkResult result);
  768. _GLFWwindow* _glfwFocusedWindow(void);
  769. _GLFWwindow* _glfwWindowForId(GLFWid id);
  770. void _glfwPlatformRunMainLoop(GLFWtickcallback, void*);
  771. void _glfwPlatformStopMainLoop(void);
  772. unsigned long long _glfwPlatformAddTimer(monotonic_t interval, bool repeats, GLFWuserdatafun callback, void *callback_data, GLFWuserdatafun free_callback);
  773. void _glfwPlatformUpdateTimer(unsigned long long timer_id, monotonic_t interval, bool enabled);
  774. void _glfwPlatformRemoveTimer(unsigned long long timer_id);
  775. int _glfwPlatformSetWindowBlur(_GLFWwindow* handle, int value);
  776. char* _glfw_strdup(const char* source);
  777. void _glfw_free_clipboard_data(_GLFWClipboardData *cd);
  778. #define debug_rendering(...) if (_glfw.hints.init.debugRendering) { timed_debug_print(__VA_ARGS__); }
  779. #define debug_input(...) if (_glfw.hints.init.debugKeyboard) { timed_debug_print(__VA_ARGS__); }