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 #include "sk_canvas.h"
12 #include "sk_data.h"
13 #include "sk_image.h"
14 #include "sk_imageinfo.h"
15 #include "sk_paint.h"
16 #include "sk_shader.h"
17 #include "sk_surface.h"
18
19 extern void sk_test_c_api(sk_canvas_t*);
20
21 #define W 256
22 #define H 256
23
make_shader()24 static sk_shader_t* make_shader() {
25 sk_point_t pts[] = { { 0, 0 }, { W, H } };
26 sk_color_t colors[] = { 0xFF00FF00, 0xFF0000FF };
27 return sk_shader_new_linear_gradient(pts, colors, NULL, 2, CLAMP_SK_SHADER_TILEMODE, NULL);
28 }
29
do_draw(sk_canvas_t * canvas)30 static void do_draw(sk_canvas_t* canvas) {
31 sk_paint_t* paint = sk_paint_new();
32 sk_paint_set_antialias(paint, true);
33
34 sk_paint_set_color(paint, 0xFFFFFFFF);
35 sk_canvas_draw_paint(canvas, paint);
36
37 sk_rect_t r = { 10, 10, W - 10, H - 10 };
38
39 sk_paint_set_color(paint, 0xFFFF0000);
40 sk_canvas_draw_rect(canvas, &r, paint);
41
42 sk_shader_t* shader = make_shader();
43 sk_paint_set_shader(paint, shader);
44 sk_shader_unref(shader);
45
46 sk_canvas_draw_oval(canvas, &r, paint);
47
48 sk_paint_delete(paint);
49 }
50
sk_test_c_api(sk_canvas_t * canvas)51 void sk_test_c_api(sk_canvas_t* canvas) {
52 do_draw(canvas);
53
54 sk_imageinfo_t* info = sk_imageinfo_new(W, H, RGBA_8888_SK_COLORTYPE, OPAQUE_SK_ALPHATYPE,
55 NULL);
56 sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
57 sk_surface_t* surf = sk_surface_new_raster(info, &surfaceProps);
58 sk_imageinfo_delete(info);
59 do_draw(sk_surface_get_canvas(surf));
60
61 sk_image_t* img0 = sk_surface_new_image_snapshot(surf);
62 sk_surface_unref(surf);
63
64 sk_canvas_draw_image(canvas, img0, W + 10, 10, NULL);
65
66 sk_data_t* data = sk_image_encode(img0);
67 sk_image_unref(img0);
68
69 sk_image_t* img1 = sk_image_new_from_encoded(data, NULL);
70 sk_data_unref(data);
71
72 if (img1) {
73 sk_canvas_draw_image(canvas, img1, W/2, H/2, NULL);
74 sk_image_unref(img1);
75 }
76 }
77
78
79