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