@@ -29,7 +29,6 @@ namespace {
2929 struct BlitterUniforms {
3030 int right; // First device x + blit run length n, used to get device x coordinate.
3131 int y; // Device y coordinate.
32- SkColor4f paint; // In device color space.
3332 };
3433 static_assert (SkIsAlign4(sizeof (BlitterUniforms)), " " );
3534 static constexpr int kBlitterUniformsCount = sizeof (BlitterUniforms) / 4 ;
@@ -42,6 +41,7 @@ namespace {
4241 SkColorInfo dst;
4342 SkBlendMode blendMode;
4443 Coverage coverage;
44+ SkColor4f paint;
4545 SkFilterQuality quality;
4646 const SkMatrixProvider& matrices;
4747
@@ -62,7 +62,7 @@ namespace {
6262 blendMode,
6363 coverage;
6464 uint32_t padding{0 };
65- // Params::quality and Params:: matrices are only passed to {shader,clip}->program(),
65+ // Params::{paint, quality, matrices} are only passed to {shader,clip}->program(),
6666 // not used here by the blitter itself. No need to include them in the key;
6767 // they'll be folded into the shader key if used.
6868
@@ -120,24 +120,25 @@ namespace {
120120 };
121121 }
122122
123- static skvm::Color paint_color (skvm::Builder* p, skvm::Uniforms* uniforms) {
124- return {
125- p->uniformF (uniforms->base , offsetof (BlitterUniforms, paint.fR )),
126- p->uniformF (uniforms->base , offsetof (BlitterUniforms, paint.fG )),
127- p->uniformF (uniforms->base , offsetof (BlitterUniforms, paint.fB )),
128- p->uniformF (uniforms->base , offsetof (BlitterUniforms, paint.fA )),
129- };
130- }
131-
132123 // If build_program() can't build this program, cache_key() sets *ok to false.
133124 static Key cache_key (const Params& params,
134125 skvm::Uniforms* uniforms, SkArenaAlloc* alloc, bool * ok) {
126+ // Take care to match build_program()'s reuse of the paint color uniforms.
127+ skvm::Uniform r = uniforms->pushF (params.paint .fR ),
128+ g = uniforms->pushF (params.paint .fG ),
129+ b = uniforms->pushF (params.paint .fB ),
130+ a = uniforms->pushF (params.paint .fA );
135131 auto hash_shader = [&](const sk_sp<SkShader>& shader) {
136132 const SkShaderBase* sb = as_SB (shader);
137133 skvm::Builder p;
138134
139135 skvm::Coord device = device_coord (&p, uniforms);
140- skvm::Color paint = paint_color (&p, uniforms);
136+ skvm::Color paint = {
137+ p.uniformF (r),
138+ p.uniformF (g),
139+ p.uniformF (b),
140+ p.uniformF (a),
141+ };
141142
142143 uint64_t hash = 0 ;
143144 if (auto c = sb->program (&p,
@@ -200,9 +201,9 @@ namespace {
200201 // - UniformA8: 8-bit coverage uniform
201202
202203 skvm::Coord device = device_coord (p, uniforms);
203- skvm::Color paint = paint_color (p , uniforms);
204+ skvm::Color paint = p-> uniformColor (params. paint , uniforms);
204205
205- // See note about arguments above... a SpriteShader will call p->arg() once here .
206+ // See note about arguments above: a SpriteShader will call p->arg() once during program() .
206207 skvm::Color src = as_SB (params.shader )->program (p, device,/* local=*/ device, paint,
207208 params.matrices , /* localM=*/ nullptr ,
208209 params.quality , params.dst ,
@@ -509,12 +510,18 @@ namespace {
509510 blendMode = SkBlendMode::kSrc ;
510511 }
511512
513+ SkColor4f paintColor = paint.getColor4f ();
514+ SkColorSpaceXformSteps{sk_srgb_singleton (), kUnpremul_SkAlphaType ,
515+ device.colorSpace (), kUnpremul_SkAlphaType }
516+ .apply (paintColor.vec ());
517+
512518 return {
513519 std::move (shader),
514520 std::move (clip),
515521 { device.colorType (), device.alphaType (), device.refColorSpace () },
516522 blendMode,
517523 Coverage::Full, // Placeholder... withCoverage() will change as needed.
524+ paintColor,
518525 paint.getFilterQuality (),
519526 matrices,
520527 };
@@ -535,13 +542,7 @@ namespace {
535542 , fUniforms (kBlitterUniformsCount )
536543 , fParams (effective_params(device, sprite, paint, matrices, std::move(clip)))
537544 , fKey (cache_key(fParams , &fUniforms , &fAlloc , ok))
538- , fPaint ([&]{
539- SkColor4f color = paint.getColor4f ();
540- SkColorSpaceXformSteps{sk_srgb_singleton (), kUnpremul_SkAlphaType ,
541- device.colorSpace (), kUnpremul_SkAlphaType }
542- .apply (color.vec ());
543- return color;
544- }()) {}
545+ {}
545546
546547 ~Blitter () override {
547548 if (SkLRUCache<Key, skvm::Program>* cache = try_acquire_program_cache ()) {
@@ -573,7 +574,6 @@ namespace {
573574 SkArenaAlloc fAlloc {2 *sizeof (void *)}; // but a few effects need to ref large content.
574575 const Params fParams ;
575576 const Key fKey ;
576- const SkColor4f fPaint ;
577577 skvm::Program fBlitH ,
578578 fBlitAntiH ,
579579 fBlitMaskA8 ,
@@ -629,7 +629,7 @@ namespace {
629629 }
630630
631631 void updateUniforms (int right, int y) {
632- BlitterUniforms uniforms{right, y, fPaint };
632+ BlitterUniforms uniforms{right, y};
633633 memcpy (fUniforms .buf .data (), &uniforms, sizeof (BlitterUniforms));
634634 }
635635
0 commit comments