Flutter Engine
The Flutter Engine
shaders.cpp
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "export.h"
6#include "helpers.h"
10#include "wrappers.h"
11
12using namespace Skwasm;
13
15 SkPoint* endPoints, // Two points
17 SkScalar* stops,
18 int count, // Number of stops/colors
19 SkTileMode tileMode,
20 SkScalar* matrix33 // Can be nullptr
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}
33
35 SkScalar centerY,
36 SkScalar radius,
38 SkScalar* stops,
39 int count,
40 SkTileMode tileMode,
41 SkScalar* matrix33) {
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}
53
55 SkPoint* endPoints, // Two points
56 SkScalar startRadius,
57 SkScalar endRadius,
59 SkScalar* stops,
60 int count,
61 SkTileMode tileMode,
62 SkScalar* matrix33) {
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}
77
79 SkScalar centerY,
81 SkScalar* stops,
82 int count,
83 SkTileMode tileMode,
85 SkScalar endAngle,
86 SkScalar* matrix33) {
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}
100
102 shader->unref();
103}
104
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}
115
117 effect->unref();
118}
119
121 return effect->uniformSize();
122}
123
125 SkRuntimeEffect* runtimeEffect,
126 SkData* uniforms,
127 SkShader** children,
128 size_t childCount) {
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}
138
140 SkTileMode tileModeX,
141 SkTileMode tileModeY,
142 FilterQuality quality,
143 SkScalar* matrix33) {
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}
int count
Definition: FontMgrTest.cpp:50
uint32_t SkColor
Definition: SkColor.h:37
SkTileMode
Definition: SkTileMode.h:13
Definition: SkData.h:25
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
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)
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)
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)
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)
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
void unref() const
Definition: SkRefCnt.h:72
size_t uniformSize() const
sk_sp< SkShader > makeShader(sk_sp< const SkData > uniforms, sk_sp< SkShader > children[], size_t childCount, const SkMatrix *localMatrix=nullptr) const
static Result MakeForShader(SkString sksl, const Options &)
T * release()
Definition: SkRefCnt.h:324
SkBitmap source
Definition: examples.cpp:28
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkScalar startAngle
Definition: SkRecords.h:250
PODArray< SkColor > colors
Definition: SkRecords.h:276
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
Definition: helpers.h:12
SkSamplingOptions samplingOptionsForQuality(FilterQuality quality)
Definition: helpers.h:47
FilterQuality
Definition: helpers.h:29
SkMatrix createMatrix(const SkScalar *f)
Definition: helpers.h:14
SKWASM_EXPORT SkShader * shader_createSweepGradient(SkScalar centerX, SkScalar centerY, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar startAngle, SkScalar endAngle, SkScalar *matrix33)
Definition: shaders.cpp:78
SKWASM_EXPORT size_t runtimeEffect_getUniformSize(SkRuntimeEffect *effect)
Definition: shaders.cpp:120
SKWASM_EXPORT SkShader * shader_createFromImage(SkImage *image, SkTileMode tileModeX, SkTileMode tileModeY, FilterQuality quality, SkScalar *matrix33)
Definition: shaders.cpp:139
SKWASM_EXPORT void shader_dispose(SkShader *shader)
Definition: shaders.cpp:101
SKWASM_EXPORT SkRuntimeEffect * runtimeEffect_create(SkString *source)
Definition: shaders.cpp:105
SKWASM_EXPORT SkShader * shader_createRuntimeEffectShader(SkRuntimeEffect *runtimeEffect, SkData *uniforms, SkShader **children, size_t childCount)
Definition: shaders.cpp:124
SKWASM_EXPORT SkShader * shader_createConicalGradient(SkPoint *endPoints, SkScalar startRadius, SkScalar endRadius, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar *matrix33)
Definition: shaders.cpp:54
SKWASM_EXPORT SkShader * shader_createLinearGradient(SkPoint *endPoints, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar *matrix33)
Definition: shaders.cpp:14
SKWASM_EXPORT void runtimeEffect_dispose(SkRuntimeEffect *effect)
Definition: shaders.cpp:116
SKWASM_EXPORT SkShader * shader_createRadialGradient(SkScalar centerX, SkScalar centerY, SkScalar radius, SkColor *colors, SkScalar *stops, int count, SkTileMode tileMode, SkScalar *matrix33)
Definition: shaders.cpp:34
#define SKWASM_EXPORT
Definition: export.h:10