10#if defined(SK_GRAPHITE)
26using namespace::skgpu::graphite;
32void empty_test(
const KeyContext& keyContext,
33 PipelineDataGatherer* gatherer,
35 PaintOptions paintOptions;
39 std::vector<UniquePaintParamsID> precompileIDs;
40 paintOptions.priv().buildCombinations(keyContext,
45 [&precompileIDs](UniquePaintParamsID
id,
49 precompileIDs.push_back(
id);
56void no_shader_option_test(
const KeyContext& keyContext,
57 PipelineDataGatherer* gatherer,
61 PaintOptions paintOptions;
62 paintOptions.setBlendModes(blendModes);
66 std::vector<UniquePaintParamsID> precompileIDs;
67 paintOptions.priv().buildCombinations(keyContext,
72 [&precompileIDs](UniquePaintParamsID
id,
76 precompileIDs.push_back(
id);
83void no_blend_mode_option_test(
const KeyContext& keyContext,
84 PipelineDataGatherer* gatherer,
86 PaintOptions paintOptions;
87 paintOptions.setShaders({ PrecompileShaders::Color() });
91 std::vector<UniquePaintParamsID> precompileIDs;
92 paintOptions.priv().buildCombinations(keyContext,
97 [&precompileIDs](UniquePaintParamsID
id,
101 precompileIDs.push_back(
id);
104 SkASSERT(precompileIDs.size() == 1);
107void big_test(
const KeyContext& keyContext,
108 PipelineDataGatherer* gatherer,
121 PaintOptions paintOptions;
131 auto blendShader_0 = PrecompileShaders::Blend(
134 PrecompileShadersPriv::LinearGradient(
true),
135 PrecompileShaders::Color()
138 PrecompileShadersPriv::LinearGradient(
true),
139 PrecompileShaders::Blend(
142 PrecompileShadersPriv::RadialGradient(
true),
143 PrecompileShaders::Color()
146 PrecompileShaders::Image()
150 paintOptions.setShaders({ sweepGrad_0, blendShader_0 });
160 paintOptions.setBlendModes(evenMoreBlendModes);
163 "Actual # of combinations %d", paintOptions.priv().numCombinations());
165 std::vector<UniquePaintParamsID> precompileIDs;
166 paintOptions.priv().buildCombinations(keyContext,
168 DrawTypeFlags::kNone,
171 [&precompileIDs](UniquePaintParamsID
id,
175 precompileIDs.push_back(
id);
178 SkASSERT(precompileIDs.size() == 256);
182std::vector<sk_sp<T>> create_runtime_combos(
188 const char* greenCode,
189 const char* combineCode) {
190 auto [redEffect, error1] = effectFactory(
SkString(redCode));
192 auto [greenEffect, error2] = effectFactory(
SkString(greenCode));
194 auto [combineEffect, error3] = effectFactory(
SkString(combineCode));
197 sk_sp<T> red = precompileFactory(redEffect, {});
200 sk_sp<T> green = precompileFactory(greenEffect, {});
203 sk_sp<T> combine = precompileFactory(combineEffect, { { red, green }, { green, red } });
209void runtime_effect_test(
const KeyContext& keyContext,
210 PipelineDataGatherer* gatherer,
225 PaintOptions paintOptions;
229 static const char* kRedS = R
"(
230 half4 main(vec2 fragcoord) { return half4(.5, 0, 0, .5); }
232 static const char* kGreenS = R
"(
233 half4 main(vec2 fragcoord) { return half4(0, .5, 0, .5); }
236 static const char* kCombineS = R
"(
237 uniform shader first;
238 uniform shader second;
239 half4 main(vec2 fragcoords) {
240 return first.eval(fragcoords) + second.eval(fragcoords);
244 std::vector<sk_sp<PrecompileShader>> combinations =
245 create_runtime_combos<PrecompileShader>(reporter,
247 MakePrecompileShader,
251 paintOptions.setShaders(combinations);
256 static const char* kRedCF = R
"(
257 half4 main(half4 color) { return half4(.5, 0, 0, .5); }
259 static const char* kGreenCF = R
"(
260 half4 main(half4 color) { return half4(0, .5, 0, .5); }
263 static const char* kCombineCF = R
"(
264 uniform colorFilter first;
265 uniform colorFilter second;
266 half4 main(half4 color) { return first.eval(color) + second.eval(color); }
269 std::vector<sk_sp<PrecompileColorFilter>> combinations =
270 create_runtime_combos<PrecompileColorFilter>(reporter,
272 MakePrecompileColorFilter,
276 paintOptions.setColorFilters(combinations);
281 static const char* kRedB = R
"(
282 half4 main(half4 src, half4 dst) { return half4(.5, 0, 0, .5); }
284 static const char* kGreenB = R
"(
285 half4 main(half4 src, half4 dst) { return half4(0, .5, 0, .5); }
288 static const char* kCombineB = R
"(
289 uniform blender first;
290 uniform blender second;
291 half4 main(half4 src, half4 dst) {
292 return first.eval(src, dst) + second.eval(src, dst);
296 std::vector<sk_sp<PrecompileBlender>> combinations =
297 create_runtime_combos<PrecompileBlender>(reporter,
299 MakePrecompileBlender,
303 paintOptions.setBlenders(combinations);
308 std::vector<UniquePaintParamsID> precompileIDs;
309 paintOptions.priv().buildCombinations(keyContext,
311 DrawTypeFlags::kNone,
314 [&precompileIDs](UniquePaintParamsID
id,
318 precompileIDs.push_back(
id);
321 SkASSERT(precompileIDs.size() == 8);
328 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
330 auto rtEffectDict = std::make_unique<RuntimeEffectDictionary>();
333 KeyContext keyContext(context->priv().caps(),
340 PipelineDataGatherer gatherer(Layout::kMetal);
342 empty_test(keyContext, &gatherer,
reporter);
343 no_shader_option_test(keyContext, &gatherer,
reporter);
344 no_blend_mode_option_test(keyContext, &gatherer,
reporter);
345 big_test(keyContext, &gatherer,
reporter);
346 runtime_effect_test(keyContext, &gatherer,
reporter);
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kSrcOver
r = s + (1-sa)*d
@ kDstOver
r = d + (1-da)*s
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
#define DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(name, reporter, graphite_ctx, ctsEnforcement)
#define REPORTER_ASSERT(r, cond,...)
static Result MakeForColorFilter(SkString sksl, const Options &)
static Result MakeForBlender(SkString sksl, const Options &)
static Result MakeForShader(SkString sksl, const Options &)