sk_canvas.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright 2014 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. // EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
  8. // DO NOT USE -- FOR INTERNAL TESTING ONLY
  9. #ifndef sk_canvas_DEFINED
  10. #define sk_canvas_DEFINED
  11. #include "include/c/sk_types.h"
  12. SK_C_PLUS_PLUS_BEGIN_GUARD
  13. /**
  14. Save the current matrix and clip on the canvas. When the
  15. balancing call to sk_canvas_restore() is made, the previous matrix
  16. and clip are restored.
  17. */
  18. SK_API void sk_canvas_save(sk_canvas_t*);
  19. /**
  20. This behaves the same as sk_canvas_save(), but in addition it
  21. allocates an offscreen surface. All drawing calls are directed
  22. there, and only when the balancing call to sk_canvas_restore() is
  23. made is that offscreen transfered to the canvas (or the previous
  24. layer).
  25. @param sk_rect_t* (may be null) This rect, if non-null, is used as
  26. a hint to limit the size of the offscreen, and
  27. thus drawing may be clipped to it, though that
  28. clipping is not guaranteed to happen. If exact
  29. clipping is desired, use sk_canvas_clip_rect().
  30. @param sk_paint_t* (may be null) The paint is copied, and is applied
  31. to the offscreen when sk_canvas_restore() is
  32. called.
  33. */
  34. SK_API void sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
  35. /**
  36. This call balances a previous call to sk_canvas_save() or
  37. sk_canvas_save_layer(), and is used to remove all modifications to
  38. the matrix and clip state since the last save call. It is an
  39. error to call sk_canvas_restore() more times than save and
  40. save_layer were called.
  41. */
  42. SK_API void sk_canvas_restore(sk_canvas_t*);
  43. /**
  44. Preconcat the current coordinate transformation matrix with the
  45. specified translation.
  46. */
  47. SK_API void sk_canvas_translate(sk_canvas_t*, float dx, float dy);
  48. /**
  49. Preconcat the current coordinate transformation matrix with the
  50. specified scale.
  51. */
  52. SK_API void sk_canvas_scale(sk_canvas_t*, float sx, float sy);
  53. /**
  54. Preconcat the current coordinate transformation matrix with the
  55. specified rotation in degrees.
  56. */
  57. SK_API void sk_canvas_rotate_degrees(sk_canvas_t*, float degrees);
  58. /**
  59. Preconcat the current coordinate transformation matrix with the
  60. specified rotation in radians.
  61. */
  62. SK_API void sk_canvas_rotate_radians(sk_canvas_t*, float radians);
  63. /**
  64. Preconcat the current coordinate transformation matrix with the
  65. specified skew.
  66. */
  67. SK_API void sk_canvas_skew(sk_canvas_t*, float sx, float sy);
  68. /**
  69. Preconcat the current coordinate transformation matrix with the
  70. specified matrix.
  71. */
  72. SK_API void sk_canvas_concat(sk_canvas_t*, const sk_matrix_t*);
  73. /**
  74. Modify the current clip with the specified rectangle. The new
  75. current clip will be the intersection of the old clip and the
  76. rectange.
  77. */
  78. SK_API void sk_canvas_clip_rect(sk_canvas_t*, const sk_rect_t*);
  79. /**
  80. Modify the current clip with the specified path. The new
  81. current clip will be the intersection of the old clip and the
  82. path.
  83. */
  84. SK_API void sk_canvas_clip_path(sk_canvas_t*, const sk_path_t*);
  85. /**
  86. Fill the entire canvas (restricted to the current clip) with the
  87. specified paint.
  88. */
  89. SK_API void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*);
  90. /**
  91. Draw the specified rectangle using the specified paint. The
  92. rectangle will be filled or stroked based on the style in the
  93. paint.
  94. */
  95. SK_API void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
  96. /**
  97. * Draw the circle centered at (cx, cy) with radius rad using the specified paint.
  98. * The circle will be filled or framed based on the style in the paint
  99. */
  100. SK_API void sk_canvas_draw_circle(sk_canvas_t*, float cx, float cy, float rad, const sk_paint_t*);
  101. /**
  102. Draw the specified oval using the specified paint. The oval will be
  103. filled or framed based on the style in the paint
  104. */
  105. SK_API void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
  106. /**
  107. Draw the specified path using the specified paint. The path will be
  108. filled or framed based on the style in the paint
  109. */
  110. SK_API void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*);
  111. /**
  112. Draw the specified image, with its top/left corner at (x,y), using
  113. the specified paint, transformed by the current matrix.
  114. @param sk_paint_t* (may be NULL) the paint used to draw the image.
  115. */
  116. SK_API void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*,
  117. float x, float y, const sk_paint_t*);
  118. /**
  119. Draw the specified image, scaling and translating so that it fills
  120. the specified dst rect. If the src rect is non-null, only that
  121. subset of the image is transformed and drawn.
  122. @param sk_paint_t* (may be NULL) The paint used to draw the image.
  123. */
  124. SK_API void sk_canvas_draw_image_rect(sk_canvas_t*, const sk_image_t*,
  125. const sk_rect_t* src,
  126. const sk_rect_t* dst, const sk_paint_t*);
  127. /**
  128. Draw the picture into this canvas (replay the pciture's drawing commands).
  129. @param sk_matrix_t* If non-null, apply that matrix to the CTM when
  130. drawing this picture. This is logically
  131. equivalent to: save, concat, draw_picture,
  132. restore.
  133. @param sk_paint_t* If non-null, draw the picture into a temporary
  134. buffer, and then apply the paint's alpha,
  135. colorfilter, imagefilter, and xfermode to that
  136. buffer as it is drawn to the canvas. This is
  137. logically equivalent to save_layer(paint),
  138. draw_picture, restore.
  139. */
  140. SK_API void sk_canvas_draw_picture(sk_canvas_t*, const sk_picture_t*,
  141. const sk_matrix_t*, const sk_paint_t*);
  142. SK_C_PLUS_PLUS_END_GUARD
  143. #endif