gl-surface-source.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright © 2008 Chris Wilson
  3. * Copyright © 2010 Intel Corporation
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software
  6. * and its documentation for any purpose is hereby granted without
  7. * fee, provided that the above copyright notice appear in all copies
  8. * and that both that copyright notice and this permission notice
  9. * appear in supporting documentation, and that the name of
  10. * Chris Wilson not be used in advertising or publicity pertaining to
  11. * distribution of the software without specific, written prior
  12. * permission. Chris Wilson makes no representations about the
  13. * suitability of this software for any purpose. It is provided "as
  14. * is" without express or implied warranty.
  15. *
  16. * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  17. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
  19. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  20. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  21. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  22. * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23. *
  24. * Author: Chris Wilson <chris@chris-wilson.co.uk>
  25. */
  26. #include "cairo-test.h"
  27. #include <cairo-gl.h>
  28. #include "surface-source.c"
  29. struct closure {
  30. Display *dpy;
  31. GLXContext ctx;
  32. };
  33. static void
  34. cleanup (void *data)
  35. {
  36. struct closure *arg = data;
  37. glXDestroyContext (arg->dpy, arg->ctx);
  38. XCloseDisplay (arg->dpy);
  39. free (arg);
  40. }
  41. static cairo_surface_t *
  42. create_source_surface (int size)
  43. {
  44. int rgba_attribs[] = {
  45. GLX_RGBA,
  46. GLX_RED_SIZE, 1,
  47. GLX_GREEN_SIZE, 1,
  48. GLX_BLUE_SIZE, 1,
  49. GLX_ALPHA_SIZE, 1,
  50. GLX_DOUBLEBUFFER,
  51. None
  52. };
  53. XVisualInfo *visinfo;
  54. GLXContext ctx;
  55. struct closure *arg;
  56. cairo_device_t *device;
  57. cairo_surface_t *surface;
  58. Display *dpy;
  59. dpy = XOpenDisplay (NULL);
  60. if (dpy == NULL)
  61. return NULL;
  62. visinfo = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs);
  63. if (visinfo == NULL) {
  64. XCloseDisplay (dpy);
  65. return NULL;
  66. }
  67. ctx = glXCreateContext (dpy, visinfo, NULL, True);
  68. XFree (visinfo);
  69. if (ctx == NULL) {
  70. XCloseDisplay (dpy);
  71. return NULL;
  72. }
  73. arg = xmalloc (sizeof (struct closure));
  74. arg->dpy = dpy;
  75. arg->ctx = ctx;
  76. device = cairo_glx_device_create (dpy, ctx);
  77. if (cairo_device_set_user_data (device,
  78. (cairo_user_data_key_t *) cleanup,
  79. arg,
  80. cleanup))
  81. {
  82. cleanup (arg);
  83. return NULL;
  84. }
  85. surface = cairo_gl_surface_create (device,
  86. CAIRO_CONTENT_COLOR_ALPHA,
  87. size, size);
  88. cairo_device_destroy (device);
  89. return surface;
  90. }
  91. CAIRO_TEST (gl_surface_source,
  92. "Test using a GL surface as the source",
  93. "source", /* keywords */
  94. NULL, /* requirements */
  95. SIZE, SIZE,
  96. preamble, draw)