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