Flutter Engine
The Flutter Engine
Functions
shaders.cpp File Reference
#include "export.h"
#include "helpers.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/effects/SkRuntimeEffect.h"
#include "wrappers.h"

Go to the source code of this file.

Functions

SKWASM_EXPORT SkShadershader_createLinearGradient (SkPoint *endPoints, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar *matrix33)
 
SKWASM_EXPORT SkShadershader_createRadialGradient (SkScalar centerX, SkScalar centerY, SkScalar radius, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar *matrix33)
 
SKWASM_EXPORT SkShadershader_createConicalGradient (SkPoint *endPoints, SkScalar startRadius, SkScalar endRadius, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar *matrix33)
 
SKWASM_EXPORT SkShadershader_createSweepGradient (SkScalar centerX, SkScalar centerY, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar startAngle, SkScalar endAngle, SkScalar *matrix33)
 
SKWASM_EXPORT void shader_dispose (SkShader *shader)
 
SKWASM_EXPORT SkRuntimeEffectruntimeEffect_create (SkString *source)
 
SKWASM_EXPORT void runtimeEffect_dispose (SkRuntimeEffect *effect)
 
SKWASM_EXPORT size_t runtimeEffect_getUniformSize (SkRuntimeEffect *effect)
 
SKWASM_EXPORT SkShadershader_createRuntimeEffectShader (SkRuntimeEffect *runtimeEffect, SkData *uniforms, SkShader **children, size_t childCount)
 
SKWASM_EXPORT SkShadershader_createFromImage (SkImage *image, SkTileMode tileModeX, SkTileMode tileModeY, FilterQuality quality, SkScalar *matrix33)
 

Function Documentation

◆ runtimeEffect_create()

SKWASM_EXPORT SkRuntimeEffect * runtimeEffect_create ( SkString source)

Definition at line 105 of file shaders.cpp.

105 {
107 if (result.effect == nullptr) {
108 printf("Failed to compile shader. Error text:\n%s",
109 result.errorText.data());
110 return nullptr;
111 } else {
112 return result.effect.release();
113 }
114}
static Result MakeForShader(SkString sksl, const Options &)
SkBitmap source
Definition: examples.cpp:28
GAsyncResult * result
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83

◆ runtimeEffect_dispose()

SKWASM_EXPORT void runtimeEffect_dispose ( SkRuntimeEffect effect)

Definition at line 116 of file shaders.cpp.

116 {
117 effect->unref();
118}
void unref() const
Definition: SkRefCnt.h:72

◆ runtimeEffect_getUniformSize()

SKWASM_EXPORT size_t runtimeEffect_getUniformSize ( SkRuntimeEffect effect)

Definition at line 120 of file shaders.cpp.

120 {
121 return effect->uniformSize();
122}
size_t uniformSize() const

◆ shader_createConicalGradient()

SKWASM_EXPORT SkShader * shader_createConicalGradient ( SkPoint endPoints,
SkScalar  startRadius,
SkScalar  endRadius,
SkColor colors,
SkScalar stops,
int  count,
SkTileMode  tileMode,
SkScalar matrix33 
)

Definition at line 54 of file shaders.cpp.

62 {
63 if (matrix33) {
64 SkMatrix localMatrix = createMatrix(matrix33);
66 endPoints[0], startRadius, endPoints[1], endRadius, colors,
67 stops, count, tileMode, 0, &localMatrix)
68 .release();
69
70 } else {
71 return SkGradientShader::MakeTwoPointConical(endPoints[0], startRadius,
72 endPoints[1], endRadius,
73 colors, stops, count, tileMode)
74 .release();
75 }
76}
int count
Definition: FontMgrTest.cpp:50
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
T * release()
Definition: SkRefCnt.h:324
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkMatrix createMatrix(const SkScalar *f)
Definition: helpers.h:14

◆ shader_createFromImage()

SKWASM_EXPORT SkShader * shader_createFromImage ( SkImage image,
SkTileMode  tileModeX,
SkTileMode  tileModeY,
FilterQuality  quality,
SkScalar matrix33 
)

Definition at line 139 of file shaders.cpp.

