blob: 5e57225b6459979e1a073147f592f9a563d53c74 [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 };
robertphillips702edbd2015-06-23 06:26:08 -070056 sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
57 sk_surface_t* surf = sk_surface_new_raster(&info, &surfaceProps);
reedb2a5d7e2014-12-25 14:16:21 -080058 do_draw(sk_surface_get_canvas(surf));
59
60 sk_image_t* img0 = sk_surface_new_image_snapshot(surf);
61 sk_surface_unref(surf);
62
63 sk_canvas_draw_image(canvas, img0, W + 10, 10, NULL);
64
65 sk_data_t* data = sk_image_encode(img0);
66 sk_image_unref(img0);
67
reed871872f2015-06-22 12:48:26 -070068 sk_image_t* img1 = sk_image_new_from_encoded(data, NULL);
reedb2a5d7e2014-12-25 14:16:21 -080069 sk_data_unref(data);
70
reed2906d4a2014-12-25 20:41:13 -080071 if (img1) {
72 sk_canvas_draw_image(canvas, img1, W/2, H/2, NULL);
73 sk_image_unref(img1);
74 }
reedb2a5d7e2014-12-25 14:16:21 -080075}
76
reedafa278e2014-11-24 19:11:48 -080077