pixel.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Copyright © 2011 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. /* Measure the overhead in setting a single pixel */
  27. #include "cairo-perf.h"
  28. #include <pixman.h>
  29. static cairo_time_t
  30. pixel_direct (cairo_t *cr, int width, int height, int loops)
  31. {
  32. cairo_surface_t *surface, *image;
  33. uint32_t *data;
  34. int stride, bpp;
  35. surface = cairo_get_target (cr);
  36. image = cairo_surface_map_to_image (surface, NULL);
  37. data = (uint32_t *) cairo_image_surface_get_data (image);
  38. stride = cairo_image_surface_get_stride (image) / sizeof (uint32_t);
  39. switch (cairo_image_surface_get_format (image)) {
  40. default:
  41. case CAIRO_FORMAT_INVALID:
  42. case CAIRO_FORMAT_A1: bpp = 0; break;
  43. case CAIRO_FORMAT_A8: bpp = 8; break;
  44. case CAIRO_FORMAT_RGB16_565: bpp = 16; break;
  45. case CAIRO_FORMAT_RGB24:
  46. case CAIRO_FORMAT_RGB30:
  47. case CAIRO_FORMAT_ARGB32: bpp = 32; break;
  48. }
  49. cairo_perf_timer_start ();
  50. while (loops--)
  51. pixman_fill (data, stride, bpp, 0, 0, 1, 1, -1);
  52. cairo_perf_timer_stop ();
  53. cairo_surface_unmap_image (surface, image);
  54. return cairo_perf_timer_elapsed ();
  55. }
  56. static cairo_time_t
  57. pixel_paint (cairo_t *cr, int width, int height, int loops)
  58. {
  59. cairo_perf_timer_start ();
  60. while (loops--)
  61. cairo_paint (cr);
  62. cairo_perf_timer_stop ();
  63. return cairo_perf_timer_elapsed ();
  64. }
  65. static cairo_time_t
  66. pixel_mask (cairo_t *cr, int width, int height, int loops)
  67. {
  68. cairo_surface_t *mask;
  69. cairo_t *cr2;
  70. mask = cairo_surface_create_similar (cairo_get_target (cr),
  71. CAIRO_CONTENT_ALPHA,
  72. 1, 1);
  73. cr2 = cairo_create (mask);
  74. cairo_set_source_rgb (cr2, 1,1,1);
  75. cairo_paint (cr2);
  76. cairo_destroy (cr2);
  77. cairo_perf_timer_start ();
  78. while (loops--)
  79. cairo_mask_surface (cr, mask, 0, 0);
  80. cairo_perf_timer_stop ();
  81. cairo_surface_destroy (mask);
  82. return cairo_perf_timer_elapsed ();
  83. }
  84. static cairo_time_t
  85. pixel_rectangle (cairo_t *cr, int width, int height, int loops)
  86. {
  87. cairo_new_path (cr);
  88. cairo_rectangle (cr, 0, 0, 1, 1);
  89. cairo_perf_timer_start ();
  90. while (loops--)
  91. cairo_fill_preserve (cr);
  92. cairo_perf_timer_stop ();
  93. cairo_new_path (cr);
  94. return cairo_perf_timer_elapsed ();
  95. }
  96. static cairo_time_t
  97. pixel_subrectangle (cairo_t *cr, int width, int height, int loops)
  98. {
  99. cairo_new_path (cr);
  100. cairo_rectangle (cr, 0.1, 0.1, .8, .8);
  101. cairo_perf_timer_start ();
  102. while (loops--)
  103. cairo_fill_preserve (cr);
  104. cairo_perf_timer_stop ();
  105. cairo_new_path (cr);
  106. return cairo_perf_timer_elapsed ();
  107. }
  108. static cairo_time_t
  109. pixel_triangle (cairo_t *cr, int width, int height, int loops)
  110. {
  111. cairo_new_path (cr);
  112. cairo_move_to (cr, 0, 0);
  113. cairo_line_to (cr, 1, 1);
  114. cairo_line_to (cr, 0, 1);
  115. cairo_perf_timer_start ();
  116. while (loops--)
  117. cairo_fill_preserve (cr);
  118. cairo_perf_timer_stop ();
  119. cairo_new_path (cr);
  120. return cairo_perf_timer_elapsed ();
  121. }
  122. static cairo_time_t
  123. pixel_circle (cairo_t *cr, int width, int height, int loops)
  124. {
  125. cairo_new_path (cr);
  126. cairo_arc (cr, 0.5, 0.5, 0.5, 0, 2 * M_PI);
  127. cairo_perf_timer_start ();
  128. while (loops--)
  129. cairo_fill_preserve (cr);
  130. cairo_perf_timer_stop ();
  131. cairo_new_path (cr);
  132. return cairo_perf_timer_elapsed ();
  133. }
  134. static cairo_time_t
  135. pixel_stroke (cairo_t *cr, int width, int height, int loops)
  136. {
  137. cairo_set_line_width (cr, 1.);
  138. cairo_new_path (cr);
  139. cairo_move_to (cr, 0, 0.5);
  140. cairo_line_to (cr, 1, 0.5);
  141. cairo_perf_timer_start ();
  142. while (loops--)
  143. cairo_stroke_preserve (cr);
  144. cairo_perf_timer_stop ();
  145. cairo_new_path (cr);
  146. return cairo_perf_timer_elapsed ();
  147. }
  148. cairo_bool_t
  149. pixel_enabled (cairo_perf_t *perf)
  150. {
  151. return cairo_perf_can_run (perf, "pixel", NULL);
  152. }
  153. void
  154. pixel (cairo_perf_t *perf, cairo_t *cr, int width, int height)
  155. {
  156. cairo_set_source_rgb (cr, 1., 1., 1.);
  157. cairo_perf_run (perf, "pixel-direct", pixel_direct, NULL);
  158. cairo_perf_run (perf, "pixel-paint", pixel_paint, NULL);
  159. cairo_perf_run (perf, "pixel-mask", pixel_mask, NULL);
  160. cairo_perf_run (perf, "pixel-rectangle", pixel_rectangle, NULL);
  161. cairo_perf_run (perf, "pixel-subrectangle", pixel_subrectangle, NULL);
  162. cairo_perf_run (perf, "pixel-triangle", pixel_triangle, NULL);
  163. cairo_perf_run (perf, "pixel-circle", pixel_circle, NULL);
  164. cairo_perf_run (perf, "pixel-stroke", pixel_stroke, NULL);
  165. }
  166. cairo_bool_t
  167. a1_pixel_enabled (cairo_perf_t *perf)
  168. {
  169. return cairo_perf_can_run (perf, "a1-pixel", NULL);
  170. }
  171. void
  172. a1_pixel (cairo_perf_t *perf, cairo_t *cr, int width, int height)
  173. {
  174. cairo_set_source_rgb (cr, 1., 1., 1.);
  175. cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
  176. cairo_perf_run (perf, "a1-pixel-direct", pixel_direct, NULL);
  177. cairo_perf_run (perf, "a1-pixel-paint", pixel_paint, NULL);
  178. cairo_perf_run (perf, "a1-pixel-mask", pixel_mask, NULL);
  179. cairo_perf_run (perf, "a1-pixel-rectangle", pixel_rectangle, NULL);
  180. cairo_perf_run (perf, "a1-pixel-subrectangle", pixel_subrectangle, NULL);
  181. cairo_perf_run (perf, "a1-pixel-triangle", pixel_triangle, NULL);
  182. cairo_perf_run (perf, "a1-pixel-circle", pixel_circle, NULL);
  183. cairo_perf_run (perf, "a1-pixel-stroke", pixel_stroke, NULL);
  184. }