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