blob: 8e65bda30769755a558e849b91297f9f4753ad9a [file] [log] [blame]
reedafa278e2014-11-24 19:11:48 -08001/*
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"
reedb2a5d7e2014-12-25 14:16:21 -080012#include "sk_data.h"
13#include "sk_image.h"
reedafa278e2014-11-24 19:11:48 -080014#include "sk_paint.h"
15#include "sk_shader.h"
16#include "sk_surface.h"
17
18extern void sk_test_c_api(sk_canvas_t*);
19
20#define W 256
21#define H 256
22
23static sk_shader_t* make_shader() {
24 sk_point_t pts[] = { { 0, 0 }, { W, H } };
25 sk_color_t colors[] = { 0xFF00FF00, 0xFF0000FF };
26 return sk_shader_new_linear_gradient(pts, colors, NULL, 2, CLAMP_SK_SHADER_TILEMODE, NULL);
27}
28
reedb2a5d7e2014-12-25 14:16:21 -080029static void do_draw(sk_canvas_t* canvas) {
reedafa278e2014-11-24 19:11:48 -080030 sk_paint_t* paint = sk_paint_new();
31 sk_paint_set_antialias(paint, true);
reedb2a5d7e2014-12-25 14:16:21 -080032
reedafa278e2014-11-24 19:11:48 -080033 sk_paint_set_color(paint, 0xFFFFFFFF);
34 sk_canvas_draw_paint(canvas, paint);
reedb2a5d7e2014-12-25 14:16:21 -080035
reedafa278e2014-11-24 19:11:48 -080036 sk_rect_t r = { 10, 10, W - 10, H - 10 };
reedb2a5d7e2014-12-25 14:16:21 -080037
reedafa278e2014-11-24 19:11:48 -080038 sk_paint_set_color(paint, 0xFFFF0000);
39 sk_canvas_draw_rect(canvas, &r, paint);
reedb2a5d7e2014-12-25 14:16:21 -080040
reedafa278e2014-11-24 19:11:48 -080041 sk_shader_t* shader = make_shader();
42 sk_paint_set_shader(paint, shader);
43 sk_shader_unref(shader);
reedb2a5d7e2014-12-25 14:16:21 -080044
reedafa278e2014-11-24 19:11:48 -080045 sk_canvas_draw_oval(canvas, &r, paint);
reedb2a5d7e2014-12-25 14:16:21 -080046
reedafa278e2014-11-24 19:11:48 -080047 sk_paint_delete(paint);
48}
49
reedb2a5d7e2014-12-25 14:16:21 -080050void sk_test_c_api(sk_canvas_t* canvas) {
51 do_draw(canvas);
52
53 sk_imageinfo_t info = {
54 W, H, sk_colortype_get_default_8888(), OPAQUE_SK_ALPHATYPE
55 };
56 sk_surface_t* surf = sk_surface_new_raster(&info);
57 do_draw(sk_surface_get_canvas(surf));
58
59 sk_image_t* img0 = sk_surface_new_image_snapshot(surf);
60 sk_surface_unref(surf);
61
62 sk_canvas_draw_image(canvas, img0, W + 10, 10, NULL);
63
64 sk_data_t* data = sk_image_encode(img0);
65 sk_image_unref(img0);
66
67 sk_image_t* img1 = sk_image_new_from_data(data);
68 sk_data_unref(data);
69
reed2906d4a2014-12-25 20:41:13 -080070 if (img1) {
71 sk_canvas_draw_image(canvas, img1, W/2, H/2, NULL);
72 sk_image_unref(img1);
73 }
reedb2a5d7e2014-12-25 14:16:21 -080074}
75
reedafa278e2014-11-24 19:11:48 -080076