pattern_create_radial.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright © 2006 Dan Amelang
  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. * the authors not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. The authors make 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. * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL THE AUTHORS 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. * Authors: Dan Amelang <dan@amelang.net>
  24. *
  25. * This test was originally created to test _cairo_fixed_from_double.
  26. * cairo_pattern_create_radial was selected as the entry point into
  27. * cairo as it makes several calls to _cairo_fixed_from_double and
  28. * presents a somewhat realistic use-case (although the RADIALS_COUNT
  29. * isn't very realistic).
  30. */
  31. #include "cairo-perf.h"
  32. #include <time.h>
  33. #define RADIALS_COUNT (10000)
  34. static struct
  35. {
  36. double cx0;
  37. double cy0;
  38. double radius0;
  39. double cx1;
  40. double cy1;
  41. double radius1;
  42. } radials[RADIALS_COUNT];
  43. static double
  44. generate_double_in_range (double min, double max)
  45. {
  46. double d;
  47. d = rand () / (double) RAND_MAX;
  48. d *= max - min;
  49. d += min;
  50. return d;
  51. }
  52. static cairo_time_t
  53. do_pattern_create_radial (cairo_t *cr, int width, int height, int loops)
  54. {
  55. cairo_perf_timer_start ();
  56. while (loops--) {
  57. cairo_pattern_t *pattern;
  58. int i;
  59. for (i = 0; i < RADIALS_COUNT; i++) {
  60. pattern =
  61. cairo_pattern_create_radial (radials[i].cx0, radials[i].cy0,
  62. radials[i].radius0,
  63. radials[i].cx1, radials[i].cy1,
  64. radials[i].radius1);
  65. cairo_pattern_destroy (pattern);
  66. }
  67. }
  68. cairo_perf_timer_stop ();
  69. return cairo_perf_timer_elapsed ();
  70. }
  71. cairo_bool_t
  72. pattern_create_radial_enabled (cairo_perf_t *perf)
  73. {
  74. return cairo_perf_can_run (perf, "pattern-create-radial", NULL);
  75. }
  76. void
  77. pattern_create_radial (cairo_perf_t *perf, cairo_t *cr, int width, int height)
  78. {
  79. int i;
  80. srand (time (0));
  81. for (i = 0; i < RADIALS_COUNT; i++)
  82. {
  83. radials[i].cx0 = generate_double_in_range (-50000.0, 50000.0);
  84. radials[i].cy0 = generate_double_in_range (-50000.0, 50000.0);
  85. radials[i].radius0 = generate_double_in_range (0.0, 1000.0);
  86. radials[i].cx1 = generate_double_in_range (-50000.0, 50000.0);
  87. radials[i].cy1 = generate_double_in_range (-50000.0, 50000.0);
  88. radials[i].radius1 = generate_double_in_range (0.0, 1000.0);
  89. }
  90. cairo_perf_run (perf, "pattern-create-radial",
  91. do_pattern_create_radial, NULL);
  92. }