Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: tests/CTest.cpp

Issue 1263773006: C API: add radial, sweep, and two-point conical gradient shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pass by const* Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/c/sk_surface.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "sk_canvas.h" 8 #include "sk_canvas.h"
9 #include "sk_paint.h" 9 #include "sk_paint.h"
10 #include "sk_surface.h" 10 #include "sk_surface.h"
11 #include "sk_shader.h"
11 12
12 #include "Test.h" 13 #include "Test.h"
13 14
15
16 static void shader_test(skiatest::Reporter* reporter) {
17 sk_imageinfo_t info =
18 {64, 64, sk_colortype_get_default_8888(), PREMUL_SK_ALPHATYPE};
19 sk_surface_t* surface = sk_surface_new_raster(&info, NULL);
20 sk_canvas_t* canvas = sk_surface_get_canvas(surface);
21 sk_paint_t* paint = sk_paint_new();
22
23 sk_shader_tilemode_t tilemode = CLAMP_SK_SHADER_TILEMODE;
24 sk_point_t point = {0.0f, 0.0f};
25 sk_point_t point2 = {30.0f, 40.0f};
26 sk_color_t colors[] = {
27 (sk_color_t)sk_color_set_argb(0xFF, 0x00, 0x00, 0xFF),
28 (sk_color_t)sk_color_set_argb(0xFF, 0x00, 0xFF, 0x00)
29 };
30 sk_shader_t* shader;
31
32 shader = sk_shader_new_radial_gradient(
33 &point, 1.0f, colors, NULL, 2, tilemode, NULL);
34 REPORTER_ASSERT(reporter, shader != NULL);
35 sk_paint_set_shader(paint, shader);
36 sk_shader_unref(shader);
37 sk_canvas_draw_paint(canvas, paint);
38
39 shader = sk_shader_new_sweep_gradient(&point, colors, NULL, 2, NULL);
40 REPORTER_ASSERT(reporter, shader != NULL);
41 sk_paint_set_shader(paint, shader);
42 sk_shader_unref(shader);
43 sk_canvas_draw_paint(canvas, paint);
44
45 shader = sk_shader_new_two_point_conical_gradient(
46 &point, 10.0f, &point2, 50.0f, colors, NULL, 2, tilemode, NULL);
47 REPORTER_ASSERT(reporter, shader != NULL);
48 sk_paint_set_shader(paint, shader);
49 sk_shader_unref(shader);
50 sk_canvas_draw_paint(canvas, paint);
51
52 sk_paint_delete(paint);
53 sk_surface_unref(surface);
54 }
55
14 static void test_c(skiatest::Reporter* reporter) { 56 static void test_c(skiatest::Reporter* reporter) {
15 sk_colortype_t ct = sk_colortype_get_default_8888(); 57 sk_colortype_t ct = sk_colortype_get_default_8888();
16 58
17 sk_imageinfo_t info = { 59 sk_imageinfo_t info = {
18 1, 1, ct, PREMUL_SK_ALPHATYPE 60 1, 1, ct, PREMUL_SK_ALPHATYPE
19 }; 61 };
20 uint32_t pixel[1] = { 0 }; 62 uint32_t pixel[1] = { 0 };
21 sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY }; 63 sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
22 64
23 sk_surface_t* surface = sk_surface_new_raster_direct(&info, pixel, sizeof(ui nt32_t), 65 sk_surface_t* surface = sk_surface_new_raster_direct(&info, pixel, sizeof(ui nt32_t),
24 &surfaceProps); 66 &surfaceProps);
25 sk_paint_t* paint = sk_paint_new(); 67 sk_paint_t* paint = sk_paint_new();
26 68
27 sk_canvas_t* canvas = sk_surface_get_canvas(surface); 69 sk_canvas_t* canvas = sk_surface_get_canvas(surface);
28 sk_canvas_draw_paint(canvas, paint); 70 sk_canvas_draw_paint(canvas, paint);
29 REPORTER_ASSERT(reporter, 0xFF000000 == pixel[0]); 71 REPORTER_ASSERT(reporter, 0xFF000000 == pixel[0]);
30 72
31 sk_paint_set_color(paint, sk_color_set_argb(0xFF, 0xFF, 0xFF, 0xFF)); 73 sk_paint_set_color(paint, sk_color_set_argb(0xFF, 0xFF, 0xFF, 0xFF));
32 sk_canvas_draw_paint(canvas, paint); 74 sk_canvas_draw_paint(canvas, paint);
33 REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]); 75 REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
34 76
35 sk_paint_delete(paint); 77 sk_paint_delete(paint);
36 sk_surface_unref(surface); 78 sk_surface_unref(surface);
37 } 79 }
38 80
39 DEF_TEST(C_API, reporter) { 81 DEF_TEST(C_API, reporter) {
40 test_c(reporter); 82 test_c(reporter);
83 shader_test(reporter);
41 } 84 }
OLDNEW
« no previous file with comments | « src/c/sk_surface.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698