81 {
82
83
84
85namespace {
86
87void add_solid_uniform_data(const ShaderCodeDictionary* dict,
89 PipelineDataGatherer* gatherer) {
91 gatherer->write(premulColor);
92}
93
94}
95
96void SolidColorShaderBlock::AddBlock(const KeyContext& keyContext,
97 PaintParamsKeyBuilder* builder,
98 PipelineDataGatherer* gatherer,
100 add_solid_uniform_data(keyContext.dict(), premulColor, gatherer);
101
102 builder->addBlock(BuiltInCodeSnippetID::kSolidColorShader);
103}
104
105
106
107namespace {
108
109void add_rgb_paint_color_uniform_data(const ShaderCodeDictionary* dict,
111 PipelineDataGatherer* gatherer) {
113 gatherer->writePaintColor(premulColor);
114}
115
116void add_alpha_only_paint_color_uniform_data(const ShaderCodeDictionary* dict,
118 PipelineDataGatherer* gatherer) {
120 gatherer->writePaintColor(premulColor);
121}
122
123}
124
125void RGBPaintColorBlock::AddBlock(const KeyContext& keyContext,
126 PaintParamsKeyBuilder* builder,
127 PipelineDataGatherer* gatherer) {
128 add_rgb_paint_color_uniform_data(keyContext.dict(), keyContext.paintColor(), gatherer);
129
130 builder->addBlock(BuiltInCodeSnippetID::kRGBPaintColor);
131}
132
133void AlphaOnlyPaintColorBlock::AddBlock(const KeyContext& keyContext,
134 PaintParamsKeyBuilder* builder,
135 PipelineDataGatherer* gatherer) {
136 add_alpha_only_paint_color_uniform_data(keyContext.dict(), keyContext.paintColor(), gatherer);
137
138 builder->addBlock(BuiltInCodeSnippetID::kAlphaOnlyPaintColor);
139}
140
141
142
143namespace {
144
145void add_dst_read_sample_uniform_data(const ShaderCodeDictionary* dict,
146 PipelineDataGatherer* gatherer,
151
153
154 SkV4 coords{
static_cast<float>(dstOffset.
x()),
155 static_cast<float>(dstOffset.
y()),
156 dstTexture ? 1.0f / dstTexture->dimensions().width() : 1.0f,
157 dstTexture ? 1.0f / dstTexture->dimensions().height() : 1.0f };
158 gatherer->write(coords);
159}
160
161}
162
163void DstReadSampleBlock::AddBlock(const KeyContext& keyContext,
164 PaintParamsKeyBuilder* builder,
165 PipelineDataGatherer* gatherer,
168 add_dst_read_sample_uniform_data(keyContext.dict(), gatherer, std::move(dstTexture), dstOffset);
169
170 builder->addBlock(BuiltInCodeSnippetID::kDstReadSample);
171}
172
173
174
175namespace {
176
177void add_gradient_preamble(const GradientShaderBlocks::GradientData& gradData,
178 PipelineDataGatherer* gatherer) {
179 constexpr int kInternalStopLimit = GradientShaderBlocks::GradientData::kNumInternalStorageStops;
180
181 if (gradData.fNumStops <= kInternalStopLimit) {
182 if (gradData.fNumStops <= 4) {
183
184 gatherer->writeArray(
SkSpan{gradData.fColors, 4});
185 gatherer->write(gradData.fOffsets[0]);
186 } else if (gradData.fNumStops <= 8) {
187
188 gatherer->writeArray(
SkSpan{gradData.fColors, 8});
189 gatherer->writeArray(
SkSpan{gradData.fOffsets, 2});
190 } else {
191
193 }
194 }
195}
196
197
198
199
200
201
202void add_gradient_postamble(const GradientShaderBlocks::GradientData& gradData,
203 PipelineDataGatherer* gatherer) {
205
206 constexpr int kInternalStopLimit = GradientShaderBlocks::GradientData::kNumInternalStorageStops;
207
208 static_assert(static_cast<int>(ColorSpace::kLab) == 2);
209 static_assert(static_cast<int>(ColorSpace::kOKLab) == 3);
210 static_assert(static_cast<int>(ColorSpace::kOKLabGamutMap) == 4);
211 static_assert(static_cast<int>(ColorSpace::kLCH) == 5);
212 static_assert(static_cast<int>(ColorSpace::kOKLCH) == 6);
213 static_assert(static_cast<int>(ColorSpace::kOKLCHGamutMap) == 7);
214 static_assert(static_cast<int>(ColorSpace::kHSL) == 9);
215 static_assert(static_cast<int>(ColorSpace::kHWB) == 10);
216
217 bool inputPremul = static_cast<bool>(gradData.fInterpolation.fInPremul);
218
219 if (gradData.fNumStops > kInternalStopLimit) {
220 gatherer->write(gradData.fNumStops);
221 }
222
223 gatherer->write(static_cast<int>(gradData.fTM));
224 gatherer->write(static_cast<int>(gradData.fInterpolation.fColorSpace));
225 gatherer->write(static_cast<int>(inputPremul));
226}
227
228void add_linear_gradient_uniform_data(const ShaderCodeDictionary* dict,
229 BuiltInCodeSnippetID codeSnippetID,
230 const GradientShaderBlocks::GradientData& gradData,
231 PipelineDataGatherer* gatherer) {
233
234 add_gradient_preamble(gradData, gatherer);
235 gatherer->write(gradData.fPoints[0]);
236 gatherer->write(gradData.fPoints[1]);
237 add_gradient_postamble(gradData, gatherer);
238};
239
240void add_radial_gradient_uniform_data(const ShaderCodeDictionary* dict,
241 BuiltInCodeSnippetID codeSnippetID,
242 const GradientShaderBlocks::GradientData& gradData,
243 PipelineDataGatherer* gatherer) {
245
246 add_gradient_preamble(gradData, gatherer);
247 gatherer->write(gradData.fPoints[0]);
248 gatherer->write(gradData.fRadii[0]);
249 add_gradient_postamble(gradData, gatherer);
250};
251
252void add_sweep_gradient_uniform_data(const ShaderCodeDictionary* dict,
253 BuiltInCodeSnippetID codeSnippetID,
254 const GradientShaderBlocks::GradientData& gradData,
255 PipelineDataGatherer* gatherer) {
257
258 add_gradient_preamble(gradData, gatherer);
259 gatherer->write(gradData.fPoints[0]);
260 gatherer->write(gradData.fBias);
261 gatherer->write(gradData.fScale);
262 add_gradient_postamble(gradData, gatherer);
263};
264
265void add_conical_gradient_uniform_data(const ShaderCodeDictionary* dict,
266 BuiltInCodeSnippetID codeSnippetID,
267 const GradientShaderBlocks::GradientData& gradData,
268 PipelineDataGatherer* gatherer) {
270
271 add_gradient_preamble(gradData, gatherer);
272 gatherer->write(gradData.fPoints[0]);
273 gatherer->write(gradData.fPoints[1]);
274 gatherer->write(gradData.fRadii[0]);
275 gatherer->write(gradData.fRadii[1]);
276 add_gradient_postamble(gradData, gatherer);
277};
278
279}
280
283 , fPoints{{0.0f, 0.0f}, {0.0f, 0.0f}}
284 , fRadii{0.0f, 0.0f}
285 , fBias(0.0f)
286 , fScale(0.0f)
288 , fNumStops(numStops) {
290 sk_bzero(fOffsets,
sizeof(fOffsets));
291}
292
295 float radius0, float radius1,
296 float bias,
float scale,
298 int numStops,
300 const float* offsets,
304 , fBias(bias)
306 , fTM(tm)
307 , fNumStops(numStops)
308 , fInterpolation(
interp) {
310
311 fPoints[0] = point0;
312 fPoints[1] = point1;
313 fRadii[0] = radius0;
314 fRadii[1] = radius1;
315
316 if (fNumStops <= kNumInternalStorageStops) {
317 memcpy(fColors, colors, fNumStops *
sizeof(
SkColor4f));
318 float* rawOffsets = fOffsets[0].ptr();
319 if (offsets) {
320 memcpy(rawOffsets, offsets, fNumStops * sizeof(float));
321 } else {
322 for (int i = 0; i < fNumStops; ++i) {
324 }
325 }
326
327
328
329 for (int i = fNumStops; i < kNumInternalStorageStops; ++i) {
330 fColors[i] = fColors[fNumStops-1];
331 rawOffsets[i] = rawOffsets[fNumStops-1];
332 }
333 } else {
334 fColorsAndOffsetsProxy = std::move(colorsAndOffsetsProxy);
336 }
337}
338
339void GradientShaderBlocks::AddBlock(const KeyContext& keyContext,
340 PaintParamsKeyBuilder* builder,
341 PipelineDataGatherer* gatherer,
342 const GradientData& gradData) {
343 auto dict = keyContext.dict();
344
345 if (gradData.fNumStops > GradientData::kNumInternalStorageStops && gatherer) {
346 SkASSERT(gradData.fColorsAndOffsetsProxy);
347
350 gatherer->add(
kNearest, kClampTiling, gradData.fColorsAndOffsetsProxy);
351 }
352
354 switch (gradData.fType) {
355 case SkShaderBase::GradientType::kLinear:
356 codeSnippetID =
357 gradData.fNumStops <= 4 ? BuiltInCodeSnippetID::kLinearGradientShader4
358 : gradData.fNumStops <= 8 ? BuiltInCodeSnippetID::kLinearGradientShader8
359 : BuiltInCodeSnippetID::kLinearGradientShaderTexture;
360 add_linear_gradient_uniform_data(dict, codeSnippetID, gradData, gatherer);
361 break;
362 case SkShaderBase::GradientType::kRadial:
363 codeSnippetID =
364 gradData.fNumStops <= 4 ? BuiltInCodeSnippetID::kRadialGradientShader4
365 : gradData.fNumStops <= 8 ? BuiltInCodeSnippetID::kRadialGradientShader8
366 : BuiltInCodeSnippetID::kRadialGradientShaderTexture;
367 add_radial_gradient_uniform_data(dict, codeSnippetID, gradData, gatherer);
368 break;
369 case SkShaderBase::GradientType::kSweep:
370 codeSnippetID =
371 gradData.fNumStops <= 4 ? BuiltInCodeSnippetID::kSweepGradientShader4
372 : gradData.fNumStops <= 8 ? BuiltInCodeSnippetID::kSweepGradientShader8
373 : BuiltInCodeSnippetID::kSweepGradientShaderTexture;
374 add_sweep_gradient_uniform_data(dict, codeSnippetID, gradData, gatherer);
375 break;
376 case SkShaderBase::GradientType::kConical:
377 codeSnippetID =
378 gradData.fNumStops <= 4 ? BuiltInCodeSnippetID::kConicalGradientShader4
379 : gradData.fNumStops <= 8 ? BuiltInCodeSnippetID::kConicalGradientShader8
380 : BuiltInCodeSnippetID::kConicalGradientShaderTexture;
381 add_conical_gradient_uniform_data(dict, codeSnippetID, gradData, gatherer);
382 break;
384 default:
385 SkDEBUGFAIL(
"Expected a gradient shader, but it wasn't one.");
386 break;
387 }
388
389 builder->addBlock(codeSnippetID);
390}
391
392
393
394namespace {
395
396void add_localmatrixshader_uniform_data(const ShaderCodeDictionary* dict,
397 const SkM44& localMatrix,
398 PipelineDataGatherer* gatherer) {
400
402 bool wasInverted = localMatrix.
invert(&lmInverse);
403 if (!wasInverted) {
405 }
406
407 gatherer->write(lmInverse);
408}
409
410}
411
412void LocalMatrixShaderBlock::BeginBlock(const KeyContext& keyContext,
413 PaintParamsKeyBuilder* builder,
414 PipelineDataGatherer* gatherer,
415 const LMShaderData& lmShaderData) {
416
417 add_localmatrixshader_uniform_data(keyContext.dict(), lmShaderData.fLocalMatrix, gatherer);
418
419 builder->beginBlock(BuiltInCodeSnippetID::kLocalMatrixShader);
420}
421
422
423
424namespace {
425
426static constexpr int kColorSpaceXformFlagAlphaSwizzle = 0x20;
427
429 ReadSwizzle readSwizzle,
430 PipelineDataGatherer* gatherer) {
431
432
433
434
436
437 int colorXformFlags = SkTo<int>(steps.
flags.
mask());
438 if (readSwizzle != ReadSwizzle::kRGBA) {
439
442 colorXformFlags |= SkTo<int>(gamutSteps.
flags.
mask());
443 if (readSwizzle != ReadSwizzle::kBGRA) {
444
445 SkASSERT(colorXformFlags < kColorSpaceXformFlagAlphaSwizzle);
446 colorXformFlags |= kColorSpaceXformFlagAlphaSwizzle;
447 }
448 }
449 gatherer->write(colorXformFlags);
450
455 } else {
456 gatherer->write(SkTo<int>(skcms_TFType::skcms_TFType_Invalid));
457 }
458
460 const float identity[] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
461
462
464 if (readSwizzle == ReadSwizzle::kRRR1) {
465 gamutTransform.
setAll(m[0] + m[3] + m[6], 0, 0,
466 m[1] + m[4] + m[7], 0, 0,
467 m[2] + m[5] + m[8], 0, 0);
468 } else if (readSwizzle == ReadSwizzle::kBGRA) {
469 gamutTransform.
setAll(m[6], m[3], m[0],
470 m[7], m[4], m[1],
471 m[8], m[5], m[2]);
472 } else if (readSwizzle == ReadSwizzle::k000R) {
473 gamutTransform.
setAll(0, 0, 0,
474 0, 0, 0,
475 0, 0, 0);
477 gamutTransform.
setAll(m[0], m[3], m[6],
478 m[1], m[4], m[7],
479 m[2], m[5], m[8]);
480 }
481 gatherer->writeHalf(gamutTransform);
482
487 } else {
488 gatherer->write(SkTo<int>(skcms_TFType::skcms_TFType_Invalid));
489 }
490
491
492 switch (readSwizzle) {
493 case ReadSwizzle::k000R:
496 break;
497 case ReadSwizzle::kRGB1:
498 case ReadSwizzle::kRRR1:
501 break;
502 default:
505 break;
506 }
507
508 gatherer->writeHalf(coeffs);
509}
510
511void add_image_uniform_data(const ShaderCodeDictionary* dict,
512 const ImageShaderBlock::ImageData& imgData,
513 PipelineDataGatherer* gatherer) {
514 SkASSERT(!imgData.fSampling.useCubic);
516
517 gatherer->write(
SkSize::Make(1.f/imgData.fImgSize.width(), 1.f/imgData.fImgSize.height()));
518 gatherer->write(imgData.fSubset);
519 gatherer->write(SkTo<int>(imgData.fTileModes[0]));
520 gatherer->write(SkTo<int>(imgData.fTileModes[1]));
521 gatherer->write(SkTo<int>(imgData.fSampling.filter));
522
523 add_color_space_uniforms(imgData.fSteps, imgData.fReadSwizzle, gatherer);
524}
525
526void add_cubic_image_uniform_data(const ShaderCodeDictionary* dict,
527 const ImageShaderBlock::ImageData& imgData,
528 PipelineDataGatherer* gatherer) {
529 SkASSERT(imgData.fSampling.useCubic);
531
532 gatherer->write(
SkSize::Make(1.f/imgData.fImgSize.width(), 1.f/imgData.fImgSize.height()));
533 gatherer->write(imgData.fSubset);
534 gatherer->write(SkTo<int>(imgData.fTileModes[0]));
535 gatherer->write(SkTo<int>(imgData.fTileModes[1]));
538
539 add_color_space_uniforms(imgData.fSteps, imgData.fReadSwizzle, gatherer);
540}
541
542void add_hw_image_uniform_data(const ShaderCodeDictionary* dict,
543 const ImageShaderBlock::ImageData& imgData,
544 PipelineDataGatherer* gatherer) {
545 SkASSERT(!imgData.fSampling.useCubic);
547
548 gatherer->write(
SkSize::Make(1.f/imgData.fImgSize.width(), 1.f/imgData.fImgSize.height()));
549
550 add_color_space_uniforms(imgData.fSteps, imgData.fReadSwizzle, gatherer);
551}
552
553}
554
560 ReadSwizzle readSwizzle)
562 , fTileModes{tileModeX, tileModeY}
563 , fImgSize(imgSize)
564 , fSubset(subset)
565 , fReadSwizzle(readSwizzle) {
567}
568
569static bool can_do_tiling_in_hw(
const Caps* caps,
const ImageShaderBlock::ImageData& imgData) {
572 return false;
573 }
574 return imgData.fSubset.contains(
SkRect::Make(imgData.fImgSize));
575}
576
577void ImageShaderBlock::AddBlock(const KeyContext& keyContext,
578 PaintParamsKeyBuilder* builder,
579 PipelineDataGatherer* gatherer,
581
582 if (keyContext.recorder() && !imgData.fTextureProxy) {
583 builder->addBlock(BuiltInCodeSnippetID::kError);
584 return;
585 }
586
587 const Caps* caps = keyContext.caps();
588 const bool doTilingInHw = !imgData.fSampling.useCubic &&
can_do_tiling_in_hw(caps, imgData);
589
591 gatherer->add(imgData.fSampling,
592 doTilingInHw ? imgData.fTileModes : kDefaultTileModes,
593 imgData.fTextureProxy);
594
595 if (doTilingInHw) {
596 add_hw_image_uniform_data(keyContext.dict(), imgData, gatherer);
597 builder->addBlock(BuiltInCodeSnippetID::kHWImageShader);
598 } else if (imgData.fSampling.useCubic) {
599 add_cubic_image_uniform_data(keyContext.dict(), imgData, gatherer);
600 builder->addBlock(BuiltInCodeSnippetID::kCubicImageShader);
601 } else {
602 add_image_uniform_data(keyContext.dict(), imgData, gatherer);
603 builder->addBlock(BuiltInCodeSnippetID::kImageShader);
604 }
605}
606
607
608
609
610namespace {
611
612void add_yuv_image_uniform_data(const ShaderCodeDictionary* dict,
613 const YUVImageShaderBlock::ImageData& imgData,
614 PipelineDataGatherer* gatherer) {
616
617 gatherer->write(
SkSize::Make(1.f/imgData.fImgSize.width(), 1.f/imgData.fImgSize.height()));
618 gatherer->write(
SkSize::Make(1.f/imgData.fImgSizeUV.width(), 1.f/imgData.fImgSizeUV.height()));
619 gatherer->write(imgData.fSubset);
620 gatherer->write(imgData.fLinearFilterUVInset);
621 gatherer->write(SkTo<int>(imgData.fTileModes[0]));
622 gatherer->write(SkTo<int>(imgData.fTileModes[1]));
623 gatherer->write(SkTo<int>(imgData.fSampling.filter));
624 gatherer->write(SkTo<int>(imgData.fSamplingUV.filter));
625
626 for (int i = 0; i < 4; ++i) {
627 gatherer->writeHalf(imgData.fChannelSelect[i]);
628 }
629 gatherer->writeHalf(imgData.fYUVtoRGBMatrix);
630 gatherer->write(imgData.fYUVtoRGBTranslate);
631}
632
633void add_cubic_yuv_image_uniform_data(const ShaderCodeDictionary* dict,
634 const YUVImageShaderBlock::ImageData& imgData,
635 PipelineDataGatherer* gatherer) {
637
638 gatherer->write(
SkSize::Make(1.f/imgData.fImgSize.width(), 1.f/imgData.fImgSize.height()));
639 gatherer->write(
SkSize::Make(1.f/imgData.fImgSizeUV.width(), 1.f/imgData.fImgSizeUV.height()));
640 gatherer->write(imgData.fSubset);
641 gatherer->write(SkTo<int>(imgData.fTileModes[0]));
642 gatherer->write(SkTo<int>(imgData.fTileModes[1]));
645
646 for (int i = 0; i < 4; ++i) {
647 gatherer->writeHalf(imgData.fChannelSelect[i]);
648 }
649 gatherer->writeHalf(imgData.fYUVtoRGBMatrix);
650 gatherer->write(imgData.fYUVtoRGBTranslate);
651}
652
653}
654
662 , fTileModes{tileModeX, tileModeY}
663 , fImgSize(imgSize)
664 , fImgSizeUV(imgSize)
665 , fSubset(subset) {
666}
667
668void YUVImageShaderBlock::AddBlock(const KeyContext& keyContext,
669 PaintParamsKeyBuilder* builder,
670 PipelineDataGatherer* gatherer,
672 if (keyContext.recorder() &&
673 (!imgData.fTextureProxies[0] || !imgData.fTextureProxies[1] ||
674 !imgData.fTextureProxies[2] || !imgData.fTextureProxies[3])) {
675 builder->addBlock(BuiltInCodeSnippetID::kError);
676 return;
677 }
678
683 gatherer->add(imgData.fSampling, imgData.fTileModes, imgData.fTextureProxies[0]);
684 gatherer->add(imgData.fSamplingUV, uvTileModes, imgData.fTextureProxies[1]);
685 gatherer->add(imgData.fSamplingUV, uvTileModes, imgData.fTextureProxies[2]);
686 gatherer->add(imgData.fSampling, imgData.fTileModes, imgData.fTextureProxies[3]);
687
688 if (imgData.fSampling.useCubic) {
689 add_cubic_yuv_image_uniform_data(keyContext.dict(), imgData, gatherer);
690 builder->addBlock(BuiltInCodeSnippetID::kCubicYUVImageShader);
691 } else {
692 add_yuv_image_uniform_data(keyContext.dict(), imgData, gatherer);
693 builder->addBlock(BuiltInCodeSnippetID::kYUVImageShader);
694 }
695}
696
697
698
699namespace {
700
701void add_coordclamp_uniform_data(const ShaderCodeDictionary* dict,
702 const CoordClampShaderBlock::CoordClampData& clampData,
703 PipelineDataGatherer* gatherer) {
705
706 gatherer->write(clampData.fSubset);
707}
708
709}
710
711void CoordClampShaderBlock::BeginBlock(const KeyContext& keyContext,
712 PaintParamsKeyBuilder* builder,
713 PipelineDataGatherer* gatherer,
714 const CoordClampData& clampData) {
715 add_coordclamp_uniform_data(keyContext.dict(), clampData, gatherer);
716
717 builder->beginBlock(BuiltInCodeSnippetID::kCoordClampShader);
718}
719
720
721
722namespace {
723
724void add_dither_uniform_data(const ShaderCodeDictionary* dict,
725 const DitherShaderBlock::DitherData& ditherData,
726 PipelineDataGatherer* gatherer) {
728
729 gatherer->writeHalf(ditherData.fRange);
730}
731
732}
733
734void DitherShaderBlock::AddBlock(const KeyContext& keyContext,
735 PaintParamsKeyBuilder* builder,
736 PipelineDataGatherer* gatherer,
737 const DitherData& data) {
738 add_dither_uniform_data(keyContext.dict(), data, gatherer);
739
742
745
746 builder->addBlock(BuiltInCodeSnippetID::kDitherShader);
747}
748
749
750
751namespace {
752
753void add_perlin_noise_uniform_data(const ShaderCodeDictionary* dict,
754 const PerlinNoiseShaderBlock::PerlinNoiseData& noiseData,
755 PipelineDataGatherer* gatherer) {
757
758 gatherer->write(noiseData.fBaseFrequency);
759 gatherer->write(noiseData.fStitchData);
760 gatherer->write(static_cast<int>(noiseData.fType));
761 gatherer->write(noiseData.fNumOctaves);
762 gatherer->write(static_cast<int>(noiseData.stitching()));
763
766
767 gatherer->add(kNearestSampling, kRepeatXTileModes, noiseData.fPermutationsProxy);
768 gatherer->add(kNearestSampling, kRepeatXTileModes, noiseData.fNoiseProxy);
769}
770
771}
772
773void PerlinNoiseShaderBlock::AddBlock(const KeyContext& keyContext,
774 PaintParamsKeyBuilder* builder,
775 PipelineDataGatherer* gatherer,
776 const PerlinNoiseData& noiseData) {
777 add_perlin_noise_uniform_data(keyContext.dict(), noiseData, gatherer);
778
779 builder->addBlock(BuiltInCodeSnippetID::kPerlinNoiseShader);
780}
781
782
783
784void BlendShaderBlock::BeginBlock(const KeyContext& keyContext,
785 PaintParamsKeyBuilder* builder,
786 PipelineDataGatherer* gatherer) {
787 VALIDATE_UNIFORMS(gatherer, keyContext.dict(), BuiltInCodeSnippetID::kBlendShader)
788
789 builder->beginBlock(BuiltInCodeSnippetID::kBlendShader);
790}
791
792
793
794void BlendModeBlenderBlock::AddBlock(const KeyContext& keyContext,
795 PaintParamsKeyBuilder* builder,
796 PipelineDataGatherer* gatherer,
798 VALIDATE_UNIFORMS(gatherer, keyContext.dict(), BuiltInCodeSnippetID::kBlendModeBlender)
799 gatherer->write(SkTo<int>(blendMode));
800
801 builder->addBlock(BuiltInCodeSnippetID::kBlendModeBlender);
802}
803
804
805
806void CoeffBlenderBlock::AddBlock(const KeyContext& keyContext,
807 PaintParamsKeyBuilder* builder,
808 PipelineDataGatherer* gatherer,
810 VALIDATE_UNIFORMS(gatherer, keyContext.dict(), BuiltInCodeSnippetID::kCoeffBlender)
813
814 builder->addBlock(BuiltInCodeSnippetID::kCoeffBlender);
815}
816
817
818
819void ClipShaderBlock::BeginBlock(const KeyContext& keyContext,
820 PaintParamsKeyBuilder* builder,
821 PipelineDataGatherer* gatherer) {
822 VALIDATE_UNIFORMS(gatherer, keyContext.dict(), BuiltInCodeSnippetID::kClipShader)
823
824 builder->beginBlock(BuiltInCodeSnippetID::kClipShader);
825}
826
827
828
829void ComposeBlock::BeginBlock(const KeyContext& keyContext,
830 PaintParamsKeyBuilder* builder,
831 PipelineDataGatherer* gatherer) {
832 builder->beginBlock(BuiltInCodeSnippetID::kCompose);
833}
834
835
836
837namespace {
838
839void add_matrix_colorfilter_uniform_data(const ShaderCodeDictionary* dict,
840 const MatrixColorFilterBlock::MatrixColorFilterData& data,
841 PipelineDataGatherer* gatherer) {
843 gatherer->write(
data.fMatrix);
844 gatherer->write(
data.fTranslate);
845 gatherer->write(
static_cast<int>(
data.fInHSLA));
846}
847
848}
849
850void MatrixColorFilterBlock::AddBlock(const KeyContext& keyContext,
851 PaintParamsKeyBuilder* builder,
852 PipelineDataGatherer* gatherer,
853 const MatrixColorFilterData& matrixCFData) {
854
855 add_matrix_colorfilter_uniform_data(keyContext.dict(), matrixCFData, gatherer);
856
857 builder->addBlock(BuiltInCodeSnippetID::kMatrixColorFilter);
858}
859
860
861
862namespace {
863
864void add_table_colorfilter_uniform_data(const ShaderCodeDictionary* dict,
865 const TableColorFilterBlock::TableColorFilterData& data,
866 PipelineDataGatherer* gatherer) {
868
871}
872
873}
874
875void TableColorFilterBlock::AddBlock(const KeyContext& keyContext,
876 PaintParamsKeyBuilder* builder,
877 PipelineDataGatherer* gatherer,
878 const TableColorFilterData& data) {
880
881 add_table_colorfilter_uniform_data(keyContext.dict(), data, gatherer);
882
883 builder->addBlock(BuiltInCodeSnippetID::kTableColorFilter);
884}
885
886
887namespace {
888
889void add_color_space_xform_uniform_data(
890 const ShaderCodeDictionary* dict,
891 const ColorSpaceTransformBlock::ColorSpaceTransformData& data,
892 PipelineDataGatherer* gatherer) {
893
894 VALIDATE_UNIFORMS(gatherer, dict, BuiltInCodeSnippetID::kColorSpaceXformColorFilter)
895 add_color_space_uniforms(
data.fSteps, ReadSwizzle::kRGBA, gatherer);
896}
897
898}
899
900ColorSpaceTransformBlock::ColorSpaceTransformData::ColorSpaceTransformData(
const SkColorSpace* src,
904 : fSteps(
src, srcAT,
dst, dstAT) {}
905
906void ColorSpaceTransformBlock::AddBlock(const KeyContext& keyContext,
907 PaintParamsKeyBuilder* builder,
908 PipelineDataGatherer* gatherer,
909 const ColorSpaceTransformData& data) {
910 add_color_space_xform_uniform_data(keyContext.dict(), data, gatherer);
911 builder->addBlock(BuiltInCodeSnippetID::kColorSpaceXformColorFilter);
912}
913
914
915
917 PaintParamsKeyBuilder* builder,
918 PipelineDataGatherer* gatherer,
921 Blend(keyContext, builder, gatherer,
922 [&] () -> void {
923
924
925
926
927
928 BlendModeBlenderBlock::AddBlock(keyContext, builder, gatherer, bm);
929 },
930 [&]() -> void {
931 SolidColorShaderBlock::AddBlock(keyContext, builder, gatherer, srcColor);
932 },
933 [&]() -> void {
934 builder->addBlock(BuiltInCodeSnippetID::kPriorOutput);
935 });
936}
937
939 : fEffect(
std::move(effect)) {}
940
943 : fEffect(
std::move(effect))
944 , fUniforms(
std::move(uniforms)) {}
945
947
948
949 return a ?
a->equals(
b) : (
a ==
b);
950}
951
952bool RuntimeEffectBlock::ShaderData::operator==(const ShaderData& rhs) const {
953 return fEffect == rhs.fEffect &&
skdata_matches(fUniforms.get(), rhs.fUniforms.get());
954}
955
959 const SkData* uniformData,
960 PipelineDataGatherer* gatherer) {
961 if (!uniformData) {
962 return;
963 }
964
965 SkDEBUGCODE(UniformExpectationsValidator uev(gatherer, graphiteUniforms);)
966
968
969 if (!rtsUniforms.empty() && uniformData) {
970
971 const uint8_t* uniformBase = uniformData->
bytes();
972 for (size_t index = 0; index < rtsUniforms.size(); ++index) {
973 const Uniform& uniform = graphiteUniforms[index];
974
975 const uint8_t* uniformPtr = uniformBase + rtsUniforms[index].offset;
976
977 gatherer->write(uniform, uniformPtr);
978 }
979 }
980
982 SkColorSpace* dstCS = keyContext.dstColorInfo().colorSpace();
983 if (!dstCS) {
985 }
986
987
988
989 ColorSpaceTransformBlock::ColorSpaceTransformData dstToLinear(dstCS,
995 dstCS,
997
998 add_color_space_uniforms(dstToLinear.fSteps, ReadSwizzle::kRGBA, gatherer);
999 add_color_space_uniforms(linearToDst.fSteps, ReadSwizzle::kRGBA, gatherer);
1000 }
1001}
1002
1003void RuntimeEffectBlock::BeginBlock(const KeyContext& keyContext,
1004 PaintParamsKeyBuilder* builder,
1005 PipelineDataGatherer* gatherer,
1006 const ShaderData& shaderData) {
1007 ShaderCodeDictionary* dict = keyContext.dict();
1008 int codeSnippetID = dict->findOrCreateRuntimeEffectSnippet(shaderData.fEffect.get());
1009
1011 keyContext.rtEffectDict()->set(codeSnippetID, shaderData.fEffect);
1012 }
1013
1014 const ShaderSnippet* entry = dict->getEntry(codeSnippetID);
1016
1018 shaderData.fEffect.get(),
1019 entry->fUniforms,
1020 shaderData.fUniforms.get(),
1021 gatherer);
1022
1023 builder->beginBlock(codeSnippetID);
1024}
1025
1026
1027
1028namespace {
1029
1031 PaintParamsKeyBuilder* builder,
1032 PipelineDataGatherer* gatherer,
1035
1037}
1038
1039
1040void add_children_to_key(const KeyContext& keyContext,
1041 PaintParamsKeyBuilder* builder,
1042 PipelineDataGatherer* gatherer,
1046
1048
1049 KeyContextWithScope childContext(keyContext, KeyContext::Scope::kRuntimeEffect);
1050
1051 for (
size_t index = 0; index < children.
size(); ++index) {
1053 std::optional<ChildType>
type = child.
type();
1054 if (
type == ChildType::kShader) {
1056 }
else if (
type == ChildType::kColorFilter) {
1058 }
else if (
type == ChildType::kBlender) {
1060 } else {
1061
1062 switch (childInfo[index].
type) {
1063 case ChildType::kShader:
1064
1065 SolidColorShaderBlock::AddBlock(childContext, builder, gatherer,
1067 break;
1068
1069 case ChildType::kColorFilter:
1070
1071 builder->addBlock(BuiltInCodeSnippetID::kPriorOutput);
1072 break;
1073
1074 case ChildType::kBlender:
1075
1077 break;
1078 }
1079 }
1080 }
1081}
1082
1084 PaintParamsKeyBuilder* builder,
1085 PipelineDataGatherer* gatherer,
1091 effect->uniforms(),
1093 keyContext.dstColorInfo().colorSpace());
1095
1096 RuntimeEffectBlock::BeginBlock(keyContext, builder, gatherer,
1097 { effect, std::move(uniforms) });
1098
1099 add_children_to_key(keyContext, builder, gatherer,
1100 blender->
children(), effect->children());
1101
1103}
1104
1106 DrawContext* drawContext,
1108 for (const auto& child : children) {
1109 if (child.
type().has_value()) {
1110 switch (*child.
type()) {
1111 case SkRuntimeEffect::ChildType::kShader:
1113 break;
1114 case SkRuntimeEffect::ChildType::kColorFilter:
1116 break;
1117 case SkRuntimeEffect::ChildType::kBlender:
1119 break;
1120 }
1121 }
1122 }
1123}
1124
1125}
1126
1127void AddToKey(
const KeyContext& keyContext,
1128 PaintParamsKeyBuilder* builder,
1129 PipelineDataGatherer* gatherer,
1131 if (!blender) {
1132 return;
1133 }
1135#define M(type) \
1136 case SkBlenderBase::BlenderType::k##type: \
1137 add_to_key(keyContext, \
1138 builder, \
1139 gatherer, \
1140 static_cast<const Sk##type##Blender*>(blender)); \
1141 return;
1143#undef M
1144 }
1146}
1147
1149 if (!blender) {
1150 return;
1151 }
1152 if (
as_BB(blender)->
type() == SkBlenderBase::BlenderType::kRuntime) {
1155 }
1156}
1157
1158
1159
1164}
1165static void add_to_key(
const KeyContext& keyContext,
1166 PaintParamsKeyBuilder* builder,
1167 PipelineDataGatherer* gatherer,
1170
1172 keyContext.dstColorInfo().colorSpace());
1173
1175}
1176
1177static void add_to_key(
const KeyContext& keyContext,
1178 PaintParamsKeyBuilder* builder,
1179 PipelineDataGatherer* gatherer,
1182
1184 ColorSpaceTransformBlock::ColorSpaceTransformData csData(filter->
src().
get(), kAlphaType,
1185 filter->
dst().
get(), kAlphaType);
1186 ColorSpaceTransformBlock::AddBlock(keyContext, builder, gatherer, csData);
1187}
1188
1189static void add_to_key(
const KeyContext& keyContext,
1190 PaintParamsKeyBuilder* keyBuilder,
1191 PipelineDataGatherer* gatherer,
1194
1195 Compose(keyContext, keyBuilder, gatherer,
1196 [&]() -> void {
1198 },
1199 [&]() -> void {
1201 });
1202}
1203
1204static void add_to_key(
const KeyContext& keyContext,
1205 PaintParamsKeyBuilder* builder,
1206 PipelineDataGatherer* gatherer,
1208 builder->addBlock(BuiltInCodeSnippetID::kGaussianColorFilter);
1209}
1210
1211static void add_to_key(
const KeyContext& keyContext,
1212 PaintParamsKeyBuilder* builder,
1213 PipelineDataGatherer* gatherer,
1216
1218 MatrixColorFilterBlock::MatrixColorFilterData matrixCFData(filter->
matrix(), inHSLA);
1219
1220 MatrixColorFilterBlock::AddBlock(keyContext, builder, gatherer, matrixCFData);
1221}
1222
1223static void add_to_key(
const KeyContext& keyContext,
1224 PaintParamsKeyBuilder* builder,
1225 PipelineDataGatherer* gatherer,
1228
1231 effect->uniforms(), filter->
uniforms(), keyContext.dstColorInfo().colorSpace());
1233
1234 RuntimeEffectBlock::BeginBlock(keyContext, builder, gatherer, {effect, std::move(uniforms)});
1235
1236 add_children_to_key(keyContext, builder, gatherer,
1237 filter->
children(), effect->children());
1238
1240}
1241
1242static void add_to_key(
const KeyContext& keyContext,
1243 PaintParamsKeyBuilder* builder,
1244 PipelineDataGatherer* gatherer,
1247
1250 if (!proxy) {
1251 SKGPU_LOG_W(
"Couldn't create TableColorFilter's table");
1252
1253
1254 builder->addBlock(BuiltInCodeSnippetID::kPriorOutput);
1255 return;
1256 }
1257
1258 TableColorFilterBlock::TableColorFilterData
data(std::move(proxy));
1259
1260 TableColorFilterBlock::AddBlock(keyContext, builder, gatherer, data);
1261}
1262
1263static void add_to_key(
const KeyContext& keyContext,
1264 PaintParamsKeyBuilder* builder,
1265 PipelineDataGatherer* gatherer,
1268
1269 const SkColorInfo& dstInfo = keyContext.dstColorInfo();
1272 if (!dstCS) {
1274 }
1275
1279 KeyContextWithColorInfo workingContext(keyContext, workingInfo);
1280
1281
1282
1283 Compose(keyContext, builder, gatherer,
1284 [&]() -> void {
1285
1286 Compose(keyContext, builder, gatherer,
1287 [&]() -> void {
1288
1289 ColorSpaceTransformBlock::ColorSpaceTransformData data1(
1290 dstCS.
get(), dstAT, workingCS.
get(), workingAT);
1291 ColorSpaceTransformBlock::AddBlock(keyContext, builder, gatherer,
1292 data1);
1293 },
1294 [&]() -> void {
1295
1297 });
1298 },
1299 [&]() -> void {
1300
1301 ColorSpaceTransformBlock::ColorSpaceTransformData data2(
1302 workingCS.
get(), workingAT, dstCS.
get(), dstAT);
1303 ColorSpaceTransformBlock::AddBlock(keyContext, builder, gatherer, data2);
1304 });
1305}
1306
1307void AddToKey(
const KeyContext& keyContext,
1308 PaintParamsKeyBuilder* builder,
1309 PipelineDataGatherer* gatherer,
1311 if (!filter) {
1312 return;
1313 }
1316
1317 builder->addBlock(BuiltInCodeSnippetID::kPriorOutput);
1318 return;
1319#define M(type) \
1320 case SkColorFilterBase::Type::k##type: \
1321 add_to_key(keyContext, \
1322 builder, \
1323 gatherer, \
1324 static_cast<const Sk##type##ColorFilter*>(filter)); \
1325 return;
1327#undef M
1328 }
1330}
1331
1333 if (!filter) {
1334 return;
1335 }
1336 if (
as_CFB(filter)->
type() == SkColorFilterBase::Type::kCompose) {
1337
1341 }
else if (
as_CFB(filter)->
type() == SkColorFilterBase::Type::kWorkingFormat) {
1342
1345 }
else if (
as_CFB(filter)->
type() == SkColorFilterBase::Type::kRuntime) {
1346
1349 }
1350}
1351
1352
1353
1354static void add_to_key(
const KeyContext& keyContext,
1355 PaintParamsKeyBuilder* builder,
1356 PipelineDataGatherer* gatherer,
1359
1360 Blend(keyContext, builder, gatherer,
1361 [&] () -> void {
1363 },
1364 [&]() -> void {
1366 },
1367 [&]() -> void {
1369 });
1370}
1372 DrawContext* drawContext,
1374
1377}
1378
1379static void add_to_key(
const KeyContext& keyContext,
1380 PaintParamsKeyBuilder* builder,
1381 PipelineDataGatherer* gatherer,
1383
1384
1385 LocalMatrixShaderBlock::LMShaderData lmShaderData(shader->
ctm());
1386
1387 KeyContextWithLocalMatrix newContext(keyContext, shader->
ctm());
1388
1389 LocalMatrixShaderBlock::BeginBlock(newContext, builder, gatherer, lmShaderData);
1390
1392
1394}
1397}
1398
1399static void add_to_key(
const KeyContext& keyContext,
1400 PaintParamsKeyBuilder* builder,
1401 PipelineDataGatherer* gatherer,
1404
1405 SolidColorShaderBlock::AddBlock(keyContext, builder, gatherer,
1407}
1409
1410}
1411
1412static void add_to_key(
const KeyContext& keyContext,
1413 PaintParamsKeyBuilder* builder,
1414 PipelineDataGatherer* gatherer,
1417
1419 keyContext.dstColorInfo().colorSpace());
1420
1421 SolidColorShaderBlock::AddBlock(keyContext, builder, gatherer,
color);
1422}
1424
1425}
1426
1427static void add_to_key(
const KeyContext& keyContext,
1428 PaintParamsKeyBuilder* builder,
1429 PipelineDataGatherer* gatherer,
1432
1433 Compose(keyContext, builder, gatherer,
1434 [&]() -> void {
1436 },
1437 [&]() -> void {
1439 });
1440}
1442 DrawContext* drawContext,
1446}
1447
1448static void add_to_key(
const KeyContext& keyContext,
1449 PaintParamsKeyBuilder* builder,
1450 PipelineDataGatherer* gatherer,
1453
1454 CoordClampShaderBlock::CoordClampData
data(shader->
subset());
1455
1456 CoordClampShaderBlock::BeginBlock(keyContext, builder, gatherer, data);
1459}
1461 DrawContext* drawContext,
1464}
1465
1466static void add_to_key(
const KeyContext& keyContext,
1467 PaintParamsKeyBuilder* builder,
1468 PipelineDataGatherer* gatherer,
1470 builder->addBlock(BuiltInCodeSnippetID::kPriorOutput);
1471}
1473
1474}
1475
1477 PaintParamsKeyBuilder* builder,
1478 PipelineDataGatherer* gatherer,
1482 SkASSERT(!imageToDraw->isAlphaOnly());
1483
1484 const Image_YUVA* yuvaImage =
static_cast<const Image_YUVA*
>(imageToDraw.
get());
1485 const SkYUVAInfo& yuvaInfo = yuvaImage->yuvaInfo();
1486
1489 YUVImageShaderBlock::ImageData imgData(sampling,
1492 imageToDraw->dimensions(),
1495 const TextureProxyView& view = yuvaImage->proxyView(locIndex);
1496 if (view) {
1497 imgData.fTextureProxies[locIndex] = view.refProxy();
1498
1499
1500 switch(view.swizzle()[0]) {
1501 case 'r': imgData.fChannelSelect[locIndex] = {1.f, 0.f, 0.f, 0.f}; break;
1502 case 'g': imgData.fChannelSelect[locIndex] = {0.f, 1.f, 0.f, 0.f}; break;
1503 case 'b': imgData.fChannelSelect[locIndex] = {0.f, 0.f, 1.f, 0.f}; break;
1504 case 'a': imgData.fChannelSelect[locIndex] = {0.f, 0.f, 0.f, 1.f}; break;
1505 default:
1506 imgData.fChannelSelect[locIndex] = {0.f, 0.f, 0.f, 0.f};
1507 SkDEBUGFAILF(
"Unexpected swizzle for YUVA data: %c", view.swizzle()[0]);
1508 break;
1509 }
1510 } else {
1511
1512
1514 imgData.fTextureProxies[locIndex] = yuvaImage->proxyView(
SkYUVAInfo::kY).refProxy();
1515 imgData.fChannelSelect[locIndex] = {1.f, 1.f, 1.f, 1.f};
1516 }
1517 }
1518
1519 auto [ssx, ssy] = yuvaImage->uvSubsampleFactors();
1520 if (ssx > 1 || ssy > 1) {
1521
1522
1523
1524 const TextureProxyView& view = yuvaImage->proxyView(
SkYUVAInfo::kU);
1525 imgData.fImgSizeUV = {view.dimensions().width()*ssx, view.dimensions().height()*ssy};
1526
1527
1528
1529
1530
1533 imgData.fSampling.mipmap);
1534
1535
1536
1537
1538
1539
1540
1542 view.dimensions().width()*ssx > yuvaInfo.
width()) {
1543 imgData.fLinearFilterUVInset.fX = 1.f/(2*ssx);
1544 }
1546 view.dimensions().height()*ssy > yuvaInfo.
height()) {
1547 imgData.fLinearFilterUVInset.fY = 1.f/(2*ssy);
1548 }
1549 }
1550
1551 imgData.fLinearFilterUVInset = {imgData.fLinearFilterUVInset.fX*ssx,
1552 imgData.fLinearFilterUVInset.fY*ssy};
1553 }
1554
1555 float yuvM[20];
1557
1558
1559
1560
1561 SkASSERT(yuvM[3] == 0 && yuvM[8] == 0 && yuvM[13] == 0 && yuvM[18] == 1);
1562 SkASSERT(yuvM[15] == 0 && yuvM[16] == 0 && yuvM[17] == 0 && yuvM[19] == 0);
1563 imgData.fYUVtoRGBMatrix.setAll(
1564 yuvM[ 0], yuvM[ 1], yuvM[ 2],
1565 yuvM[ 5], yuvM[ 6], yuvM[ 7],
1566 yuvM[10], yuvM[11], yuvM[12]
1567 );
1568 imgData.fYUVtoRGBTranslate = {yuvM[4], yuvM[9], yuvM[14]};
1569
1570
1571
1573 LocalMatrixShaderBlock::LMShaderData lmShaderData(originMatrix);
1574
1575 KeyContextWithLocalMatrix newContext(keyContext, originMatrix);
1576
1579 if (!origShader->
isRaw()) {
1581 imageToDraw->alphaType(),
1582 keyContext.dstColorInfo().colorSpace(),
1583 keyContext.dstColorInfo().alphaType());
1584 }
1585 ColorSpaceTransformBlock::ColorSpaceTransformData
data(steps);
1586
1587 Compose(keyContext, builder, gatherer,
1588 [&]() -> void {
1589 LocalMatrixShaderBlock::BeginBlock(newContext, builder, gatherer, lmShaderData);
1590 YUVImageShaderBlock::AddBlock(newContext, builder, gatherer, imgData);
1592 },
1593 [&]() -> void {
1594 ColorSpaceTransformBlock::AddBlock(keyContext, builder, gatherer, data);
1595 });
1596}
1597
1609 } else {
1610 SKGPU_LOG_W(
"%s is an unsupported read swizzle. Defaulting to RGBA.\n",
1613 }
1614}
1615
1616static void add_to_key(
const KeyContext& keyContext,
1617 PaintParamsKeyBuilder* builder,
1618 PipelineDataGatherer* gatherer,
1621
1625 if (!imageToDraw) {
1626 SKGPU_LOG_W(
"Couldn't convert ImageShader's image to a Graphite-backed image");
1627 builder->addBlock(BuiltInCodeSnippetID::kError);
1628 return;
1629 }
1630 if (
as_IB(imageToDraw)->isYUVA()) {
1632 builder,
1633 gatherer,
1634 shader,
1635 std::move(imageToDraw),
1636 newSampling);
1637 }
1638
1641
1642 ImageShaderBlock::ImageData imgData(shader->
sampling(),
1645 view.proxy()->dimensions(),
1647 ReadSwizzle::kRGBA);
1648 imgData.fSampling = newSampling;
1649 imgData.fTextureProxy = view.refProxy();
1651
1652 if (imageToDraw->isAlphaOnly()) {
1654 }
1656
1657 if (!shader->
isRaw()) {
1659 imageToDraw->alphaType(),
1660 keyContext.dstColorInfo().colorSpace(),
1661 keyContext.dstColorInfo().alphaType());
1662
1663 if (imageToDraw->isAlphaOnly() && keyContext.scope() != KeyContext::Scope::kRuntimeEffect) {
1664 Blend(keyContext, builder, gatherer,
1665 [&] () -> void {
1667 },
1668 [&] () -> void {
1669 ImageShaderBlock::AddBlock(keyContext, builder, gatherer, imgData);
1670 },
1671 [&]() -> void {
1672 RGBPaintColorBlock::AddBlock(keyContext, builder, gatherer);
1673 });
1674 return;
1675 }
1676 }
1677
1678 ImageShaderBlock::AddBlock(keyContext, builder, gatherer, imgData);
1679}
1681 DrawContext*,
1684 if (!
image->isGraphiteBacked()) {
1685
1686 return;
1687 }
1688
1689
1690
1691 static_cast<Image_Base*
>(
image)->notifyInUse(recorder);
1692}
1693
1694static void add_to_key(
const KeyContext& keyContext,
1695 PaintParamsKeyBuilder* builder,
1696 PipelineDataGatherer* gatherer,
1700
1701
1702
1704 if (
as_SB(wrappedShader)->
type() == SkShaderBase::ShaderType::kImage) {
1705 auto imgShader =
static_cast<const SkImageShader*
>(wrappedShader);
1706
1707
1708
1709
1710 auto imgBase =
as_IB(imgShader->image());
1711 if (imgBase->isGraphiteBacked() && !imgBase->isYUVA()) {
1712 auto imgGraphite =
static_cast<Image*
>(imgBase);
1714 const auto& view = imgGraphite->textureProxyView();
1715 if (view.origin() == Origin::kBottomLeft) {
1717 matrix.setTranslateY(view.height());
1718 }
1719 }
1720 }
1721
1723 LocalMatrixShaderBlock::LMShaderData lmShaderData(matrix);
1724
1725 KeyContextWithLocalMatrix newContext(keyContext, matrix);
1726
1727 LocalMatrixShaderBlock::BeginBlock(newContext, builder, gatherer, lmShaderData);
1728
1729 AddToKey(newContext, builder, gatherer, wrappedShader);
1730
1732}
1733
1735 DrawContext* drawContext,
1738}
1739
1740
1741
1743 (int)PerlinNoiseShaderBlock::Type::kFractalNoise);
1745 (int)PerlinNoiseShaderBlock::Type::kTurbulence);
1746static void add_to_key(
const KeyContext& keyContext,
1747 PaintParamsKeyBuilder* builder,
1748 PipelineDataGatherer* gatherer,
1752
1753 std::unique_ptr<SkPerlinNoiseShader::PaintingData> paintingData = shader->
getPaintingData();
1754 paintingData->generateBitmaps();
1755
1757 keyContext.recorder(), paintingData->getPermutationsBitmap());
1758
1760 RecorderPriv::CreateCachedProxy(keyContext.recorder(), paintingData->getNoiseBitmap());
1761
1762 if (!perm || !noise) {
1763 SKGPU_LOG_W(
"Couldn't create tables for PerlinNoiseShader");
1764 builder->addBlock(BuiltInCodeSnippetID::kError);
1765 return;
1766 }
1767
1768 PerlinNoiseShaderBlock::PerlinNoiseData perlinData(
1769 static_cast<PerlinNoiseShaderBlock::Type
>(shader->
noiseType()),
1770 paintingData->fBaseFrequency,
1772 {paintingData->fStitchDataInit.fWidth, paintingData->fStitchDataInit.fHeight});
1773
1774 perlinData.fPermutationsProxy = std::move(perm);
1775 perlinData.fNoiseProxy = std::move(noise);
1776
1777 PerlinNoiseShaderBlock::AddBlock(keyContext, builder, gatherer, perlinData);
1778}
1780
1781}
1782
1783static void add_to_key(
const KeyContext& keyContext,
1784 PaintParamsKeyBuilder* builder,
1785 PipelineDataGatherer* gatherer,
1788
1789 Recorder* recorder = keyContext.recorder();
1790 const Caps* caps = recorder->
priv().
caps();
1791
1792
1793
1795
1796 SkMatrix totalM = keyContext.local2Dev().asM33();
1797 if (keyContext.localMatrix()) {
1798 totalM.
preConcat(*keyContext.localMatrix());
1799 }
1801 totalM,
1802 keyContext.dstColorInfo().colorType(),
1803 keyContext.dstColorInfo().colorSpace(),
1804 caps->maxTextureSize(),
1805 props);
1806 if (!
info.success) {
1807 SKGPU_LOG_W(
"Couldn't access PictureShaders' Image info");
1808 builder->addBlock(BuiltInCodeSnippetID::kError);
1809 return;
1810 }
1811
1812
1813
1814
1818 if (!img) {
1819 SKGPU_LOG_W(
"Couldn't create SkImage for PictureShader");
1820 builder->addBlock(BuiltInCodeSnippetID::kError);
1821 return;
1822 }
1823
1827 if (!imgShader) {
1828 SKGPU_LOG_W(
"Couldn't create SkImageShader for PictureShader");
1829 builder->addBlock(BuiltInCodeSnippetID::kError);
1830 return;
1831 }
1832
1833 AddToKey(keyContext, builder, gatherer, imgShader.
get());
1834}
1836
1837
1838}
1839
1840static void add_to_key(
const KeyContext& keyContext,
1841 PaintParamsKeyBuilder* builder,
1842 PipelineDataGatherer* gatherer,
1847 effect->uniforms(),
1848 shader->
uniformData(keyContext.dstColorInfo().colorSpace()),
1849 keyContext.dstColorInfo().colorSpace());
1851
1852 RuntimeEffectBlock::BeginBlock(keyContext, builder, gatherer,
1853 {effect, std::move(uniforms)});
1854
1855 add_children_to_key(keyContext, builder, gatherer,
1856 shader->
children(), effect->children());
1857
1859}
1861 DrawContext* drawContext,
1864}
1865
1866static void add_to_key(
const KeyContext& keyContext,
1867 PaintParamsKeyBuilder* builder,
1868 PipelineDataGatherer* gatherer,
1870 SKGPU_LOG_W(
"Raster-only SkShader (SkTransformShader) encountered");
1871 builder->addBlock(BuiltInCodeSnippetID::kError);
1872}
1874
1875}
1876
1877static void add_to_key(
const KeyContext& keyContext,
1878 PaintParamsKeyBuilder* builder,
1879 PipelineDataGatherer* gatherer,
1881 SKGPU_LOG_W(
"Raster-only SkShader (SkTriColorShader) encountered");
1882 builder->addBlock(BuiltInCodeSnippetID::kError);
1883}
1885
1886}
1887
1888static void add_to_key(
const KeyContext& keyContext,
1889 PaintParamsKeyBuilder* builder,
1890 PipelineDataGatherer* gatherer,
1893
1894 const SkColorInfo& dstInfo = keyContext.dstColorInfo();
1897 if (!dstCS) {
1899 }
1900
1903 KeyContextWithColorInfo workingContext(keyContext, workingInfo);
1904
1905
1906 Compose(keyContext, builder, gatherer,
1907 [&]() -> void {
1909 },
1910 [&]() -> void {
1911 ColorSpaceTransformBlock::ColorSpaceTransformData
data(
1912 workingCS.
get(), dstAT, dstCS.
get(), dstAT);
1913 ColorSpaceTransformBlock::AddBlock(keyContext, builder, gatherer, data);
1914 });
1915}
1917 DrawContext* drawContext,
1920}
1921
1924 const float* offsets) {
1926
1929
1930 for (int i = 0; i < numStops; i++) {
1931
1932
1935
1938
1939 int exponent;
1940 float mantissa = frexp(
offset, &exponent);
1941
1945 return {};
1946 }
1947
1948#if defined(SK_DEBUG)
1950
1954#endif
1955
1956
1957
1960 }
1961
1962 return colorsAndOffsetsBitmap;
1963}
1964
1965
1966
1968 PaintParamsKeyBuilder* builder,
1969 PipelineDataGatherer* gatherer,
1970 const GradientShaderBlocks::GradientData& gradData,
1974
1975 bool inputPremul =
static_cast<bool>(
interp.fInPremul);
1976
1977 switch (
interp.fColorSpace) {
1978 case ColorSpace::kLab:
1979 case ColorSpace::kOKLab:
1980 case ColorSpace::kOKLabGamutMap:
1981 case ColorSpace::kLCH:
1982 case ColorSpace::kOKLCH:
1983 case ColorSpace::kOKLCHGamutMap:
1984 case ColorSpace::kHSL:
1985 case ColorSpace::kHWB:
1986 inputPremul = false;
1987 break;
1988 default:
1989 break;
1990 }
1991
1992 const SkColorInfo& dstColorInfo = keyContext.dstColorInfo();
1993
1996
1998
1999 ColorSpaceTransformBlock::ColorSpaceTransformData
data(
2000 intermediateCS, intermediateAlphaType, dstColorSpace, dstColorInfo.
alphaType());
2001
2002
2003
2004
2005 Compose(keyContext, builder, gatherer,
2006 [&]() -> void {
2007 GradientShaderBlocks::AddBlock(keyContext, builder, gatherer, gradData);
2008 },
2009 [&]() -> void {
2010 ColorSpaceTransformBlock::AddBlock(keyContext, builder, gatherer, data);
2011 });
2012}
2013
2015 PaintParamsKeyBuilder* builder,
2016 PipelineDataGatherer* gatherer,
2020 float radius0,
2021 float radius1,
2022 float bias,
2024 SkColor4fXformer xformedColors(shader, keyContext.dstColorInfo().colorSpace());
2026 const float* positions = xformedColors.fPositions;
2027 const int colorCount = xformedColors.fColors.size();
2028
2030
2031 if (colorCount > GradientShaderBlocks::GradientData::kNumInternalStorageStops) {
2035 if (colorsAndOffsetsBitmap.
empty()) {
2036 SKGPU_LOG_W(
"Couldn't create GradientShader's color and offset bitmap");
2037 builder->addBlock(BuiltInCodeSnippetID::kError);
2038 return;
2039 }
2041 }
2042
2043 proxy = RecorderPriv::CreateCachedProxy(keyContext.recorder(), shader->
cachedBitmap());
2044 if (!proxy) {
2045 SKGPU_LOG_W(
"Couldn't create GradientShader's color and offset bitmap proxy");
2046 builder->addBlock(BuiltInCodeSnippetID::kError);
2047 return;
2048 }
2049 }
2050
2052 point0,
2053 point1,
2054 radius0,
2055 radius1,
2056 bias,
2059 colorCount,
2060 colors,
2061 positions,
2062 std::move(proxy),
2064
2066 builder,
2067 gatherer,
2068 data,
2070 xformedColors.fIntermediateColorSpace.get());
2071}
2072
2074 PaintParamsKeyBuilder* builder,
2075 PipelineDataGatherer* gatherer,
2078 builder,
2079 gatherer,
2080 shader,
2085 0.0f,
2086 0.0f);
2087}
2088
2090 PaintParamsKeyBuilder* builder,
2091 PipelineDataGatherer* gatherer,
2094 builder,
2095 gatherer,
2096 shader,
2099 0.0f,
2100 0.0f,
2101 0.0f,
2102 0.0f);
2103}
2104
2106 PaintParamsKeyBuilder* builder,
2107 PipelineDataGatherer* gatherer,
2110 builder,
2111 gatherer,
2112 shader,
2114 { 0.0f, 0.0f },
2116 0.0f,
2117 0.0f,
2118 0.0f);
2119}
2120
2122 PaintParamsKeyBuilder* builder,
2123 PipelineDataGatherer* gatherer,
2126 builder,
2127 gatherer,
2128 shader,
2130 { 0.0f, 0.0f },
2131 0.0f,
2132 0.0f,
2135}
2136
2137static void add_to_key(
const KeyContext& keyContext,
2138 PaintParamsKeyBuilder* builder,
2139 PipelineDataGatherer* gatherer,
2143#define M(type) \
2144 case SkShaderBase::GradientType::k##type: \
2145 add_gradient_to_key(keyContext, \
2146 builder, \
2147 gatherer, \
2148 static_cast<const Sk##type##Gradient*>(shader)); \
2149 return;
2151#undef M
2153 SkDEBUGFAIL(
"Gradient shader says its type is none");
2154 return;
2155 }
2157}
2159
2160}
2161
2162void AddToKey(
const KeyContext& keyContext,
2163 PaintParamsKeyBuilder* builder,
2164 PipelineDataGatherer* gatherer,
2166 if (!shader) {
2167 return;
2168 }
2170#define M(type) \
2171 case SkShaderBase::ShaderType::k##type: \
2172 add_to_key(keyContext, \
2173 builder, \
2174 gatherer, \
2175 static_cast<const Sk##type##Shader*>(shader)); \
2176 return;
2178#undef M
2179 }
2181}
2182
2184 DrawContext* drawContext,
2186 if (!shader) {
2187 return;
2188 }
2190#define M(type) \
2191 case SkShaderBase::ShaderType::k##type: \
2192 notify_in_use(recorder, \
2193 drawContext, \
2194 static_cast<const Sk##type##Shader*>(shader)); \
2195 return;
2197#undef M
2198 }
2200}
2201
2202
2203}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static std::unique_ptr< GrFragmentProcessor > make_interpolated_to_dst(std::unique_ptr< GrFragmentProcessor > gradient, const SkGradientShader::Interpolation &interpolation, SkColorSpace *intermediateColorSpace, const GrColorInfo &dstInfo, bool allOpaque)
#define VALIDATE_UNIFORMS(gatherer, dict, codeSnippetID)
#define SKGPU_LOG_W(fmt,...)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
#define SkDEBUGFAIL(message)
#define SkDEBUGFAILF(fmt,...)
static SkRGBA4f< kDstAT > map_color(const SkColor4f &c, SkColorSpace *src, SkColorSpace *dst)
@ kSrcOver
r = s + (1-sa)*d
#define SK_ALL_BLENDERS(M)
SkBlenderBase * as_BB(SkBlender *blend)
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
#define SK_ALL_COLOR_FILTERS(M)
static SkColorFilterBase * as_CFB(SkColorFilter *filter)
SkColorSpace * sk_srgb_linear_singleton()
SkColorSpace * sk_srgb_singleton()
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
static float2 interp(const float2 &v0, const float2 &v1, const float2 &t)
float SkHalfToFloat(SkHalf h)
SkHalf SkFloatToHalf(float f)
static SkImage_Base * as_IB(SkImage *image)
static void sk_bzero(void *buffer, size_t size)
SkShaderBase * as_SB(SkShader *shader)
#define SK_ALL_GRADIENTS(M)
#define SK_ALL_SHADERS(M)
void SkColorMatrix_YUV2RGB(SkYUVColorSpace cs, float m[20])
Type::kYUV Type::kRGBA() int(0.7 *637)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
void erase(SkColor4f c, const SkIRect &area) const
sk_sp< SkShader > dst() const
sk_sp< SkShader > src() const
const SkMatrix & ctm() const
sk_sp< SkShader > proxyShader() const
sk_sp< SkColorSpace > colorSpace() const
sk_sp< SkColorFilterBase > filter() const
sk_sp< SkShader > shader() const
SkAlphaType alphaType() const
sk_sp< SkColorSpace > refColorSpace() const
SkColorSpace * colorSpace() const
SkColorType colorType() const
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorFilterBase > inner() const
sk_sp< SkColorFilterBase > outer() const
const SkPoint & getEndCenter() const
SkScalar getEndRadius() const
const SkPoint & getStartCenter() const
SkScalar getStartRadius() const
sk_sp< SkShader > shader() const
const uint8_t * bytes() const
const Interpolation & getInterpolation() const
void setCachedBitmap(SkBitmap b) const
const SkBitmap & cachedBitmap() const
SkTileMode getTileMode() const
SkSamplingOptions sampling() const
static SkM44 CubicResamplerMatrix(float B, float C)
SkTileMode tileModeX() const
sk_sp< SkImage > image() const
SkTileMode tileModeY() const
const SkPoint & start() const
const SkPoint & end() const
const SkMatrix & localMatrix() const
sk_sp< SkShader > wrappedShader() const
bool invert(SkM44 *inverse) const
const float * matrix() const
static SkMatrix Scale(SkScalar sx, SkScalar sy)
SkMatrix & setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
SkMatrix & preConcat(const SkMatrix &other)
SkPerlinNoiseShaderType noiseType() const
std::unique_ptr< PaintingData > getPaintingData() const
SkTileMode tileModeY() const
SkTileMode tileModeX() const
SkFilterMode filter() const
sk_sp< SkPicture > picture() const
const SkPoint & center() const
sk_sp< SkRuntimeEffect > effect() const
SkSpan< const SkRuntimeEffect::ChildPtr > children() const
sk_sp< const SkData > uniforms() const
SkSpan< const SkRuntimeEffect::ChildPtr > children() const
sk_sp< SkRuntimeEffect > effect() const
sk_sp< const SkData > uniforms() const
static sk_sp< const SkData > TransformUniforms(SkSpan< const SkRuntimeEffect::Uniform > uniforms, sk_sp< const SkData > originalData, const SkColorSpaceXformSteps &)
static bool UsesColorTransform(const SkRuntimeEffect *effect)
SkBlender * blender() const
SkShader * shader() const
std::optional< ChildType > type() const
SkColorFilter * colorFilter() const
SkSpan< const Uniform > uniforms() const
SkSpan< const SkRuntimeEffect::ChildPtr > children() const
sk_sp< const SkData > uniformData(const SkColorSpace *dstCS) const
sk_sp< SkRuntimeEffect > effect() const
virtual GradientType asGradient(GradientInfo *info=nullptr, SkMatrix *localMatrix=nullptr) const
constexpr size_t size() const
const char * data() const
const SkPoint & center() const
const SkBitmap & bitmap() const
sk_sp< SkShader > shader() const
sk_sp< SkColorSpace > workingSpace() const
SkMatrix originMatrix() const
SkYUVColorSpace yuvColorSpace() const
static constexpr int kYUVAChannelCount
static constexpr Swizzle Concat(const Swizzle &a, const Swizzle &b)
SkString asString() const
static constexpr Swizzle BGRA()
static constexpr Swizzle RGBA()
static constexpr Swizzle RGB1()
const Caps * caps() const
const uint8_t uint32_t uint32_t GError ** error
static constexpr int kUnknownRuntimeEffectIDStart
unsigned useCenter Optional< SkMatrix > matrix
PODArray< SkColor > colors
SkSamplingOptions sampling
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
void AddToKey(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, const SkBlender *blender)
void AddKnownModeBlend(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkBlendMode bm)
void AddBlendModeColorFilter(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkBlendMode bm, const SkPMColor4f &srcColor)
static void notify_in_use(Recorder *recorder, DrawContext *drawContext, const SkBlendShader *shader)
static void add_yuv_image_to_key(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, const SkImageShader *origShader, sk_sp< const SkImage > imageToDraw, SkSamplingOptions sampling)
static bool can_do_tiling_in_hw(const Caps *caps, const ImageShaderBlock::ImageData &imgData)
static SkBitmap create_color_and_offset_bitmap(int numStops, const SkPMColor4f *colors, const float *offsets)
std::pair< sk_sp< SkImage >, SkSamplingOptions > GetGraphiteBacked(Recorder *recorder, const SkImage *imageIn, SkSamplingOptions sampling)
static void add_to_key(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, const SkBlendModeColorFilter *filter)
static void add_gradient_to_key(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, const SkGradientBaseShader *shader, SkPoint point0, SkPoint point1, float radius0, float radius1, float bias, float scale)
static skgpu::graphite::ReadSwizzle swizzle_class_to_read_enum(const skgpu::Swizzle &swizzle)
void AddModeBlend(const KeyContext &keyContext, PaintParamsKeyBuilder *builder, PipelineDataGatherer *gatherer, SkBlendMode bm)
static void gather_runtime_effect_uniforms(const KeyContext &keyContext, const SkRuntimeEffect *effect, SkSpan< const Uniform > graphiteUniforms, const SkData *uniformData, PipelineDataGatherer *gatherer)
static bool skdata_matches(const SkData *a, const SkData *b)
void NotifyImagesInUse(Recorder *recorder, DrawContext *drawContext, const SkBlender *blender)
SIN Vec< N, float > abs(const Vec< N, float > &x)
skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction *tf)
constexpr int32_t y() const
constexpr int32_t x() const
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static CachedImageInfo Make(const SkRect &bounds, const SkMatrix &totalM, SkColorType dstColorType, SkColorSpace *dstColorSpace, const int maxTextureSize, const SkSurfaceProps &propsIn)
SkRGBA4f< kPremul_SkAlphaType > premul() const
static SkRGBA4f FromColor(SkColor color)
static SkRect Make(const SkISize &size)
static constexpr SkSize Make(SkScalar w, SkScalar h)