2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 // EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
9 // DO NOT USE -- FOR INTERNAL TESTING ONLY
11 #ifndef sk_canvas_DEFINED
12 #define sk_canvas_DEFINED
16 SK_C_PLUS_PLUS_BEGIN_GUARD
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.
23 SK_API int sk_canvas_save(sk_canvas_t*);
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
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
40 SK_API int sk_canvas_save_layer(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
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.
48 SK_API void sk_canvas_restore(sk_canvas_t*);
50 Preconcat the current coordinate transformation matrix with the
51 specified translation.
53 SK_API void sk_canvas_translate(sk_canvas_t*, float dx, float dy);
55 Preconcat the current coordinate transformation matrix with the
58 SK_API void sk_canvas_scale(sk_canvas_t*, float sx, float sy);
60 Preconcat the current coordinate transformation matrix with the
61 specified rotation in degrees.
63 SK_API void sk_canvas_rotate_degrees(sk_canvas_t*, float degrees);
65 Preconcat the current coordinate transformation matrix with the
66 specified rotation in radians.
68 SK_API void sk_canvas_rotate_radians(sk_canvas_t*, float radians);
70 Preconcat the current coordinate transformation matrix with the
73 SK_API void sk_canvas_skew(sk_canvas_t*, float sx, float sy);
75 Preconcat the current coordinate transformation matrix with the
78 SK_API void sk_canvas_concat(sk_canvas_t*, const sk_matrix_t*);
81 Modify the current clip with the specified rectangle. The new
82 current clip will be the intersection of the old clip and the
85 SK_API void sk_canvas_clip_rect(sk_canvas_t*, const sk_rect_t*);
87 Modify the current clip with the specified path. The new
88 current clip will be the intersection of the old clip and the
91 SK_API void sk_canvas_clip_path(sk_canvas_t*, const sk_path_t*);
94 Fill the entire canvas (restricted to the current clip) with the
97 SK_API void sk_canvas_draw_paint(sk_canvas_t*, const sk_paint_t*);
99 Draw the specified rectangle using the specified paint. The
100 rectangle will be filled or stroked based on the style in the
103 SK_API void sk_canvas_draw_rect(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
105 * Draw the circle centered at (cx, cy) with radius rad using the specified paint.
106 * The circle will be filled or framed based on the style in the paint
108 SK_API void sk_canvas_draw_circle(sk_canvas_t*, float cx, float cy, float rad, const sk_paint_t*);
110 Draw the specified oval using the specified paint. The oval will be
111 filled or framed based on the style in the paint
113 SK_API void sk_canvas_draw_oval(sk_canvas_t*, const sk_rect_t*, const sk_paint_t*);
115 Draw the specified path using the specified paint. The path will be
116 filled or framed based on the style in the paint
118 SK_API void sk_canvas_draw_path(sk_canvas_t*, const sk_path_t*, const sk_paint_t*);
120 Draw the specified image, with its top/left corner at (x,y), using
121 the specified paint, transformed by the current matrix.
123 @param sk_paint_t* (may be NULL) the paint used to draw the image.
125 SK_API void sk_canvas_draw_image(sk_canvas_t*, const sk_image_t*,
126 float x, float y, const sk_paint_t*);
128 Draw the specified image, scaling and translating so that it fills
129 the specified dst rect. If the src rect is non-null, only that
130 subset of the image is transformed and drawn.
132 @param sk_paint_t* (may be NULL) The paint used to draw the image.
134 SK_API void sk_canvas_draw_image_rect(sk_canvas_t*, const sk_image_t*,
135 const sk_rect_t* src,
136 const sk_rect_t* dst, const sk_paint_t*);
138 Draw the picture into this canvas (replay the pciture's drawing commands).
140 @param sk_matrix_t* If non-null, apply that matrix to the CTM when
141 drawing this picture. This is logically
142 equivalent to: save, concat, draw_picture,
145 @param sk_paint_t* If non-null, draw the picture into a temporary
146 buffer, and then apply the paint's alpha,
147 colorfilter, imagefilter, and xfermode to that
148 buffer as it is drawn to the canvas. This is
149 logically equivalent to save_layer(paint),
150 draw_picture, restore.
152 SK_API void sk_canvas_draw_picture(sk_canvas_t*, const sk_picture_t*,
153 const sk_matrix_t*, const sk_paint_t*);
155 Helper method for drawing a color in SRC mode, completely replacing all the pixels
156 in the current clip with this color.
158 SK_API void sk_canvas_clear(sk_canvas_t*, sk_color_t);
160 This makes the contents of the canvas undefined. Subsequent calls that
161 require reading the canvas contents will produce undefined results. Examples
162 include blending and readPixels. The actual implementation is backend-
163 dependent and one legal implementation is to do nothing. Like clear(), this
166 This function should only be called if the caller intends to subsequently
167 draw to the canvas. The canvas may do real work at discard() time in order
168 to optimize performance on subsequent draws. Thus, if you call this and then
169 never draw to the canvas subsequently you may pay a perfomance penalty.
171 SK_API void sk_canvas_discard(sk_canvas_t*);
173 Returns the number of matrix/clip states on the SkCanvas' private stack.
174 This will equal # save() calls - # restore() calls + 1. The save count on
177 SK_API int sk_canvas_get_save_count(sk_canvas_t*);
179 Efficient way to pop any calls to sk_canvas_save() that happened after the save
180 count reached saveCount. It is an error for saveCount to be greater than
181 getSaveCount(). To pop all the way back to the initial matrix/clip context
184 SK_API void sk_canvas_restore_to_count(sk_canvas_t*, int saveCount);
186 Draws with the specified color and mode.
188 SK_API void sk_canvas_draw_color(sk_canvas_t* ccanvas, sk_color_t color, sk_blendmode_t mode);
190 Draw a series of points, interpreted based on the sk_point_mode_t mode. For
191 all modes, the count parameter is interpreted as the total number of
192 points. For LINES_SK_POINT_MODE mode, count/2 line segments are drawn.
193 For POINTS_SK_POINT_MODE mode, each point is drawn centered at its coordinate, and its
194 size is specified by the paint's stroke-width. It draws as a square,
195 unless the paint's cap-type is round, in which the points are drawn as
197 For LINES_SK_POINT_MODE mode, each pair of points is drawn as a line segment,
198 respecting the paint's settings for cap/join/width.
199 For POLYGON_SK_POINT_MODE mode, the entire array is drawn as a series of connected
201 Note that, while similar, LINES_SK_POINT_MODE and POLYGON_SK_POINT_MODE modes draw slightly
202 differently than the equivalent path built with a series of moveto,
203 lineto calls, in that the path will draw all of its contours at once,
204 with no interactions if contours intersect each other (think XOR
205 xfermode). sk_canvas_draw_paint always draws each element one at a time.
207 SK_API void sk_canvas_draw_points(sk_canvas_t*, sk_point_mode_t, size_t, const sk_point_t[], const sk_paint_t*);
209 Draws a single point with the specified paint
211 SK_API void sk_canvas_draw_point(sk_canvas_t*, float, float, const sk_paint_t*);
213 Draws a single point with the specified paint
215 SK_API void sk_canvas_draw_point_color(sk_canvas_t*, float, float, sk_color_t);
217 Draws a line from x0,y0 to x1,y1
219 SK_API void sk_canvas_draw_line(sk_canvas_t* ccanvas, float x0, float y0, float x1, float y1, sk_paint_t* cpaint);
221 Draw the text, with origin at (x,y), using the specified paint.
222 The origin is interpreted based on the Align setting in the paint.
224 @param text The text to be drawn
225 @param byteLength The number of bytes to read from the text parameter
226 @param x The x-coordinate of the origin of the text being drawn
227 @param y The y-coordinate of the origin of the text being drawn
228 @param paint The paint used for the text (e.g. color, size, style)
230 SK_API void sk_canvas_draw_text (sk_canvas_t*, const char *text, size_t byteLength, float x, float y, const sk_paint_t* paint);
232 Draw the text, with each character/glyph origin specified by the pos[]
233 array. The origin is interpreted by the Align setting in the paint.
235 @param text The text to be drawn
236 @param byteLength The number of bytes to read from the text parameter
237 @param pos Array of positions, used to position each character
238 @param paint The paint used for the text (e.g. color, size, style)
240 SK_API void sk_canvas_draw_pos_text (sk_canvas_t*, const char *text, size_t byteLength, const sk_point_t[], const sk_paint_t* paint);
242 Draw the text, with origin at (x,y), using the specified paint, along
243 the specified path. The paint's Align setting determins where along the
244 path to start the text.
246 @param text The text to be drawn
247 @param byteLength The number of bytes to read from the text parameter
248 @param path The path the text should follow for its baseline
249 @param hOffset The distance along the path to add to the text's
251 @param vOffset The distance above(-) or below(+) the path to
253 @param paint The paint used for the text
255 SK_API void sk_canvas_draw_text_on_path (sk_canvas_t*, const char *text, size_t byteLength, const sk_path_t*path, float hOffset, float vOffset, const sk_paint_t* paint);
257 Draw the specified bitmap, with its top/left corner at (x,y), using the
258 specified paint, transformed by the current matrix. Note: if the paint
259 contains a maskfilter that generates a mask which extends beyond the
260 bitmap's original width/height, then the bitmap will be drawn as if it
261 were in a Shader with CLAMP mode. Thus the color outside of the original
262 width/height will be the edge color replicated.
264 If a shader is present on the paint it will be ignored, except in the
265 case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
266 generated by the shader.
268 @param bitmap The bitmap to be drawn
269 @param left The position of the left side of the bitmap being drawn
270 @param top The position of the top side of the bitmap being drawn
271 @param paint The paint used to draw the bitmap, or NULL
273 SK_API void sk_canvas_draw_bitmap(sk_canvas_t* ccanvas, const sk_bitmap_t* bitmap, float left, float top, const sk_paint_t* paint);
274 /** Draw the specified bitmap, scaling and translating so that it fills the specified
275 dst rect. If the src rect is non-null, only that subset of the bitmap is transformed
278 @param bitmap The bitmap to be drawn
279 @param src Optional: specify the subset of the bitmap to be drawn
280 @param dst The destination rectangle where the scaled/translated
282 @param paint The paint used to draw the bitmap, or NULL
284 SK_API void sk_canvas_draw_bitmap_rect(sk_canvas_t* ccanvas, const sk_bitmap_t* bitmap, const sk_rect_t* src, const sk_rect_t* dst, const sk_paint_t* paint);
286 Helper for setMatrix(identity). Sets the current matrix to identity.
288 SK_API void sk_canvas_reset_matrix(sk_canvas_t* ccanvas);
290 Replace the current matrix with a copy of the specified matrix.
292 @param matrix The matrix that will be copied into the current matrix.
294 SK_API void sk_canvas_set_matrix(sk_canvas_t* ccanvas, const sk_matrix_t* matrix);
296 Return the current matrix on the canvas.
297 This does not account for the translate in any of the devices.
299 @param matrix The current matrix on the canvas.
301 SK_API void sk_canvas_get_total_matrix(sk_canvas_t* ccanvas, sk_matrix_t* matrix);
303 Draw the specified rounded rectangle using the specified paint. The
304 rectangle will be filled or stroked based on the style in the
307 SK_API void sk_canvas_draw_round_rect(sk_canvas_t*, const sk_rect_t*, float rx, float ry, const sk_paint_t*);
309 Modify the current clip with the specified rectangle.
311 SK_API void sk_canvas_clip_rect_with_operation(sk_canvas_t* t, const sk_rect_t* crect, sk_clipop_t op, bool doAA);
313 Modify the current clip with the specified path.
315 SK_API void sk_canvas_clip_path_with_operation(sk_canvas_t* t, const sk_path_t* crect, sk_clipop_t op, bool doAA);
318 Return the bounds of the current clip (in local coordinates) in the
319 bounds parameter, and return true if it is non-empty. This can be useful
320 in a way similar to quickReject, in that it tells you that drawing
321 outside of these bounds will be clipped out.
323 SK_API bool sk_canvas_get_clip_bounds(sk_canvas_t* t, sk_rect_t* cbounds);
325 Return the bounds of the current clip, in device coordinates; returns
326 true if non-empty. Maybe faster than getting the clip explicitly and
327 then taking its bounds.
329 SK_API bool sk_canvas_get_clip_device_bounds(sk_canvas_t* t, sk_irect_t* cbounds);
332 Trigger the immediate execution of all pending draw operations. For the GPU
333 backend this will resolve all rendering to the GPU surface backing the
334 SkSurface that owns this canvas.
336 SK_API void sk_canvas_flush(sk_canvas_t* ccanvas);
338 SK_API sk_canvas_t* sk_canvas_new_from_bitmap(const sk_bitmap_t* bitmap);
340 SK_API void sk_canvas_draw_bitmap_lattice(sk_canvas_t* t, const sk_bitmap_t* bitmap, const sk_lattice_t* lattice, const sk_rect_t* dst, const sk_paint_t* paint);
341 SK_API void sk_canvas_draw_image_lattice(sk_canvas_t* t, const sk_image_t* image, const sk_lattice_t* lattice, const sk_rect_t* dst, const sk_paint_t* paint);
343 SK_C_PLUS_PLUS_END_GUARD