143 {
144 if (matrix33) {
145 SkMatrix localMatrix = createMatrix(matrix33);
146 return image
147 ->makeShader(tileModeX, tileModeY, samplingOptionsForQuality(quality),
148 &localMatrix)
149 .release();
150 } else {
151 return image
152 ->makeShader(tileModeX, tileModeY, samplingOptionsForQuality(quality))
153 .release();
154 }
155}
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions samplingOptionsForQuality(FilterQuality quality)
Definition: helpers.h:47

◆ shader_createLinearGradient()

SKWASM_EXPORT SkShader * shader_createLinearGradient ( SkPoint endPoints,
SkColor colors,
SkScalar stops,
int  count,
SkTileMode  tileMode,
SkScalar matrix33 
)

Definition at line 14 of file shaders.cpp.

21 {
22 if (matrix33) {
23 SkMatrix localMatrix = createMatrix(matrix33);
24 return SkGradientShader::MakeLinear(endPoints, colors, stops, count,
25 tileMode, 0, &localMatrix)
26 .release();
27 } else {
28 return SkGradientShader::MakeLinear(endPoints, colors, stops, count,
29 tileMode)
30 .release();
31 }
32}
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)

◆ shader_createRadialGradient()

SKWASM_EXPORT SkShader * shader_createRadialGradient ( SkScalar  centerX,
SkScalar  centerY,
SkScalar  radius,
SkColor colors,
SkScalar stops,
int  count,
SkTileMode  tileMode,
SkScalar matrix33 
)

Definition at line 34 of file shaders.cpp.

41 {
42 if (matrix33) {
43 SkMatrix localMatrix = createMatrix(matrix33);
44 return SkGradientShader::MakeRadial({centerX, centerY}, radius, colors,
45 stops, count, tileMode, 0, &localMatrix)
46 .release();
47 } else {
48 return SkGradientShader::MakeRadial({centerX, centerY}, radius, colors,
49 stops, count, tileMode)
50 .release();
51 }
52}
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)

◆ shader_createRuntimeEffectShader()

SKWASM_EXPORT SkShader * shader_createRuntimeEffectShader ( SkRuntimeEffect runtimeEffect,
SkData uniforms,
SkShader **  children,
size_t  childCount 
)

Definition at line 124 of file shaders.cpp.

128 {
129 std::vector<sk_sp<SkShader>> childPointers;
130 for (size_t i = 0; i < childCount; i++) {
131 childPointers.emplace_back(sk_ref_sp<SkShader>(children[i]));
132 }
133 return runtimeEffect
134 ->makeShader(SkData::MakeWithCopy(uniforms->data(), uniforms->size()),
135 childPointers.data(), childCount, nullptr)
136 .release();
137}
const void * data() const
Definition: SkData.h:37
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
size_t size() const
Definition: SkData.h:30
sk_sp< SkShader > makeShader(sk_sp< const SkData > uniforms, sk_sp< SkShader > children[], size_t childCount, const SkMatrix *localMatrix=nullptr) const

◆ shader_createSweepGradient()

SKWASM_EXPORT SkShader * shader_createSweepGradient ( SkScalar  centerX,
SkScalar  centerY,
SkColor colors,
SkScalar stops,
int  count,
SkTileMode  tileMode,
SkScalar  startAngle,
SkScalar  endAngle,
SkScalar matrix33 
)

Definition at line 78 of file shaders.cpp.

86 {
87 if (matrix33) {
88 SkMatrix localMatrix = createMatrix(matrix33);
89 return SkGradientShader::MakeSweep(centerX, centerY, colors, stops, count,
90 tileMode, startAngle, endAngle, 0,
91 &localMatrix)
92 .release();
93 } else {
94 return SkGradientShader::MakeSweep(centerX, centerY, colors, stops, count,
95 tileMode, startAngle, endAngle, 0,
96 nullptr)
97 .release();
98 }
99}
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
SkScalar startAngle
Definition: SkRecords.h:250

◆ shader_dispose()

SKWASM_EXPORT void shader_dispose ( SkShader shader)

Definition at line 101 of file shaders.cpp.

101 {
102 shader->unref();
103}