@@ -29,7 +29,6 @@ namespace {
29
29
struct BlitterUniforms {
30
30
int right; // First device x + blit run length n, used to get device x coordinate.
31
31
int y; // Device y coordinate.
32
- SkColor4f paint; // In device color space.
33
32
};
34
33
static_assert (SkIsAlign4(sizeof (BlitterUniforms)), " " );
35
34
static constexpr int kBlitterUniformsCount = sizeof (BlitterUniforms) / 4 ;
@@ -42,6 +41,7 @@ namespace {
42
41
SkColorInfo dst;
43
42
SkBlendMode blendMode;
44
43
Coverage coverage;
44
+ SkColor4f paint;
45
45
SkFilterQuality quality;
46
46
const SkMatrixProvider& matrices;
47
47
@@ -62,7 +62,7 @@ namespace {
62
62
blendMode,
63
63
coverage;
64
64
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(),
66
66
// not used here by the blitter itself. No need to include them in the key;
67
67
// they'll be folded into the shader key if used.
68
68
@@ -120,24 +120,25 @@ namespace {
120
120
};
121
121
}
122
122
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
-
132
123
// If build_program() can't build this program, cache_key() sets *ok to false.
133
124
static Key cache_key (const Params& params,
134
125
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 );
135
131
auto hash_shader = [&](const sk_sp<SkShader>& shader) {
136
132
const SkShaderBase* sb = as_SB (shader);
137
133
skvm::Builder p;
138
134
139
135
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
+ };
141
142
142
143
uint64_t hash = 0 ;
143
144
if (auto c = sb->program (&p,
@@ -200,9 +201,9 @@ namespace {
200
201
// - UniformA8: 8-bit coverage uniform
201
202
202
203
skvm::Coord device = device_coord (p, uniforms);
203
- skvm::Color paint = paint_color (p , uniforms);
204
+ skvm::Color paint = p-> uniformColor (params. paint , uniforms);
204
205
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() .
206
207
skvm::Color src = as_SB (params.shader )->program (p, device,/* local=*/ device, paint,
207
208
params.matrices , /* localM=*/ nullptr ,
208
209
params.quality , params.dst ,
@@ -509,12 +510,18 @@ namespace {
509
510
blendMode = SkBlendMode::kSrc ;
510
511
}
511
512
513
+ SkColor4f paintColor = paint.getColor4f ();
514
+ SkColorSpaceXformSteps{sk_srgb_singleton (), kUnpremul_SkAlphaType ,
515
+ device.colorSpace (), kUnpremul_SkAlphaType }
516
+ .apply (paintColor.vec ());
517
+
512
518
return {
513
519
std::move (shader),
514
520
std::move (clip),
515
521
{ device.colorType (), device.alphaType (), device.refColorSpace () },
516
522
blendMode,
517
523
Coverage::Full, // Placeholder... withCoverage() will change as needed.
524
+ paintColor,
518
525
paint.getFilterQuality (),
519
526
matrices,
520
527
};
@@ -535,13 +542,7 @@ namespace {
535
542
, fUniforms (kBlitterUniformsCount )
536
543
, fParams (effective_params(device, sprite, paint, matrices, std::move(clip)))
537
544
, 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
+ {}
545
546
546
547
~Blitter () override {
547
548
if (SkLRUCache<Key, skvm::Program>* cache = try_acquire_program_cache ()) {
@@ -573,7 +574,6 @@ namespace {
573
574
SkArenaAlloc fAlloc {2 *sizeof (void *)}; // but a few effects need to ref large content.
574
575
const Params fParams ;
575
576
const Key fKey ;
576
- const SkColor4f fPaint ;
577
577
skvm::Program fBlitH ,
578
578
fBlitAntiH ,
579
579
fBlitMaskA8 ,
@@ -629,7 +629,7 @@ namespace {
629
629
}
630
630
631
631
void updateUniforms (int right, int y) {
632
- BlitterUniforms uniforms{right, y, fPaint };
632
+ BlitterUniforms uniforms{right, y};
633
633
memcpy (fUniforms .buf .data (), &uniforms, sizeof (BlitterUniforms));
634
634
}
635
635
0 commit comments