surface-pattern-big-scale-down.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright © 2006 Mozilla Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software
  5. * and its documentation for any purpose is hereby granted without
  6. * fee, provided that the above copyright notice appear in all copies
  7. * and that both that copyright notice and this permission notice
  8. * appear in supporting documentation, and that the name of
  9. * Mozilla Corporation not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Mozilla Corporation makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as
  13. * is" without express or implied warranty.
  14. *
  15. * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
  18. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21. * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Author: Vladimir Vukicevic <vladimir@pobox.com>
  24. */
  25. #include "cairo-test.h"
  26. #define SRC_WIDTH 2048
  27. #define SRC_HEIGHT 32
  28. static cairo_surface_t *
  29. create_source_surface (int w, int h)
  30. {
  31. cairo_surface_t *surface;
  32. cairo_t *cr;
  33. surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SRC_WIDTH, SRC_HEIGHT);
  34. cr = cairo_create (surface);
  35. cairo_surface_destroy (surface);
  36. cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
  37. cairo_rectangle (cr, 0, 0, w/2, h/2);
  38. cairo_fill (cr);
  39. cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
  40. cairo_rectangle (cr, w/2, 0, w/2, h/2);
  41. cairo_fill (cr);
  42. cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
  43. cairo_rectangle (cr, 0, h/2, w/2, h/2);
  44. cairo_fill (cr);
  45. cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
  46. cairo_rectangle (cr, w/2, h/2, w/2, h/2);
  47. cairo_fill (cr);
  48. surface = cairo_surface_reference (cairo_get_target (cr));
  49. cairo_destroy (cr);
  50. return surface;
  51. }
  52. static void
  53. draw_n (cairo_t *cr, cairo_pattern_t *pat, double dest_size, int n)
  54. {
  55. cairo_matrix_t mat;
  56. cairo_matrix_init_scale (&mat, SRC_WIDTH / dest_size, SRC_HEIGHT / dest_size);
  57. cairo_matrix_translate (&mat, n * -dest_size, 0.0);
  58. cairo_pattern_set_matrix (pat, &mat);
  59. cairo_set_source (cr, pat);
  60. cairo_new_path (cr);
  61. cairo_rectangle (cr, n * dest_size, 0.0, dest_size, dest_size);
  62. cairo_fill (cr);
  63. }
  64. static cairo_test_status_t
  65. draw (cairo_t *cr, int width, int height)
  66. {
  67. cairo_surface_t *surface;
  68. cairo_pattern_t *pat;
  69. cairo_set_source_rgb (cr, 0, 0, 0);
  70. cairo_paint (cr);
  71. surface = create_source_surface (SRC_WIDTH, SRC_HEIGHT);
  72. pat = cairo_pattern_create_for_surface (surface);
  73. cairo_surface_destroy (surface);
  74. /* We want to draw at a position such that n * SRC_WIDTH * (SRC_WIDTH/16.0) > 32768.
  75. * x = n * 16.
  76. *
  77. * To show the bug, we want to draw on either side of the boundary;
  78. * in our case here, n = 16 results in 32768, and n = 17 results in > 32768.
  79. *
  80. * Drawing at 16 and 17 is sufficient to show the problem.
  81. */
  82. #if 1
  83. /* n = 16 */
  84. draw_n (cr, pat, 16.0, 16);
  85. /* n = 17 */
  86. draw_n (cr, pat, 16.0, 17);
  87. #else
  88. {
  89. int n;
  90. for (n = 0; n < 32; n++)
  91. draw_n (cr, pat, 16.0, n);
  92. }
  93. #endif
  94. cairo_pattern_destroy (pat);
  95. return CAIRO_TEST_SUCCESS;
  96. }
  97. CAIRO_TEST (surface_pattern_big_scale_down,
  98. "Test scaled-down transformed not-repeated surface patterns with large images and offsets",
  99. "transform", /* keywords */
  100. NULL, /* requirements */
  101. 512, 16,
  102. NULL, draw)