2 * Copyright 2016 Xamarin Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkComposeShader.h"
10 #include "SkColorFilter.h"
11 #include "SkGradientShader.h"
12 #include "SkPerlinNoiseShader.h"
14 #include "sk_shader.h"
16 #include "sk_types_priv.h"
18 sk_shader_t* sk_shader_new_empty() {
19 return ToShader(SkShader::MakeEmptyShader().release());
22 sk_shader_t* sk_shader_new_color(sk_color_t color) {
23 return ToShader(SkShader::MakeColorShader(color).release());
26 sk_shader_t* sk_shader_new_bitmap(const sk_bitmap_t* src,
27 sk_shader_tilemode_t tmx,
28 sk_shader_tilemode_t tmy,
29 const sk_matrix_t* localMatrix) {
32 from_c(localMatrix, &matrix);
36 sk_sp<SkShader> s = SkShader::MakeBitmapShader(
38 (SkShader::TileMode)tmx,
39 (SkShader::TileMode)tmy,
41 return ToShader(s.release());
44 sk_shader_t* sk_shader_new_picture(sk_picture_t* src,
45 sk_shader_tilemode_t tmx,
46 sk_shader_tilemode_t tmy,
47 const sk_matrix_t* localMatrix,
48 const sk_rect_t* tile) {
51 from_c(localMatrix, &matrix);
56 sk_sp<SkShader> s = SkShader::MakePictureShader(
57 sk_ref_sp(AsPicture(src)),
58 (SkShader::TileMode)tmx,
59 (SkShader::TileMode)tmy,
62 return ToShader(s.release());
65 sk_shader_t* sk_shader_new_color_filter(sk_shader_t* proxy,
66 sk_colorfilter_t* filter) {
67 sk_sp<SkShader> s = AsShader(proxy)->makeWithColorFilter(sk_ref_sp(AsColorFilter(filter)));
68 return ToShader(s.release());
71 sk_shader_t* sk_shader_new_local_matrix(sk_shader_t* proxy,
72 const sk_matrix_t* localMatrix) {
75 from_c(localMatrix, &matrix);
79 sk_sp<SkShader> s = AsShader(proxy)->makeWithLocalMatrix(matrix);
80 return ToShader(s.release());
83 sk_shader_t* sk_shader_new_perlin_noise_fractal_noise(
88 const sk_isize_t* ctileSize) {
90 const SkISize* tileSize = AsISize(ctileSize);
91 sk_sp<SkShader> s = SkPerlinNoiseShader::MakeFractalNoise(
97 return ToShader(s.release());
100 sk_shader_t* sk_shader_new_perlin_noise_turbulence(
101 float baseFrequencyX,
102 float baseFrequencyY,
105 const sk_isize_t* ctileSize) {
107 const SkISize* tileSize = AsISize(ctileSize);
108 sk_sp<SkShader> s = SkPerlinNoiseShader::MakeTurbulence(
114 return ToShader(s.release());
117 sk_shader_t* sk_shader_new_compose(
118 sk_shader_t* shaderA,
119 sk_shader_t* shaderB) {
121 sk_sp<SkShader> s = SkShader::MakeComposeShader(
122 sk_ref_sp(AsShader(shaderA)),
123 sk_ref_sp(AsShader(shaderB)),
124 SkXfermode::kSrcOver_Mode);
125 return ToShader(s.release());
128 sk_shader_t* sk_shader_new_compose_with_mode(
129 sk_shader_t* shaderA,
130 sk_shader_t* shaderB,
131 sk_xfermode_mode_t cmode) {
133 sk_sp<SkShader> s = SkShader::MakeComposeShader(
134 sk_ref_sp(AsShader(shaderA)),
135 sk_ref_sp(AsShader(shaderB)),
136 (SkXfermode::Mode)cmode);
137 return ToShader(s.release());
140 void sk_shader_ref(sk_shader_t* cshader) {
141 SkSafeRef(AsShader(cshader));
144 void sk_shader_unref(sk_shader_t* cshader) {
145 SkSafeUnref(AsShader(cshader));
148 sk_shader_t* sk_shader_new_linear_gradient(const sk_point_t pts[2],
149 const sk_color_t colors[],
150 const float colorPos[],
152 sk_shader_tilemode_t cmode,
153 const sk_matrix_t* cmatrix) {
156 from_c(cmatrix, &matrix);
158 matrix.setIdentity();
160 return (sk_shader_t*)SkGradientShader::MakeLinear(reinterpret_cast<const SkPoint*>(pts),
161 reinterpret_cast<const SkColor*>(colors),
162 colorPos, colorCount,
163 (SkShader::TileMode)cmode, 0, &matrix).release();
166 sk_shader_t* sk_shader_new_radial_gradient(const sk_point_t* ccenter,
168 const sk_color_t colors[],
169 const float colorPos[],
171 sk_shader_tilemode_t cmode,
172 const sk_matrix_t* cmatrix) {
175 from_c(cmatrix, &matrix);
177 matrix.setIdentity();
179 SkPoint center = AsPoint(*ccenter);
180 return (sk_shader_t*)SkGradientShader::MakeRadial(center, (SkScalar)radius,
181 reinterpret_cast<const SkColor*>(colors),
182 reinterpret_cast<const SkScalar*>(colorPos),
183 colorCount, (SkShader::TileMode)cmode, 0, &matrix).release();
186 sk_shader_t* sk_shader_new_sweep_gradient(const sk_point_t* ccenter,
187 const sk_color_t colors[],
188 const float colorPos[],
190 const sk_matrix_t* cmatrix) {
193 from_c(cmatrix, &matrix);
195 matrix.setIdentity();
197 return (sk_shader_t*)SkGradientShader::MakeSweep((SkScalar)(ccenter->x),
198 (SkScalar)(ccenter->y),
199 reinterpret_cast<const SkColor*>(colors),
200 reinterpret_cast<const SkScalar*>(colorPos),
201 colorCount, 0, &matrix).release();
204 sk_shader_t* sk_shader_new_two_point_conical_gradient(const sk_point_t* start,
206 const sk_point_t* end,
208 const sk_color_t colors[],
209 const float colorPos[],
211 sk_shader_tilemode_t cmode,
212 const sk_matrix_t* cmatrix) {
215 from_c(cmatrix, &matrix);
217 matrix.setIdentity();
219 SkPoint skstart = AsPoint(*start);
220 SkPoint skend = AsPoint(*end);
221 return (sk_shader_t*)SkGradientShader::MakeTwoPointConical(skstart, (SkScalar)startRadius,
222 skend, (SkScalar)endRadius,
223 reinterpret_cast<const SkColor*>(colors),
224 reinterpret_cast<const SkScalar*>(colorPos),
225 colorCount, (SkShader::TileMode)cmode, 0, &matrix).release();