SDL_nullvideo.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
  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_internal.h"
  19. #if SDL_VIDEO_DRIVER_DUMMY
  20. /* Dummy SDL video driver implementation; this is just enough to make an
  21. * SDL-based application THINK it's got a working video driver, for
  22. * applications that call SDL_Init(SDL_INIT_VIDEO) when they don't need it,
  23. * and also for use as a collection of stubs when porting SDL to a new
  24. * platform for which you haven't yet written a valid video driver.
  25. *
  26. * This is also a great way to determine bottlenecks: if you think that SDL
  27. * is a performance problem for a given platform, enable this driver, and
  28. * then see if your application runs faster without video overhead.
  29. *
  30. * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
  31. * of this was cut-and-pasted from Stephane Peter's work in the AAlib
  32. * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
  33. */
  34. #include "SDL_video.h"
  35. #include "SDL_mouse.h"
  36. #include "../SDL_sysvideo.h"
  37. #include "../SDL_pixels_c.h"
  38. #include "../../events/SDL_events_c.h"
  39. #include "SDL_nullvideo.h"
  40. #include "SDL_nullevents_c.h"
  41. #include "SDL_nullframebuffer_c.h"
  42. #define DUMMYVID_DRIVER_NAME "dummy"
  43. /* Initialization/Query functions */
  44. static int DUMMY_VideoInit(_THIS);
  45. static int DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
  46. static void DUMMY_VideoQuit(_THIS);
  47. /* DUMMY driver bootstrap functions */
  48. static int
  49. DUMMY_Available(void)
  50. {
  51. const char *envr = SDL_getenv("SDL_VIDEODRIVER");
  52. if ((envr) && (SDL_strcmp(envr, DUMMYVID_DRIVER_NAME) == 0)) {
  53. return (1);
  54. }
  55. return (0);
  56. }
  57. static void
  58. DUMMY_DeleteDevice(SDL_VideoDevice * device)
  59. {
  60. SDL_free(device);
  61. }
  62. static SDL_VideoDevice *
  63. DUMMY_CreateDevice(int devindex)
  64. {
  65. SDL_VideoDevice *device;
  66. /* Initialize all variables that we clean on shutdown */
  67. device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
  68. if (!device) {
  69. SDL_OutOfMemory();
  70. SDL_free(device);
  71. return (0);
  72. }
  73. /* Set the function pointers */
  74. device->VideoInit = DUMMY_VideoInit;
  75. device->VideoQuit = DUMMY_VideoQuit;
  76. device->SetDisplayMode = DUMMY_SetDisplayMode;
  77. device->PumpEvents = DUMMY_PumpEvents;
  78. device->CreateWindowFramebuffer = SDL_DUMMY_CreateWindowFramebuffer;
  79. device->UpdateWindowFramebuffer = SDL_DUMMY_UpdateWindowFramebuffer;
  80. device->DestroyWindowFramebuffer = SDL_DUMMY_DestroyWindowFramebuffer;
  81. device->free = DUMMY_DeleteDevice;
  82. return device;
  83. }
  84. VideoBootStrap DUMMY_bootstrap = {
  85. DUMMYVID_DRIVER_NAME, "SDL dummy video driver",
  86. DUMMY_Available, DUMMY_CreateDevice
  87. };
  88. int
  89. DUMMY_VideoInit(_THIS)
  90. {
  91. SDL_DisplayMode mode;
  92. /* Use a fake 32-bpp desktop mode */
  93. mode.format = SDL_PIXELFORMAT_RGB888;
  94. mode.w = 1024;
  95. mode.h = 768;
  96. mode.refresh_rate = 0;
  97. mode.driverdata = NULL;
  98. if (SDL_AddBasicVideoDisplay(&mode) < 0) {
  99. return -1;
  100. }
  101. SDL_zero(mode);
  102. SDL_AddDisplayMode(&_this->displays[0], &mode);
  103. /* We're done! */
  104. return 0;
  105. }
  106. static int
  107. DUMMY_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
  108. {
  109. return 0;
  110. }
  111. void
  112. DUMMY_VideoQuit(_THIS)
  113. {
  114. }
  115. #endif /* SDL_VIDEO_DRIVER_DUMMY */
  116. /* vi: set ts=4 sw=4 expandtab: */