10#if defined(SK_GRAPHITE)
28using namespace::skgpu::graphite;
33static constexpr int kExpectedBlendColorFilterCombos = 1;
36static constexpr int kExpectedSolidColorCombos = 1;
37static constexpr int kExpectedGradientCombos = 3;
38static constexpr int kExpectedImageCombos = 6;
39static constexpr int kExpectedPerlinNoiseCombos = 1;
40static constexpr int kExpectedPictureCombos = 12;
41static constexpr int kExpectedRawImageCombos = 3;
45void no_blend_mode_option_test(
const KeyContext& keyContext,
46 PipelineDataGatherer* gatherer,
48 PaintOptions paintOptions;
53 std::vector<UniquePaintParamsID> precompileIDs;
54 paintOptions.priv().buildCombinations(keyContext,
59 [&precompileIDs](UniquePaintParamsID
id,
63 precompileIDs.push_back(
id);
71void run_test(
const KeyContext& keyContext,
72 PipelineDataGatherer* gatherer,
74 const PaintOptions& paintOptions,
75 int expectedNumOptions) {
79 std::vector<UniquePaintParamsID> precompileIDs;
80 paintOptions.priv().buildCombinations(keyContext,
85 [&precompileIDs](UniquePaintParamsID
id,
89 precompileIDs.push_back(
id);
92 SkASSERT(
static_cast<int>(precompileIDs.size()) == expectedNumOptions);
95void big_test(
const KeyContext& keyContext,
96 PipelineDataGatherer* gatherer,
99 static constexpr int kNumExpected = 444;
113 PaintOptions paintOptions;
142 paintOptions.setShaders({ sweepGrad_0, blendShader_0 });
152 paintOptions.setBlendModes(kEvenMoreBlendModes);
155 "Actual # of combinations %d", paintOptions.priv().numCombinations());
157 std::vector<UniquePaintParamsID> precompileIDs;
158 paintOptions.priv().buildCombinations(keyContext,
163 [&precompileIDs](UniquePaintParamsID
id,
167 precompileIDs.push_back(
id);
170 SkASSERT(precompileIDs.size() == kNumExpected);
174std::vector<sk_sp<T>> create_runtime_combos(
180 const char* greenCode,
181 const char* combineCode) {
182 auto [redEffect, error1] = effectFactory(
SkString(redCode));
184 auto [greenEffect, error2] = effectFactory(
SkString(greenCode));
186 auto [combineEffect, error3] = effectFactory(
SkString(combineCode));
189 sk_sp<T> red = precompileFactory(redEffect, {});
192 sk_sp<T> green = precompileFactory(greenEffect, {});
195 sk_sp<T> combine = precompileFactory(combineEffect, { { red, green }, { green, red } });
201void runtime_effect_test(
const KeyContext& keyContext,
202 PipelineDataGatherer* gatherer,
217 PaintOptions paintOptions;
221 static const char* kRedS = R
"(
222 half4 main(vec2 fragcoord) { return half4(.5, 0, 0, .5); }
224 static const char* kGreenS = R
"(
225 half4 main(vec2 fragcoord) { return half4(0, .5, 0, .5); }
228 static const char* kCombineS = R
"(
229 uniform shader first;
230 uniform shader second;
231 half4 main(vec2 fragcoords) {
232 return first.eval(fragcoords) + second.eval(fragcoords);
236 std::vector<sk_sp<PrecompileShader>> combinations =
237 create_runtime_combos<PrecompileShader>(reporter,
243 paintOptions.setShaders(combinations);
248 static const char* kRedCF = R
"(
249 half4 main(half4 color) { return half4(.5, 0, 0, .5); }
251 static const char* kGreenCF = R
"(
252 half4 main(half4 color) { return half4(0, .5, 0, .5); }
255 static const char* kCombineCF = R
"(
256 uniform colorFilter first;
257 uniform colorFilter second;
258 half4 main(half4 color) { return first.eval(color) + second.eval(color); }
261 std::vector<sk_sp<PrecompileColorFilter>> combinations =
262 create_runtime_combos<PrecompileColorFilter>(reporter,
268 paintOptions.setColorFilters(combinations);
273 static const char* kRedB = R
"(
274 half4 main(half4 src, half4 dst) { return half4(.5, 0, 0, .5); }
276 static const char* kGreenB = R
"(
277 half4 main(half4 src, half4 dst) { return half4(0, .5, 0, .5); }
280 static const char* kCombineB = R
"(
281 uniform blender first;
282 uniform blender second;
283 half4 main(half4 src, half4 dst) {
284 return first.eval(src, dst) + second.eval(src, dst);
288 std::vector<sk_sp<PrecompileBlender>> combinations =
289 create_runtime_combos<PrecompileBlender>(reporter,
295 paintOptions.setBlenders(combinations);
300 std::vector<UniquePaintParamsID> precompileIDs;
301 paintOptions.priv().buildCombinations(keyContext,
306 [&precompileIDs](UniquePaintParamsID
id,
310 precompileIDs.push_back(
id);
313 SkASSERT(precompileIDs.size() == 8);
317void blend_subtest(
const KeyContext& keyContext,
318 PipelineDataGatherer* gatherer,
322 PaintOptions paintOptions;
331 PaintOptions paintOptions;
339 PaintOptions paintOptions;
347void shader_subtest(
const KeyContext& keyContext,
348 PipelineDataGatherer* gatherer,
351 PaintOptions paintOptions;
361 PaintOptions paintOptions;
365 kExpectedSolidColorCombos);
379 PaintOptions paintOptions;
380 paintOptions.setShaders(
387 kExpectedSolidColorCombos *
388 kExpectedPerlinNoiseCombos);
394 PaintOptions paintOptions;
398 kExpectedImageCombos);
403 PaintOptions paintOptions;
407 kExpectedRawImageCombos);
412 PaintOptions paintOptions;
417 kExpectedPerlinNoiseCombos + kExpectedPerlinNoiseCombos);
422 PaintOptions paintOptions;
429 kExpectedGradientCombos + kExpectedGradientCombos +
430 kExpectedGradientCombos + kExpectedGradientCombos);
436 PaintOptions paintOptions;
440 kExpectedPictureCombos);
446 PaintOptions paintOptions;
447 paintOptions.setShaders(
451 kExpectedGradientCombos);
456 PaintOptions paintOptions;
457 paintOptions.setShaders(
462 kExpectedGradientCombos *
463 kExpectedBlendColorFilterCombos);
467 PaintOptions paintOptions;
468 paintOptions.setShaders(
473 kExpectedGradientCombos *
482 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
484 auto rtEffectDict = std::make_unique<RuntimeEffectDictionary>();
487 KeyContext keyContext(context->priv().caps(),
499 PaintOptions paintOptions;
504 blend_subtest(keyContext, &gatherer,
reporter);
505 shader_subtest(keyContext, &gatherer,
reporter);
507 no_blend_mode_option_test(keyContext, &gatherer,
reporter);
508 big_test(keyContext, &gatherer,
reporter);
509 runtime_effect_test(keyContext, &gatherer,
reporter);
static void run_test(GrDirectContext *dContext, skiatest::Reporter *reporter, BulkRectTest test)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kColorDodge
brighten destination to reflect source
@ kSrcOver
r = s + (1-sa)*d
@ kDstOver
r = d + (1-da)*s
@ kHardLight
multiply or screen, depending on source
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
@ 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 sk_sp< SkColorSpace > MakeSRGBLinear()
static Result MakeForColorFilter(SkString sksl, const Options &)
static Result MakeForBlender(SkString sksl, const Options &)
static Result MakeForShader(SkString sksl, const Options &)
SK_API sk_sp< SkShader > Color(SkColor)
SK_API sk_sp< SkShader > MakeTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
SK_API sk_sp< SkShader > CoordClamp(sk_sp< SkShader >, const SkRect &subset)
SK_API sk_sp< SkShader > RawImage(sk_sp< SkImage > image, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &options, const SkMatrix *localMatrix=nullptr)
SK_API sk_sp< SkShader > MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr)
SK_API sk_sp< SkShader > Empty()
SK_API sk_sp< PrecompileBlender > Arithmetic()
SK_API sk_sp< PrecompileShader > ColorFilter(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< PrecompileColorFilter > > colorFilters)
SK_API sk_sp< PrecompileShader > LocalMatrix(SkSpan< const sk_sp< PrecompileShader > > wrapped)
SK_API sk_sp< PrecompileShader > WorkingColorSpace(SkSpan< const sk_sp< PrecompileShader > > shaders, SkSpan< const sk_sp< SkColorSpace > > colorSpaces)
SK_API sk_sp< PrecompileShader > LinearGradient()
SK_API sk_sp< PrecompileShader > RadialGradient()
SK_API sk_sp< PrecompileShader > Picture()
SK_API sk_sp< PrecompileShader > SweepGradient()
SK_API sk_sp< PrecompileShader > TwoPointConicalGradient()
sk_sp< PrecompileBlender > MakePrecompileBlender(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
sk_sp< PrecompileShader > MakePrecompileShader(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)
sk_sp< PrecompileColorFilter > MakePrecompileColorFilter(sk_sp< SkRuntimeEffect > effect, SkSpan< const PrecompileChildOptions > childOptions)