SDL_uikitvideo.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_UIKIT
  20. #import <UIKit/UIKit.h>
  21. #include "SDL_video.h"
  22. #include "SDL_mouse.h"
  23. #include "../SDL_sysvideo.h"
  24. #include "../SDL_pixels_c.h"
  25. #include "../../events/SDL_events_c.h"
  26. #include "SDL_uikitvideo.h"
  27. #include "SDL_uikitevents.h"
  28. #include "SDL_uikitmodes.h"
  29. #include "SDL_uikitwindow.h"
  30. #include "SDL_uikitopengles.h"
  31. #define UIKITVID_DRIVER_NAME "uikit"
  32. /* Initialization/Query functions */
  33. static int UIKit_VideoInit(_THIS);
  34. static void UIKit_VideoQuit(_THIS);
  35. /* DUMMY driver bootstrap functions */
  36. static int
  37. UIKit_Available(void)
  38. {
  39. return 1;
  40. }
  41. static void UIKit_DeleteDevice(SDL_VideoDevice * device)
  42. {
  43. SDL_free(device);
  44. }
  45. static SDL_VideoDevice *
  46. UIKit_CreateDevice(int devindex)
  47. {
  48. SDL_VideoDevice *device;
  49. /* Initialize all variables that we clean on shutdown */
  50. device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
  51. if (!device) {
  52. SDL_free(device);
  53. SDL_OutOfMemory();
  54. return (0);
  55. }
  56. /* Set the function pointers */
  57. device->VideoInit = UIKit_VideoInit;
  58. device->VideoQuit = UIKit_VideoQuit;
  59. device->GetDisplayModes = UIKit_GetDisplayModes;
  60. device->SetDisplayMode = UIKit_SetDisplayMode;
  61. device->PumpEvents = UIKit_PumpEvents;
  62. device->CreateWindow = UIKit_CreateWindow;
  63. device->ShowWindow = UIKit_ShowWindow;
  64. device->HideWindow = UIKit_HideWindow;
  65. device->RaiseWindow = UIKit_RaiseWindow;
  66. device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
  67. device->DestroyWindow = UIKit_DestroyWindow;
  68. device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
  69. /* !!! FIXME: implement SetWindowBordered */
  70. #if SDL_IPHONE_KEYBOARD
  71. device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
  72. device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
  73. device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
  74. device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
  75. device->SetTextInputRect = UIKit_SetTextInputRect;
  76. #endif
  77. /* OpenGL (ES) functions */
  78. device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
  79. device->GL_SwapWindow = UIKit_GL_SwapWindow;
  80. device->GL_CreateContext = UIKit_GL_CreateContext;
  81. device->GL_DeleteContext = UIKit_GL_DeleteContext;
  82. device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
  83. device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
  84. device->free = UIKit_DeleteDevice;
  85. device->gl_config.accelerated = 1;
  86. return device;
  87. }
  88. VideoBootStrap UIKIT_bootstrap = {
  89. UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
  90. UIKit_Available, UIKit_CreateDevice
  91. };
  92. int
  93. UIKit_VideoInit(_THIS)
  94. {
  95. _this->gl_config.driver_loaded = 1;
  96. if (UIKit_InitModes(_this) < 0) {
  97. return -1;
  98. }
  99. return 0;
  100. }
  101. void
  102. UIKit_VideoQuit(_THIS)
  103. {
  104. UIKit_QuitModes(_this);
  105. }
  106. /*
  107. * iOS log support.
  108. *
  109. * This doesn't really have aything to do with the interfaces of the SDL video
  110. * subsystem, but we need to stuff this into an Objective-C source code file.
  111. */
  112. void SDL_NSLog(const char *text)
  113. {
  114. NSLog(@"%s", text);
  115. }
  116. #endif /* SDL_VIDEO_DRIVER_UIKIT */
  117. /* vi: set ts=4 sw=4 expandtab: */