• 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 #include "include/c/sk_canvas.h"
9 #include "include/c/sk_imageinfo.h"
10 #include "include/c/sk_paint.h"
11 #include "include/c/sk_shader.h"
12 #include "include/c/sk_surface.h"
13 #include "include/c/sk_types.h"
14 #include "tests/Test.h"
15 
16 #include <stddef.h>
17 #include <stdint.h>
18 
shader_test(skiatest::Reporter * reporter)19 static void shader_test(skiatest::Reporter* reporter) {
20     sk_imageinfo_t* info = sk_imageinfo_new(64, 64, RGBA_8888_SK_COLORTYPE, PREMUL_SK_ALPHATYPE,
21                                             NULL);
22     sk_surface_t* surface  = sk_surface_new_raster(info, nullptr);
23     sk_canvas_t* canvas = sk_surface_get_canvas(surface);
24     sk_paint_t* paint = sk_paint_new();
25 
26     sk_shader_tilemode_t tilemode = CLAMP_SK_SHADER_TILEMODE;
27     sk_point_t point = {0.0f, 0.0f};
28     sk_point_t point2 = {30.0f, 40.0f};
29     sk_color_t colors[] = {
30         (sk_color_t)sk_color_set_argb(0xFF, 0x00, 0x00, 0xFF),
31         (sk_color_t)sk_color_set_argb(0xFF, 0x00, 0xFF, 0x00)
32     };
33     sk_shader_t* shader;
34 
35     shader = sk_shader_new_radial_gradient(
36             &point, 1.0f, colors, nullptr, 2, tilemode, nullptr);
37     REPORTER_ASSERT(reporter, shader != nullptr);
38     sk_paint_set_shader(paint, shader);
39     sk_shader_unref(shader);
40     sk_canvas_draw_paint(canvas, paint);
41 
42     shader = sk_shader_new_sweep_gradient(&point, colors, nullptr, 2, nullptr);
43     REPORTER_ASSERT(reporter, shader != nullptr);
44     sk_paint_set_shader(paint, shader);
45     sk_shader_unref(shader);
46     sk_canvas_draw_paint(canvas, paint);
47 
48     shader = sk_shader_new_two_point_conical_gradient(
49             &point, 10.0f,  &point2, 50.0f, colors, nullptr, 2, tilemode, nullptr);
50     REPORTER_ASSERT(reporter, shader != nullptr);
51     sk_paint_set_shader(paint, shader);
52     sk_shader_unref(shader);
53     sk_canvas_draw_paint(canvas, paint);
54 
55     sk_paint_delete(paint);
56     sk_surface_unref(surface);
57     sk_imageinfo_delete(info);
58 }
59 
test_c(skiatest::Reporter * reporter)60 static void test_c(skiatest::Reporter* reporter) {
61     sk_imageinfo_t* info = sk_imageinfo_new(1, 1, RGBA_8888_SK_COLORTYPE, PREMUL_SK_ALPHATYPE,
62                                             NULL);
63     uint32_t pixel[1] = { 0 };
64     sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
65 
66     sk_surface_t* surface = sk_surface_new_raster_direct(info, pixel, sizeof(uint32_t),
67                                                          &surfaceProps);
68     sk_paint_t* paint = sk_paint_new();
69 
70     sk_canvas_t* canvas = sk_surface_get_canvas(surface);
71     sk_canvas_draw_paint(canvas, paint);
72     REPORTER_ASSERT(reporter, 0xFF000000 == pixel[0]);
73 
74     sk_paint_set_color(paint, sk_color_set_argb(0xFF, 0xFF, 0xFF, 0xFF));
75     sk_canvas_draw_paint(canvas, paint);
76     REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
77 
78     sk_paint_set_xfermode_mode(paint, SRC_SK_XFERMODE_MODE);
79     sk_paint_set_color(paint, sk_color_set_argb(0x80, 0x80, 0x80, 0x80));
80     sk_canvas_draw_paint(canvas, paint);
81     REPORTER_ASSERT(reporter, 0x80404040 == pixel[0]);
82 
83     sk_paint_delete(paint);
84     sk_surface_unref(surface);
85     sk_imageinfo_delete(info);
86 }
87 
DEF_TEST(C_API,reporter)88 DEF_TEST(C_API, reporter) {
89     test_c(reporter);
90     shader_test(reporter);
91 }
92