SDL_ngagevideo.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../SDL_sysvideo.h"
  19. #ifdef SDL_VIDEO_DRIVER_NGAGE
  20. #include "SDL_ngagevideo.h"
  21. #define NGAGE_VIDEO_DRIVER_NAME "N-Gage"
  22. static void NGAGE_DeleteDevice(SDL_VideoDevice *device);
  23. static bool NGAGE_VideoInit(SDL_VideoDevice *device);
  24. static void NGAGE_VideoQuit(SDL_VideoDevice *device);
  25. static bool NGAGE_GetDisplayBounds(SDL_VideoDevice *device, SDL_VideoDisplay *display, SDL_Rect *rect);
  26. static bool NGAGE_GetDisplayModes(SDL_VideoDevice *device, SDL_VideoDisplay *display);
  27. static void NGAGE_PumpEvents(SDL_VideoDevice *device);
  28. static bool NGAGE_SuspendScreenSaver(SDL_VideoDevice *device);
  29. static SDL_VideoDevice *NGAGE_CreateDevice(void)
  30. {
  31. SDL_VideoDevice *device;
  32. SDL_VideoData *phdata;
  33. // Initialize all variables that we clean on shutdown.
  34. device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice));
  35. if (!device) {
  36. SDL_OutOfMemory();
  37. return (SDL_VideoDevice *)0;
  38. }
  39. // Initialize internal N-Gage specific data.
  40. phdata = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData));
  41. if (!phdata) {
  42. SDL_OutOfMemory();
  43. SDL_free(device);
  44. return (SDL_VideoDevice *)0;
  45. }
  46. device->internal = phdata;
  47. device->name = "Nokia N-Gage";
  48. device->VideoInit = NGAGE_VideoInit;
  49. device->VideoQuit = NGAGE_VideoQuit;
  50. device->GetDisplayBounds = NGAGE_GetDisplayBounds;
  51. device->GetDisplayModes = NGAGE_GetDisplayModes;
  52. device->PumpEvents = NGAGE_PumpEvents;
  53. device->SuspendScreenSaver = NGAGE_SuspendScreenSaver;
  54. device->free = NGAGE_DeleteDevice;
  55. device->device_caps = VIDEO_DEVICE_CAPS_FULLSCREEN_ONLY;
  56. return device;
  57. }
  58. VideoBootStrap NGAGE_bootstrap = {
  59. NGAGE_VIDEO_DRIVER_NAME,
  60. "N-Gage Video Driver",
  61. NGAGE_CreateDevice,
  62. 0
  63. };
  64. static void NGAGE_DeleteDevice(SDL_VideoDevice *device)
  65. {
  66. SDL_free(device->internal);
  67. SDL_free(device);
  68. }
  69. static bool NGAGE_VideoInit(SDL_VideoDevice *device)
  70. {
  71. SDL_VideoData *phdata = (SDL_VideoData *)device->internal;
  72. if (!phdata) {
  73. return false;
  74. }
  75. SDL_zero(phdata->mode);
  76. SDL_zero(phdata->display);
  77. phdata->mode.w = 176;
  78. phdata->mode.h = 208;
  79. phdata->mode.refresh_rate = 60.0f;
  80. phdata->mode.format = SDL_PIXELFORMAT_ARGB4444;
  81. phdata->display.name = "N-Gage";
  82. phdata->display.desktop_mode = phdata->mode;
  83. if (SDL_AddVideoDisplay(&phdata->display, false) == 0) {
  84. return false;
  85. }
  86. return true;
  87. }
  88. static void NGAGE_VideoQuit(SDL_VideoDevice *device)
  89. {
  90. SDL_VideoData *phdata = (SDL_VideoData *)device->internal;
  91. if (phdata) {
  92. SDL_zero(phdata->mode);
  93. SDL_zero(phdata->display);
  94. }
  95. }
  96. static bool NGAGE_GetDisplayBounds(SDL_VideoDevice *device, SDL_VideoDisplay *display, SDL_Rect *rect)
  97. {
  98. if (!display) {
  99. return false;
  100. }
  101. rect->x = 0;
  102. rect->y = 0;
  103. rect->w = display->current_mode->w;
  104. rect->h = display->current_mode->h;
  105. return true;
  106. }
  107. static bool NGAGE_GetDisplayModes(SDL_VideoDevice *device, SDL_VideoDisplay *display)
  108. {
  109. SDL_VideoData *phdata = (SDL_VideoData *)device->internal;
  110. SDL_DisplayMode mode;
  111. SDL_zero(mode);
  112. mode.w = phdata->mode.w;
  113. mode.h = phdata->mode.h;
  114. mode.refresh_rate = phdata->mode.refresh_rate;
  115. mode.format = phdata->mode.format;
  116. if (!SDL_AddFullscreenDisplayMode(display, &mode)) {
  117. return false;
  118. }
  119. return true;
  120. }
  121. #include "../../render/ngage/SDL_render_ngage_c.h"
  122. static void NGAGE_PumpEvents(SDL_VideoDevice *device)
  123. {
  124. NGAGE_PumpEventsInternal();
  125. }
  126. static bool NGAGE_SuspendScreenSaver(SDL_VideoDevice *device)
  127. {
  128. NGAGE_SuspendScreenSaverInternal(device->suspend_screensaver);
  129. return true;
  130. }
  131. #endif // SDL_VIDEO_DRIVER_NGAGE