half-coverage.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright 2010 Intel Corporation
  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: Chris Wilson <chris@chris-wilson.co.uk>
  25. */
  26. #include "cairo-test.h"
  27. /* Test the fidelity of the rasterisation, because Cairo is my favourite
  28. * driver test suite.
  29. */
  30. #define SIZE 256
  31. #define WIDTH 2
  32. #define HEIGHT 10
  33. static cairo_test_status_t
  34. rectangles (cairo_t *cr, int width, int height)
  35. {
  36. int i;
  37. cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
  38. cairo_paint (cr);
  39. cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
  40. for (i = 1; i <= SIZE; i++) {
  41. int x, y;
  42. cairo_save (cr);
  43. cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
  44. cairo_clip (cr);
  45. cairo_scale (cr, 1./SIZE, 1./SIZE);
  46. for (x = -i; x < SIZE*WIDTH; x += 2*i) {
  47. for (y = -i; y < SIZE*HEIGHT; y += 2*i) {
  48. /* Add a little tile composed of two non-overlapping squares
  49. * +--+
  50. * | |
  51. * |__|__
  52. * | |
  53. * | |
  54. * +--+
  55. */
  56. cairo_rectangle (cr, x, y, i, i);
  57. cairo_rectangle (cr, x+i, y+i, i, i);
  58. }
  59. }
  60. cairo_fill (cr);
  61. cairo_restore (cr);
  62. cairo_translate (cr, WIDTH, 0);
  63. }
  64. return CAIRO_TEST_SUCCESS;
  65. }
  66. static cairo_test_status_t
  67. triangles (cairo_t *cr, int width, int height)
  68. {
  69. int i;
  70. cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
  71. cairo_paint (cr);
  72. cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
  73. for (i = 1; i <= SIZE; i++) {
  74. int x, y;
  75. cairo_save (cr);
  76. cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
  77. cairo_clip (cr);
  78. cairo_scale (cr, 1./SIZE, 1./SIZE);
  79. for (x = -i; x < SIZE*WIDTH; x += 2*i) {
  80. for (y = -i; y < SIZE*HEIGHT; y += 2*i) {
  81. /* Add a tile composed of four non-overlapping
  82. * triangles. The plus and minus signs inside the
  83. * triangles denote the orientation of the triangle's
  84. * edges: + for clockwise and - for anticlockwise.
  85. *
  86. * +-----+
  87. * \-|+/
  88. * \|/
  89. * /|\
  90. * /-|-\
  91. * +-----+
  92. */
  93. /* top left triangle */
  94. cairo_move_to (cr, x, y);
  95. cairo_line_to (cr, x+i, y+i);
  96. cairo_line_to (cr, x+i, y);
  97. cairo_close_path (cr);
  98. /* top right triangle */
  99. cairo_move_to (cr, x+i, y);
  100. cairo_line_to (cr, x+2*i, y);
  101. cairo_line_to (cr, x+i, y+i);
  102. cairo_close_path (cr);
  103. /* bottom left triangle */
  104. cairo_move_to (cr, x+i, y+i);
  105. cairo_line_to (cr, x, y+2*i);
  106. cairo_line_to (cr, x+i, y+2*i);
  107. cairo_close_path (cr);
  108. /* bottom right triangle */
  109. cairo_move_to (cr, x+i, y+i);
  110. cairo_line_to (cr, x+i, y+2*i);
  111. cairo_line_to (cr, x+2*i, y+2*i);
  112. cairo_close_path (cr);
  113. }
  114. }
  115. cairo_fill (cr);
  116. cairo_restore (cr);
  117. cairo_translate (cr, WIDTH, 0);
  118. }
  119. return CAIRO_TEST_SUCCESS;
  120. }
  121. CAIRO_TEST (half_coverage_rectangles,
  122. "Check the fidelity of the rasterisation.",
  123. NULL, /* keywords */
  124. "target=raster slow", /* requirements */
  125. WIDTH * SIZE, HEIGHT,
  126. NULL, rectangles)
  127. CAIRO_TEST (half_coverage_triangles,
  128. "Check the fidelity of the rasterisation.",
  129. NULL, /* keywords */
  130. "target=raster slow", /* requirements */
  131. WIDTH * SIZE, HEIGHT,
  132. NULL, triangles)