clip-intersect.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2009 Chris Wilson
  3. * Copyright 2011 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. #define WIDTH 20
  28. #define HEIGHT 20
  29. static void clip_mask (cairo_t *cr)
  30. {
  31. cairo_move_to (cr, 10, 0);
  32. cairo_line_to (cr, 0, 10);
  33. cairo_line_to (cr, 10, 20);
  34. cairo_line_to (cr, 20, 10);
  35. cairo_clip (cr);
  36. }
  37. static cairo_test_status_t
  38. draw (cairo_t *cr, int width, int height)
  39. {
  40. cairo_set_source_rgb (cr, 1, 1, 1);
  41. cairo_paint (cr);
  42. clip_mask (cr);
  43. cairo_set_source_rgb (cr, 0, 1, 0);
  44. cairo_paint (cr);
  45. cairo_reset_clip (cr);
  46. cairo_set_source_rgb (cr, 1, 0, 0);
  47. cairo_rectangle (cr, 0, 0, 4, 4);
  48. cairo_clip (cr);
  49. clip_mask (cr);
  50. cairo_paint (cr);
  51. cairo_reset_clip (cr);
  52. cairo_rectangle (cr, 20, 0, -4, 4);
  53. cairo_clip (cr);
  54. clip_mask (cr);
  55. cairo_paint (cr);
  56. cairo_reset_clip (cr);
  57. cairo_rectangle (cr, 20, 20, -4, -4);
  58. cairo_clip (cr);
  59. clip_mask (cr);
  60. cairo_paint (cr);
  61. cairo_reset_clip (cr);
  62. cairo_rectangle (cr, 0, 20, 4, -4);
  63. cairo_clip (cr);
  64. clip_mask (cr);
  65. cairo_paint (cr);
  66. cairo_reset_clip (cr);
  67. cairo_set_source_rgb (cr, 0, 0, 1);
  68. cairo_rectangle (cr, 8, 8, 4, 4);
  69. cairo_clip (cr);
  70. clip_mask (cr);
  71. cairo_paint (cr);
  72. cairo_reset_clip (cr);
  73. return CAIRO_TEST_SUCCESS;
  74. }
  75. CAIRO_TEST (clip_intersect,
  76. "Tests intersection of a simple clip with a clip-mask",
  77. "clip, paint", /* keywords */
  78. NULL, /* requirements */
  79. WIDTH, HEIGHT,
  80. NULL, draw)