Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

msctest.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright © 2009 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Jesse Barnes <jesse.barnes@intel.com>
  25. *
  26. */
  27. /** @file msctest.c
  28. * Simple test for MSC functionality.
  29. */
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <unistd.h>
  34. #include <GL/gl.h>
  35. #include <GL/glu.h>
  36. #include <GL/glx.h>
  37. #include <GL/glxext.h>
  38. #include <X11/X.h>
  39. #include <X11/Xlib.h>
  40. #include <X11/Xutil.h>
  41. void (*get_sync_values)(Display *dpy, Window winGL, int64_t *ust, int64_t *msc, int64_t *sbc);
  42. void (*wait_sync)(Display *dpy, Window winGL, int64_t target_msc, int64_t divisor, int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc);
  43. static int GLXExtensionSupported(Display *dpy, const char *extension)
  44. {
  45. const char *extensionsString, *client_extensions, *pos;
  46. extensionsString = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
  47. client_extensions = glXGetClientString(dpy, GLX_EXTENSIONS);
  48. pos = strstr(extensionsString, extension);
  49. if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
  50. (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
  51. return 1;
  52. pos = strstr(client_extensions, extension);
  53. if (pos != NULL && (pos == extensionsString || pos[-1] == ' ') &&
  54. (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'))
  55. return 1;
  56. return 0;
  57. }
  58. extern char *optarg;
  59. extern int optind, opterr, optopt;
  60. static char optstr[] = "v";
  61. static void usage(char *name)
  62. {
  63. printf("usage: %s\n", name);
  64. exit(-1);
  65. }
  66. int main(int argc, char *argv[])
  67. {
  68. Display *disp;
  69. XVisualInfo *pvi;
  70. XSetWindowAttributes swa;
  71. int attrib[14];
  72. Window winGL;
  73. GLXContext context;
  74. int dummy;
  75. Atom wmDelete;
  76. int verbose = 0, width = 200, height = 200;
  77. int c, i = 1;
  78. int64_t ust, msc, sbc;
  79. opterr = 0;
  80. while ((c = getopt(argc, argv, optstr)) != -1) {
  81. switch (c) {
  82. case 'v':
  83. verbose = 1;
  84. break;
  85. default:
  86. usage(argv[0]);
  87. break;
  88. }
  89. }
  90. disp = XOpenDisplay(NULL);
  91. if (!disp) {
  92. fprintf(stderr, "failed to open display\n");
  93. return -1;
  94. }
  95. if (!glXQueryExtension(disp, &dummy, &dummy)) {
  96. fprintf(stderr, "glXQueryExtension failed\n");
  97. return -1;
  98. }
  99. if (!GLXExtensionSupported(disp, "GLX_OML_sync_control")) {
  100. fprintf(stderr, "GLX_OML_sync_control not supported, exiting\n");
  101. return -1;
  102. }
  103. attrib[0] = GLX_RGBA;
  104. attrib[1] = 1;
  105. attrib[2] = GLX_RED_SIZE;
  106. attrib[3] = 1;
  107. attrib[4] = GLX_GREEN_SIZE;
  108. attrib[5] = 1;
  109. attrib[6] = GLX_BLUE_SIZE;
  110. attrib[7] = 1;
  111. attrib[8] = GLX_DOUBLEBUFFER;
  112. attrib[9] = 1;
  113. attrib[10] = None;
  114. pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib);
  115. if (!pvi) {
  116. fprintf(stderr, "failed to choose visual, exiting\n");
  117. return -1;
  118. }
  119. context = glXCreateContext(disp, pvi, None, GL_TRUE);
  120. if (!context) {
  121. fprintf(stderr, "failed to create glx context\n");
  122. return -1;
  123. }
  124. pvi->screen = DefaultScreen(disp);
  125. swa.colormap = XCreateColormap(disp, RootWindow(disp, pvi->screen),
  126. pvi->visual, AllocNone);
  127. swa.border_pixel = 0;
  128. swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
  129. StructureNotifyMask;
  130. winGL = XCreateWindow(disp, RootWindow(disp, pvi->screen),
  131. 0, 0,
  132. width, height,
  133. 0, pvi->depth, InputOutput, pvi->visual,
  134. CWBorderPixel | CWColormap | CWEventMask, &swa);
  135. if (!winGL) {
  136. fprintf(stderr, "window creation failed\n");
  137. return -1;
  138. }
  139. wmDelete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
  140. XSetWMProtocols(disp, winGL, &wmDelete, 1);
  141. XSetStandardProperties(disp, winGL, "msc test", "msc text",
  142. None, NULL, 0, NULL);
  143. XMapRaised(disp, winGL);
  144. glXMakeCurrent(disp, winGL, context);
  145. get_sync_values = glXGetProcAddress((unsigned char *)"glXGetSyncValuesOML");
  146. wait_sync = glXGetProcAddress((unsigned char *)"glXWaitForMscOML");
  147. if (!get_sync_values || !wait_sync) {
  148. fprintf(stderr, "failed to get sync values function\n");
  149. return -1;
  150. }
  151. while (i++) {
  152. get_sync_values(disp, winGL, &ust, &msc, &sbc);
  153. fprintf(stderr, "ust: %llu, msc: %llu, sbc: %llu\n", ust, msc,
  154. sbc);
  155. /* Alternate colors to make tearing obvious */
  156. if (i & 1)
  157. glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
  158. else
  159. glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
  160. glClear(GL_COLOR_BUFFER_BIT);
  161. glXSwapBuffers(disp, winGL);
  162. wait_sync(disp, winGL, 0, 60, 0, &ust, &msc, &sbc);
  163. fprintf(stderr,
  164. "wait returned ust: %llu, msc: %llu, sbc: %llu\n",
  165. ust, msc, sbc);
  166. sleep(1);
  167. }
  168. XDestroyWindow(disp, winGL);
  169. glXDestroyContext(disp, context);
  170. XCloseDisplay(disp);
  171. return 0;
  172. }