sample.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2012 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 GENERATE_REFERENCE 0
  31. #define WIDTH 256
  32. #define HEIGHT 40
  33. #include "../src/cairo-fixed-type-private.h"
  34. #define PRECISION (1 << CAIRO_FIXED_FRAC_BITS)
  35. static cairo_test_status_t
  36. vertical (cairo_t *cr, int width, int height)
  37. {
  38. int x;
  39. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  40. cairo_paint (cr);
  41. cairo_set_source_rgba (cr, 1, 1, 1, 1);
  42. for (x = -HEIGHT*PRECISION-2; x <= (WIDTH+HEIGHT)*PRECISION+2; x += 4) {
  43. cairo_move_to (cr, x / (double)PRECISION - 2, -2);
  44. cairo_rel_line_to (cr, 0, HEIGHT + 4);
  45. }
  46. cairo_set_line_width (cr, 2 / (double)PRECISION);
  47. cairo_stroke (cr);
  48. return CAIRO_TEST_SUCCESS;
  49. }
  50. static cairo_test_status_t
  51. horizontal (cairo_t *cr, int width, int height)
  52. {
  53. int x;
  54. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  55. cairo_paint (cr);
  56. cairo_set_source_rgba (cr, 1, 1, 1, 1);
  57. for (x = -HEIGHT*PRECISION-2; x <= (WIDTH+HEIGHT)*PRECISION+2; x += 4) {
  58. cairo_move_to (cr, -2, x / (double)PRECISION - 2);
  59. cairo_rel_line_to (cr, HEIGHT + 4, 0);
  60. }
  61. cairo_set_line_width (cr, 2 / (double)PRECISION);
  62. cairo_stroke (cr);
  63. return CAIRO_TEST_SUCCESS;
  64. }
  65. static cairo_test_status_t
  66. diagonal (cairo_t *cr, int width, int height)
  67. {
  68. int x;
  69. cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
  70. cairo_paint (cr);
  71. cairo_set_source_rgba (cr, 1, 1, 1, 1);
  72. for (x = -HEIGHT*PRECISION-2; x <= (WIDTH+HEIGHT)*PRECISION+2; x += 6) {
  73. cairo_move_to (cr, x / (double)PRECISION - 2, -2);
  74. cairo_rel_line_to (cr, HEIGHT + 4, HEIGHT + 4);
  75. }
  76. cairo_set_line_width (cr, 2 / (double)PRECISION);
  77. cairo_stroke (cr);
  78. return CAIRO_TEST_SUCCESS;
  79. }
  80. CAIRO_TEST (sample_vertical,
  81. "Check the fidelity of the rasterisation.",
  82. NULL, /* keywords */
  83. "target=raster slow", /* requirements */
  84. WIDTH, HEIGHT,
  85. NULL, vertical)
  86. CAIRO_TEST (sample_horizontal,
  87. "Check the fidelity of the rasterisation.",
  88. NULL, /* keywords */
  89. "target=raster slow", /* requirements */
  90. WIDTH, HEIGHT,
  91. NULL, horizontal)
  92. CAIRO_TEST (sample_diagonal,
  93. "Check the fidelity of the rasterisation.",
  94. NULL, /* keywords */
  95. "target=raster slow", /* requirements */
  96. WIDTH, HEIGHT,
  97. NULL, diagonal)