Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

apple_glx.c 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Copyright (c) 2008, 2009 Apple Inc.
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation files
  5. (the "Software"), to deal in the Software without restriction,
  6. including without limitation the rights to use, copy, modify, merge,
  7. publish, distribute, sublicense, and/or sell copies of the Software,
  8. and to permit persons to whom the Software is furnished to do so,
  9. subject to the following conditions:
  10. The above copyright notice and this permission notice shall be
  11. included in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
  16. HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  17. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. DEALINGS IN THE SOFTWARE.
  20. Except as contained in this notice, the name(s) of the above
  21. copyright holders shall not be used in advertising or otherwise to
  22. promote the sale, use or other dealings in this Software without
  23. prior written authorization.
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <assert.h>
  29. #include <stdarg.h>
  30. #include <dlfcn.h>
  31. #include "appledri.h"
  32. #include "apple_glx.h"
  33. #include "apple_glx_context.h"
  34. #include "apple_cgl.h"
  35. static bool initialized = false;
  36. static int dri_event_base = 0;
  37. const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
  38. static bool diagnostic = false;
  39. void
  40. apple_glx_diagnostic(const char *fmt, ...)
  41. {
  42. va_list vl;
  43. if (diagnostic) {
  44. fprintf(stderr, "DIAG: ");
  45. va_start(vl, fmt);
  46. vfprintf(stderr, fmt, vl);
  47. va_end(vl);
  48. }
  49. }
  50. int
  51. apple_get_dri_event_base(void)
  52. {
  53. if (!initialized) {
  54. fprintf(stderr,
  55. "error: dri_event_base called before apple_init_glx!\n");
  56. abort();
  57. }
  58. return dri_event_base;
  59. }
  60. static void
  61. surface_notify_handler(Display * dpy, unsigned int uid, int kind)
  62. {
  63. switch (kind) {
  64. case AppleDRISurfaceNotifyDestroyed:
  65. apple_glx_diagnostic("%s: surface destroyed %u\n", __func__, uid);
  66. apple_glx_surface_destroy(uid);
  67. break;
  68. case AppleDRISurfaceNotifyChanged:{
  69. int updated;
  70. updated = apple_glx_context_surface_changed(uid, pthread_self());
  71. apple_glx_diagnostic("surface notify updated %d\n", updated);
  72. }
  73. break;
  74. default:
  75. fprintf(stderr, "unhandled kind of event: %d in %s\n", kind, __func__);
  76. }
  77. }
  78. xp_client_id
  79. apple_glx_get_client_id(void)
  80. {
  81. static xp_client_id id;
  82. if (0 == id) {
  83. if ((XP_Success != xp_init(XP_IN_BACKGROUND)) ||
  84. (Success != xp_get_client_id(&id))) {
  85. return 0;
  86. }
  87. }
  88. return id;
  89. }
  90. /* Return true if an error occured. */
  91. bool
  92. apple_init_glx(Display * dpy)
  93. {
  94. int eventBase, errorBase;
  95. int major, minor, patch;
  96. if (!XAppleDRIQueryExtension(dpy, &eventBase, &errorBase))
  97. return true;
  98. if (!XAppleDRIQueryVersion(dpy, &major, &minor, &patch))
  99. return true;
  100. if (initialized)
  101. return false;
  102. if (getenv("LIBGL_DIAGNOSTIC")) {
  103. printf("initializing libGL in %s\n", __func__);
  104. diagnostic = true;
  105. }
  106. apple_cgl_init();
  107. (void) apple_glx_get_client_id();
  108. XAppleDRISetSurfaceNotifyHandler(surface_notify_handler);
  109. /* This should really be per display. */
  110. dri_event_base = eventBase;
  111. initialized = true;
  112. return false;
  113. }
  114. void
  115. apple_glx_swap_buffers(void *ptr)
  116. {
  117. struct apple_glx_context *ac = ptr;
  118. /* This may not be needed with CGLFlushDrawable: */
  119. glFlush();
  120. apple_cgl.flush_drawable(ac->context_obj);
  121. }
  122. void
  123. apple_glx_waitx(Display * dpy, void *ptr)
  124. {
  125. struct apple_private_context *ac = ptr;
  126. (void) ac;
  127. glFlush();
  128. glFinish();
  129. XSync(dpy, False);
  130. }