get-xrender-format.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright © 2008 Red Hat, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Author: Carl D. Worth <cworth@cworth.org>
  25. */
  26. #include "cairo-test.h"
  27. #include "cairo-xlib.h"
  28. #include "cairo-xlib-xrender.h"
  29. #include "cairo-boilerplate-xlib.h"
  30. static cairo_test_status_t
  31. preamble (cairo_test_context_t *ctx)
  32. {
  33. Display *dpy;
  34. XRenderPictFormat *orig_format, *format;
  35. cairo_surface_t *surface;
  36. Pixmap pixmap;
  37. int screen;
  38. cairo_test_status_t result;
  39. result = CAIRO_TEST_UNTESTED;
  40. if (! cairo_test_is_target_enabled (ctx, "xlib"))
  41. goto CLEANUP_TEST;
  42. dpy = XOpenDisplay (NULL);
  43. if (! dpy) {
  44. cairo_test_log (ctx, "Error: Cannot open display: %s, skipping.\n",
  45. XDisplayName (NULL));
  46. goto CLEANUP_TEST;
  47. }
  48. result = CAIRO_TEST_FAILURE;
  49. screen = DefaultScreen (dpy);
  50. cairo_test_log (ctx, "Testing with image surface.\n");
  51. surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
  52. format = cairo_xlib_surface_get_xrender_format (surface);
  53. if (format != NULL) {
  54. cairo_test_log (ctx, "Error: expected NULL for image surface\n");
  55. goto CLEANUP_SURFACE;
  56. }
  57. cairo_surface_destroy (surface);
  58. cairo_test_log (ctx, "Testing with non-xrender xlib surface.\n");
  59. pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
  60. 1, 1, DefaultDepth (dpy, screen));
  61. surface = cairo_xlib_surface_create (dpy, pixmap,
  62. DefaultVisual (dpy, screen),
  63. 1, 1);
  64. orig_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
  65. format = cairo_xlib_surface_get_xrender_format (surface);
  66. if (format != orig_format) {
  67. cairo_test_log (ctx, "Error: did not receive the same format as XRenderFindVisualFormat\n");
  68. goto CLEANUP_PIXMAP;
  69. }
  70. cairo_surface_destroy (surface);
  71. XFreePixmap (dpy, pixmap);
  72. cairo_test_log (ctx, "Testing with xlib xrender surface.\n");
  73. orig_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
  74. pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
  75. 1, 1, 32);
  76. surface = cairo_xlib_surface_create_with_xrender_format (dpy,
  77. pixmap,
  78. DefaultScreenOfDisplay (dpy),
  79. orig_format,
  80. 1, 1);
  81. format = cairo_xlib_surface_get_xrender_format (surface);
  82. if (format != orig_format) {
  83. cairo_test_log (ctx, "Error: did not receive the same format originally set\n");
  84. goto CLEANUP_PIXMAP;
  85. }
  86. result = CAIRO_TEST_SUCCESS;
  87. CLEANUP_PIXMAP:
  88. XFreePixmap (dpy, pixmap);
  89. CLEANUP_SURFACE:
  90. cairo_surface_destroy (surface);
  91. XCloseDisplay (dpy);
  92. CLEANUP_TEST:
  93. return result;
  94. }
  95. CAIRO_TEST (get_xrender_format,
  96. "Check XRender specific API",
  97. "xrender, api", /* keywords */
  98. NULL, /* requirements */
  99. 0, 0,
  100. preamble, NULL)