2014-10-24 18:16:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/c/sk_canvas.h"
|
|
|
|
#include "include/c/sk_imageinfo.h"
|
|
|
|
#include "include/c/sk_paint.h"
|
|
|
|
#include "include/c/sk_shader.h"
|
|
|
|
#include "include/c/sk_surface.h"
|
|
|
|
#include "include/c/sk_types.h"
|
|
|
|
#include "tests/Test.h"
|
2018-04-17 18:14:51 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2014-11-17 14:15:42 +00:00
|
|
|
|
2015-08-12 14:37:34 +00:00
|
|
|
static void shader_test(skiatest::Reporter* reporter) {
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_imageinfo_t* info = sk_imageinfo_new(64, 64, RGBA_8888_SK_COLORTYPE, PREMUL_SK_ALPHATYPE,
|
|
|
|
NULL);
|
|
|
|
sk_surface_t* surface = sk_surface_new_raster(info, nullptr);
|
2015-08-12 14:37:34 +00:00
|
|
|
sk_canvas_t* canvas = sk_surface_get_canvas(surface);
|
|
|
|
sk_paint_t* paint = sk_paint_new();
|
|
|
|
|
|
|
|
sk_shader_tilemode_t tilemode = CLAMP_SK_SHADER_TILEMODE;
|
|
|
|
sk_point_t point = {0.0f, 0.0f};
|
|
|
|
sk_point_t point2 = {30.0f, 40.0f};
|
|
|
|
sk_color_t colors[] = {
|
|
|
|
(sk_color_t)sk_color_set_argb(0xFF, 0x00, 0x00, 0xFF),
|
|
|
|
(sk_color_t)sk_color_set_argb(0xFF, 0x00, 0xFF, 0x00)
|
|
|
|
};
|
|
|
|
sk_shader_t* shader;
|
|
|
|
|
|
|
|
shader = sk_shader_new_radial_gradient(
|
2015-08-27 14:41:13 +00:00
|
|
|
&point, 1.0f, colors, nullptr, 2, tilemode, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, shader != nullptr);
|
2015-08-12 14:37:34 +00:00
|
|
|
sk_paint_set_shader(paint, shader);
|
|
|
|
sk_shader_unref(shader);
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
shader = sk_shader_new_sweep_gradient(&point, colors, nullptr, 2, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, shader != nullptr);
|
2015-08-12 14:37:34 +00:00
|
|
|
sk_paint_set_shader(paint, shader);
|
|
|
|
sk_shader_unref(shader);
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
|
|
|
|
|
|
|
shader = sk_shader_new_two_point_conical_gradient(
|
2015-08-27 14:41:13 +00:00
|
|
|
&point, 10.0f, &point2, 50.0f, colors, nullptr, 2, tilemode, nullptr);
|
|
|
|
REPORTER_ASSERT(reporter, shader != nullptr);
|
2015-08-12 14:37:34 +00:00
|
|
|
sk_paint_set_shader(paint, shader);
|
|
|
|
sk_shader_unref(shader);
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
|
|
|
|
|
|
|
sk_paint_delete(paint);
|
|
|
|
sk_surface_unref(surface);
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_imageinfo_delete(info);
|
2015-08-12 14:37:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 18:16:19 +00:00
|
|
|
static void test_c(skiatest::Reporter* reporter) {
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_imageinfo_t* info = sk_imageinfo_new(1, 1, RGBA_8888_SK_COLORTYPE, PREMUL_SK_ALPHATYPE,
|
|
|
|
NULL);
|
2014-10-24 18:16:19 +00:00
|
|
|
uint32_t pixel[1] = { 0 };
|
2015-06-23 13:26:08 +00:00
|
|
|
sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
|
2014-10-24 18:16:19 +00:00
|
|
|
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_surface_t* surface = sk_surface_new_raster_direct(info, pixel, sizeof(uint32_t),
|
2015-06-23 13:26:08 +00:00
|
|
|
&surfaceProps);
|
2014-10-24 18:16:19 +00:00
|
|
|
sk_paint_t* paint = sk_paint_new();
|
|
|
|
|
|
|
|
sk_canvas_t* canvas = sk_surface_get_canvas(surface);
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
|
|
|
REPORTER_ASSERT(reporter, 0xFF000000 == pixel[0]);
|
|
|
|
|
|
|
|
sk_paint_set_color(paint, sk_color_set_argb(0xFF, 0xFF, 0xFF, 0xFF));
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
|
|
|
REPORTER_ASSERT(reporter, 0xFFFFFFFF == pixel[0]);
|
|
|
|
|
2015-07-31 20:38:06 +00:00
|
|
|
sk_paint_set_xfermode_mode(paint, SRC_SK_XFERMODE_MODE);
|
|
|
|
sk_paint_set_color(paint, sk_color_set_argb(0x80, 0x80, 0x80, 0x80));
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
|
|
|
REPORTER_ASSERT(reporter, 0x80404040 == pixel[0]);
|
|
|
|
|
2014-10-24 18:16:19 +00:00
|
|
|
sk_paint_delete(paint);
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_surface_unref(surface);
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_imageinfo_delete(info);
|
2014-10-24 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(C_API, reporter) {
|
|
|
|
test_c(reporter);
|
2015-08-12 14:37:34 +00:00
|
|
|
shader_test(reporter);
|
2014-10-24 18:16:19 +00:00
|
|
|
}
|