1
0

SDL_androidgl.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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 defined(SDL_VIDEO_DRIVER_ANDROID) && defined(SDL_VIDEO_OPENGL_EGL)
  20. // Android SDL video driver implementation
  21. #include "../SDL_egl_c.h"
  22. #include "SDL_androidwindow.h"
  23. #include "SDL_androidvideo.h"
  24. #include "SDL_androidevents.h"
  25. #include "SDL_androidgl.h"
  26. #include "../../core/android/SDL_android.h"
  27. #include <android/log.h>
  28. #include <dlfcn.h>
  29. bool Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
  30. {
  31. if (window && context) {
  32. return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context);
  33. } else {
  34. return SDL_EGL_MakeCurrent(_this, NULL, NULL);
  35. }
  36. }
  37. SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
  38. {
  39. SDL_GLContext result;
  40. if (!Android_WaitActiveAndLockActivity()) {
  41. return NULL;
  42. }
  43. result = SDL_EGL_CreateContext(_this, window->internal->egl_surface);
  44. Android_UnlockActivityMutex();
  45. return result;
  46. }
  47. bool Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
  48. {
  49. bool result;
  50. Android_LockActivityMutex();
  51. /* The following two calls existed in the original Java code
  52. * If you happen to have a device that's affected by their removal,
  53. * please report to our bug tracker. -- Gabriel
  54. */
  55. /*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
  56. _this->egl_data->eglWaitGL();*/
  57. result = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface);
  58. Android_UnlockActivityMutex();
  59. return result;
  60. }
  61. bool Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
  62. {
  63. return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0);
  64. }
  65. #endif // SDL_VIDEO_DRIVER_ANDROID