• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/core/SkColor.h"
9 #include "include/core/SkPaint.h"
10 #include "include/core/SkShader.h"
11 #include "include/private/SkTo.h"
12 #include "src/core/SkArenaAlloc.h"
13 #include "src/core/SkBlendModePriv.h"
14 #include "src/core/SkBlitter.h"
15 #include "src/core/SkColorFilterBase.h"
16 #include "src/core/SkColorSpacePriv.h"
17 #include "src/core/SkColorSpaceXformSteps.h"
18 #include "src/core/SkMatrixProvider.h"
19 #include "src/core/SkOpts.h"
20 #include "src/core/SkRasterPipeline.h"
21 #include "src/core/SkUtils.h"
22 #include "src/shaders/SkShaderBase.h"
23 
24 class SkRasterPipelineBlitter final : public SkBlitter {
25 public:
26     // This is our common entrypoint for creating the blitter once we've sorted out shaders.
27     static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*,
28                              const SkRasterPipeline& shaderPipeline,
29                              bool is_opaque, bool is_constant,
30                              sk_sp<SkShader> clipShader);
31 
SkRasterPipelineBlitter(SkPixmap dst,SkBlendMode blend,SkArenaAlloc * alloc)32     SkRasterPipelineBlitter(SkPixmap dst,
33                             SkBlendMode blend,
34                             SkArenaAlloc* alloc)
35         : fDst(dst)
36         , fBlend(blend)
37         , fAlloc(alloc)
38         , fColorPipeline(alloc)
39     {}
40 
41     void blitH     (int x, int y, int w)                            override;
42     void blitAntiH (int x, int y, const SkAlpha[], const int16_t[]) override;
43     void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1)               override;
44     void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1)               override;
45     void blitMask  (const SkMask&, const SkIRect& clip)             override;
46     void blitRect  (int x, int y, int width, int height)            override;
47     void blitV     (int x, int y, int height, SkAlpha alpha)        override;
48 
49 private:
50     void append_load_dst      (SkRasterPipeline*) const;
51     void append_store         (SkRasterPipeline*) const;
52 
53     // these check internally, and only append if there was a native clipShader
54     void append_clip_scale    (SkRasterPipeline*) const;
55     void append_clip_lerp     (SkRasterPipeline*) const;
56 
57     SkPixmap               fDst;
58     SkBlendMode            fBlend;
59     SkArenaAlloc*          fAlloc;
60     SkRasterPipeline       fColorPipeline;
61     // set to pipeline storage (for alpha) if we have a clipShader
62     void*                  fClipShaderBuffer = nullptr; // "native" : float or U16
63 
64     SkRasterPipeline_MemoryCtx
65         fDstPtr       = {nullptr,0},  // Always points to the top-left of fDst.
66         fMaskPtr      = {nullptr,0};  // Updated each call to blitMask().
67     SkRasterPipeline_EmbossCtx fEmbossCtx;  // Used only for k3D_Format masks.
68 
69     // We may be able to specialize blitH() or blitRect() into a memset.
70     void   (*fMemset2D)(SkPixmap*, int x,int y, int w,int h, uint64_t color) = nullptr;
71     uint64_t fMemsetColor = 0;   // Big enough for largest memsettable dst format, F16.
72 
73     // Built lazily on first use.
74     std::function<void(size_t, size_t, size_t, size_t)> fBlitRect,
75                                                         fBlitAntiH,
76                                                         fBlitMaskA8,
77                                                         fBlitMaskLCD16,
78                                                         fBlitMask3D;
79 
80     // These values are pointed to by the blit pipelines above,
81     // which allows us to adjust them from call to call.
82     float fCurrentCoverage = 0.0f;
83     float fDitherRate      = 0.0f;
84 
85     using INHERITED = SkBlitter;
86 };
87 
SkCreateRasterPipelineBlitter(const SkPixmap & dst,const SkPaint & paint,const SkMatrixProvider & matrixProvider,SkArenaAlloc * alloc,sk_sp<SkShader> clipShader)88 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
89                                          const SkPaint& paint,
90                                          const SkMatrixProvider& matrixProvider,
91                                          SkArenaAlloc* alloc,
92                                          sk_sp<SkShader> clipShader) {
93     if (!paint.asBlendMode()) {
94         // The raster pipeline doesn't support SkBlender.
95         return nullptr;
96     }
97 
98     SkColorSpace* dstCS = dst.colorSpace();
99     SkColorType dstCT = dst.colorType();
100     SkColor4f paintColor = paint.getColor4f();
101     SkColorSpaceXformSteps(sk_srgb_singleton(), kUnpremul_SkAlphaType,
102                            dstCS,               kUnpremul_SkAlphaType).apply(paintColor.vec());
103 
104     auto shader = as_SB(paint.getShader());
105 
106     SkRasterPipeline_<256> shaderPipeline;
107     if (!shader) {
108         // Having no shader makes things nice and easy... just use the paint color.
109         shaderPipeline.append_constant_color(alloc, paintColor.premul().vec());
110         bool is_opaque    = paintColor.fA == 1.0f,
111              is_constant  = true;
112         return SkRasterPipelineBlitter::Create(dst, paint, alloc,
113                                                shaderPipeline, is_opaque, is_constant,
114                                                std::move(clipShader));
115     }
116 
117     bool is_opaque    = shader->isOpaque() && paintColor.fA == 1.0f;
118     bool is_constant  = shader->isConstant();
119 
120     if (shader->appendStages(
121                 {&shaderPipeline, alloc, dstCT, dstCS, paint, nullptr, matrixProvider})) {
122         if (paintColor.fA != 1.0f) {
123             shaderPipeline.append(SkRasterPipeline::scale_1_float,
124                                   alloc->make<float>(paintColor.fA));
125         }
126         return SkRasterPipelineBlitter::Create(dst, paint, alloc,
127                                                shaderPipeline, is_opaque, is_constant,
128                                                std::move(clipShader));
129     }
130 
131     // The shader can't draw with SkRasterPipeline.
132     return nullptr;
133 }
134 
SkCreateRasterPipelineBlitter(const SkPixmap & dst,const SkPaint & paint,const SkRasterPipeline & shaderPipeline,bool is_opaque,SkArenaAlloc * alloc,sk_sp<SkShader> clipShader)135 SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
136                                          const SkPaint& paint,
137                                          const SkRasterPipeline& shaderPipeline,
138                                          bool is_opaque,
139                                          SkArenaAlloc* alloc,
140                                          sk_sp<SkShader> clipShader) {
141     bool is_constant = false;  // If this were the case, it'd be better to just set a paint color.
142     return SkRasterPipelineBlitter::Create(dst, paint, alloc,
143                                            shaderPipeline, is_opaque, is_constant,
144                                            clipShader);
145 }
146 
Create(const SkPixmap & dst,const SkPaint & paint,SkArenaAlloc * alloc,const SkRasterPipeline & shaderPipeline,bool is_opaque,bool is_constant,sk_sp<SkShader> clipShader)147 SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
148                                            const SkPaint& paint,
149                                            SkArenaAlloc* alloc,
150                                            const SkRasterPipeline& shaderPipeline,
151                                            bool is_opaque,
152                                            bool is_constant,
153                                            sk_sp<SkShader> clipShader) {
154     const auto bm = paint.asBlendMode();
155     if (!bm) {
156         return nullptr;
157     }
158 
159     auto blitter = alloc->make<SkRasterPipelineBlitter>(dst, bm.value(), alloc);
160 
161     // Our job in this factory is to fill out the blitter's color pipeline.
162     // This is the common front of the full blit pipelines, each constructed lazily on first use.
163     // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
164     auto colorPipeline = &blitter->fColorPipeline;
165 
166     if (clipShader) {
167         auto clipP = colorPipeline;
168         SkPaint clipPaint;  // just need default values
169         SkColorType clipCT = kRGBA_8888_SkColorType;
170         SkColorSpace* clipCS = nullptr;
171         SkMatrixProvider clipMatrixProvider(SkMatrix::I());
172         SkStageRec rec = {clipP, alloc, clipCT, clipCS, clipPaint, nullptr, clipMatrixProvider};
173         if (as_SB(clipShader)->appendStages(rec)) {
174             struct Storage {
175                 // large enough for highp (float) or lowp(U16)
176                 float   fA[SkRasterPipeline_kMaxStride];
177             };
178             auto storage = alloc->make<Storage>();
179             clipP->append(SkRasterPipeline::store_src_a, storage->fA);
180             blitter->fClipShaderBuffer = storage->fA;
181             is_constant = false;
182         } else {
183             return nullptr;
184         }
185     }
186 
187     // Let's get the shader in first.
188     colorPipeline->extend(shaderPipeline);
189 
190     // If there's a color filter it comes next.
191     if (auto colorFilter = paint.getColorFilter()) {
192         SkMatrixProvider matrixProvider(SkMatrix::I());
193         SkStageRec rec = {
194             colorPipeline, alloc, dst.colorType(), dst.colorSpace(), paint, nullptr, matrixProvider
195         };
196         if (!as_CFB(colorFilter)->appendStages(rec, is_opaque)) {
197             return nullptr;
198         }
199         is_opaque = is_opaque && as_CFB(colorFilter)->isAlphaUnchanged();
200     }
201 
202     // Not all formats make sense to dither (think, F16).  We set their dither rate
203     // to zero.  We only dither non-constant shaders, so is_constant won't change here.
204     if (paint.isDither() && !is_constant) {
205         switch (dst.info().colorType()) {
206             case kARGB_4444_SkColorType:
207                 blitter->fDitherRate = 1 / 15.0f;
208                 break;
209             case kRGB_565_SkColorType:
210                 blitter->fDitherRate = 1 / 63.0f;
211                 break;
212             case kGray_8_SkColorType:
213             case kRGB_888x_SkColorType:
214             case kRGBA_8888_SkColorType:
215             case kBGRA_8888_SkColorType:
216             case kSRGBA_8888_SkColorType:
217             case kR8_unorm_SkColorType:
218                 blitter->fDitherRate = 1 / 255.0f;
219                 break;
220             case kRGB_101010x_SkColorType:
221             case kRGBA_1010102_SkColorType:
222             case kBGR_101010x_SkColorType:
223             case kBGRA_1010102_SkColorType:
224                 blitter->fDitherRate = 1 / 1023.0f;
225                 break;
226 
227             case kUnknown_SkColorType:
228             case kAlpha_8_SkColorType:
229             case kRGBA_F16_SkColorType:
230             case kRGBA_F16Norm_SkColorType:
231             case kRGBA_F32_SkColorType:
232             case kR8G8_unorm_SkColorType:
233             case kA16_float_SkColorType:
234             case kA16_unorm_SkColorType:
235             case kR16G16_float_SkColorType:
236             case kR16G16_unorm_SkColorType:
237             case kR16G16B16A16_unorm_SkColorType:
238                 blitter->fDitherRate = 0.0f;
239                 break;
240         }
241         if (blitter->fDitherRate > 0.0f) {
242             colorPipeline->append(SkRasterPipeline::dither, &blitter->fDitherRate);
243         }
244     }
245 
246     // We're logically done here.  The code between here and return blitter is all optimization.
247 
248     // A pipeline that's still constant here can collapse back into a constant color.
249     if (is_constant) {
250         SkColor4f constantColor;
251         SkRasterPipeline_MemoryCtx constantColorPtr = { &constantColor, 0 };
252         colorPipeline->append_gamut_clamp_if_normalized(dst.info());
253         colorPipeline->append(SkRasterPipeline::store_f32, &constantColorPtr);
254         colorPipeline->run(0,0,1,1);
255         colorPipeline->reset();
256         colorPipeline->append_constant_color(alloc, constantColor);
257 
258         is_opaque = constantColor.fA == 1.0f;
259     }
260 
261     // We can strength-reduce SrcOver into Src when opaque.
262     if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
263         blitter->fBlend = SkBlendMode::kSrc;
264     }
265 
266     // When we're drawing a constant color in Src mode, we can sometimes just memset.
267     // (The previous two optimizations help find more opportunities for this one.)
268     if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
269         // Run our color pipeline all the way through to produce what we'd memset when we can.
270         // Not all blits can memset, so we need to keep colorPipeline too.
271         SkRasterPipeline_<256> p;
272         p.extend(*colorPipeline);
273         p.append_gamut_clamp_if_normalized(dst.info());
274         blitter->fDstPtr = SkRasterPipeline_MemoryCtx{&blitter->fMemsetColor, 0};
275         blitter->append_store(&p);
276         p.run(0,0,1,1);
277 
278         switch (blitter->fDst.shiftPerPixel()) {
279             case 0: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
280                 void* p = dst->writable_addr(x,y);
281                 while (h --> 0) {
282                     memset(p, c, w);
283                     p = SkTAddOffset<void>(p, dst->rowBytes());
284                 }
285             }; break;
286 
287             case 1: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
288                 SkOpts::rect_memset16(dst->writable_addr16(x,y), c, w, dst->rowBytes(), h);
289             }; break;
290 
291             case 2: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
292                 SkOpts::rect_memset32(dst->writable_addr32(x,y), c, w, dst->rowBytes(), h);
293             }; break;
294 
295             case 3: blitter->fMemset2D = [](SkPixmap* dst, int x,int y, int w,int h, uint64_t c) {
296                 SkOpts::rect_memset64(dst->writable_addr64(x,y), c, w, dst->rowBytes(), h);
297             }; break;
298 
299             // TODO(F32)?
300         }
301     }
302 
303     blitter->fDstPtr = SkRasterPipeline_MemoryCtx{
304         blitter->fDst.writable_addr(),
305         blitter->fDst.rowBytesAsPixels(),
306     };
307 
308     return blitter;
309 }
310 
append_load_dst(SkRasterPipeline * p) const311 void SkRasterPipelineBlitter::append_load_dst(SkRasterPipeline* p) const {
312     p->append_load_dst(fDst.info().colorType(), &fDstPtr);
313     if (fDst.info().alphaType() == kUnpremul_SkAlphaType) {
314         p->append(SkRasterPipeline::premul_dst);
315     }
316 }
317 
append_store(SkRasterPipeline * p) const318 void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
319     if (fDst.info().alphaType() == kUnpremul_SkAlphaType) {
320         p->append(SkRasterPipeline::unpremul);
321     }
322     p->append_store(fDst.info().colorType(), &fDstPtr);
323 }
324 
append_clip_scale(SkRasterPipeline * p) const325 void SkRasterPipelineBlitter::append_clip_scale(SkRasterPipeline* p) const {
326     if (fClipShaderBuffer) {
327         p->append(SkRasterPipeline::scale_native, fClipShaderBuffer);
328     }
329 }
330 
append_clip_lerp(SkRasterPipeline * p) const331 void SkRasterPipelineBlitter::append_clip_lerp(SkRasterPipeline* p) const {
332     if (fClipShaderBuffer) {
333         p->append(SkRasterPipeline::lerp_native, fClipShaderBuffer);
334     }
335 }
336 
blitH(int x,int y,int w)337 void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
338     this->blitRect(x,y,w,1);
339 }
340 
blitRect(int x,int y,int w,int h)341 void SkRasterPipelineBlitter::blitRect(int x, int y, int w, int h) {
342     if (fMemset2D) {
343         fMemset2D(&fDst, x,y, w,h, fMemsetColor);
344         return;
345     }
346 
347     if (!fBlitRect) {
348         SkRasterPipeline p(fAlloc);
349         p.extend(fColorPipeline);
350         p.append_gamut_clamp_if_normalized(fDst.info());
351         if (fBlend == SkBlendMode::kSrcOver
352                 && (fDst.info().colorType() == kRGBA_8888_SkColorType ||
353                     fDst.info().colorType() == kBGRA_8888_SkColorType)
354                 && !fDst.colorSpace()
355                 && fDst.info().alphaType() != kUnpremul_SkAlphaType
356                 && fDitherRate == 0.0f) {
357             if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
358                 p.append(SkRasterPipeline::swap_rb);
359             }
360             this->append_clip_scale(&p);
361             p.append(SkRasterPipeline::srcover_rgba_8888, &fDstPtr);
362         } else {
363             if (fBlend != SkBlendMode::kSrc) {
364                 this->append_load_dst(&p);
365                 SkBlendMode_AppendStages(fBlend, &p);
366                 this->append_clip_lerp(&p);
367             } else if (fClipShaderBuffer) {
368                 this->append_load_dst(&p);
369                 this->append_clip_lerp(&p);
370             }
371             this->append_store(&p);
372         }
373         fBlitRect = p.compile();
374     }
375 
376     fBlitRect(x,y,w,h);
377 }
378 
blitAntiH(int x,int y,const SkAlpha aa[],const int16_t runs[])379 void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
380     if (!fBlitAntiH) {
381         SkRasterPipeline p(fAlloc);
382         p.extend(fColorPipeline);
383         p.append_gamut_clamp_if_normalized(fDst.info());
384         if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/false)) {
385             p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
386             this->append_clip_scale(&p);
387             this->append_load_dst(&p);
388             SkBlendMode_AppendStages(fBlend, &p);
389         } else {
390             this->append_load_dst(&p);
391             SkBlendMode_AppendStages(fBlend, &p);
392             p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
393             this->append_clip_lerp(&p);
394         }
395 
396         this->append_store(&p);
397         fBlitAntiH = p.compile();
398     }
399 
400     for (int16_t run = *runs; run > 0; run = *runs) {
401         switch (*aa) {
402             case 0x00:                       break;
403             case 0xff: this->blitH(x,y,run); break;
404             default:
405                 fCurrentCoverage = *aa * (1/255.0f);
406                 fBlitAntiH(x,y,run,1);
407         }
408         x    += run;
409         runs += run;
410         aa   += run;
411     }
412 }
413 
blitAntiH2(int x,int y,U8CPU a0,U8CPU a1)414 void SkRasterPipelineBlitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
415     SkIRect clip = {x,y, x+2,y+1};
416     uint8_t coverage[] = { (uint8_t)a0, (uint8_t)a1 };
417 
418     SkMask mask;
419     mask.fImage    = coverage;
420     mask.fBounds   = clip;
421     mask.fRowBytes = 2;
422     mask.fFormat   = SkMask::kA8_Format;
423 
424     this->blitMask(mask, clip);
425 }
426 
blitAntiV2(int x,int y,U8CPU a0,U8CPU a1)427 void SkRasterPipelineBlitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
428     SkIRect clip = {x,y, x+1,y+2};
429     uint8_t coverage[] = { (uint8_t)a0, (uint8_t)a1 };
430 
431     SkMask mask;
432     mask.fImage    = coverage;
433     mask.fBounds   = clip;
434     mask.fRowBytes = 1;
435     mask.fFormat   = SkMask::kA8_Format;
436 
437     this->blitMask(mask, clip);
438 }
439 
blitV(int x,int y,int height,SkAlpha alpha)440 void SkRasterPipelineBlitter::blitV(int x, int y, int height, SkAlpha alpha) {
441     SkIRect clip = {x,y, x+1,y+height};
442 
443     SkMask mask;
444     mask.fImage    = &alpha;
445     mask.fBounds   = clip;
446     mask.fRowBytes = 0;     // so we reuse the 1 "row" for all of height
447     mask.fFormat   = SkMask::kA8_Format;
448 
449     this->blitMask(mask, clip);
450 }
451 
blitMask(const SkMask & mask,const SkIRect & clip)452 void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
453     if (mask.fFormat == SkMask::kBW_Format) {
454         // TODO: native BW masks?
455         return INHERITED::blitMask(mask, clip);
456     }
457 
458     // ARGB and SDF masks shouldn't make it here.
459     SkASSERT(mask.fFormat == SkMask::kA8_Format
460           || mask.fFormat == SkMask::kLCD16_Format
461           || mask.fFormat == SkMask::k3D_Format);
462 
463     auto extract_mask_plane = [&mask](int plane, SkRasterPipeline_MemoryCtx* ctx) {
464         // LCD is 16-bit per pixel; A8 and 3D are 8-bit per pixel.
465         size_t bpp = mask.fFormat == SkMask::kLCD16_Format ? 2 : 1;
466 
467         // Select the right mask plane.  Usually plane == 0 and this is just mask.fImage.
468         auto ptr = (uintptr_t)mask.fImage
469                  + plane * mask.computeImageSize();
470 
471         // Update ctx to point "into" this current mask, but lined up with fDstPtr at (0,0).
472         // This sort of trickery upsets UBSAN (pointer-overflow) so our ptr must be a uintptr_t.
473         // mask.fRowBytes is a uint32_t, which would break our addressing math on 64-bit builds.
474         size_t rowBytes = mask.fRowBytes;
475         ctx->stride = rowBytes / bpp;
476         ctx->pixels = (void*)(ptr - mask.fBounds.left() * bpp
477                                   - mask.fBounds.top()  * rowBytes);
478     };
479 
480     extract_mask_plane(0, &fMaskPtr);
481     if (mask.fFormat == SkMask::k3D_Format) {
482         extract_mask_plane(1, &fEmbossCtx.mul);
483         extract_mask_plane(2, &fEmbossCtx.add);
484     }
485 
486     // Lazily build whichever pipeline we need, specialized for each mask format.
487     if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
488         SkRasterPipeline p(fAlloc);
489         p.extend(fColorPipeline);
490         p.append_gamut_clamp_if_normalized(fDst.info());
491         if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/false)) {
492             p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
493             this->append_clip_scale(&p);
494             this->append_load_dst(&p);
495             SkBlendMode_AppendStages(fBlend, &p);
496         } else {
497             this->append_load_dst(&p);
498             SkBlendMode_AppendStages(fBlend, &p);
499             p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
500             this->append_clip_lerp(&p);
501         }
502         this->append_store(&p);
503         fBlitMaskA8 = p.compile();
504     }
505     if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
506         SkRasterPipeline p(fAlloc);
507         p.extend(fColorPipeline);
508         p.append_gamut_clamp_if_normalized(fDst.info());
509         if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/true)) {
510             // Somewhat unusually, scale_565 needs dst loaded first.
511             this->append_load_dst(&p);
512             p.append(SkRasterPipeline::scale_565, &fMaskPtr);
513             this->append_clip_scale(&p);
514             SkBlendMode_AppendStages(fBlend, &p);
515         } else {
516             this->append_load_dst(&p);
517             SkBlendMode_AppendStages(fBlend, &p);
518             p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
519             this->append_clip_lerp(&p);
520         }
521         this->append_store(&p);
522         fBlitMaskLCD16 = p.compile();
523     }
524     if (mask.fFormat == SkMask::k3D_Format && !fBlitMask3D) {
525         SkRasterPipeline p(fAlloc);
526         p.extend(fColorPipeline);
527         // This bit is where we differ from kA8_Format:
528         p.append(SkRasterPipeline::emboss, &fEmbossCtx);
529         // Now onward just as kA8.
530         p.append_gamut_clamp_if_normalized(fDst.info());
531         if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/false)) {
532             p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
533             this->append_clip_scale(&p);
534             this->append_load_dst(&p);
535             SkBlendMode_AppendStages(fBlend, &p);
536         } else {
537             this->append_load_dst(&p);
538             SkBlendMode_AppendStages(fBlend, &p);
539             p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
540             this->append_clip_lerp(&p);
541         }
542         this->append_store(&p);
543         fBlitMask3D = p.compile();
544     }
545 
546     std::function<void(size_t,size_t,size_t,size_t)>* blitter = nullptr;
547     switch (mask.fFormat) {
548         case SkMask::kA8_Format:    blitter = &fBlitMaskA8;    break;
549         case SkMask::kLCD16_Format: blitter = &fBlitMaskLCD16; break;
550         case SkMask::k3D_Format:    blitter = &fBlitMask3D;    break;
551         default:
552             SkASSERT(false);
553             return;
554     }
555 
556     SkASSERT(blitter);
557     (*blitter)(clip.left(),clip.top(), clip.width(),clip.height());
558 }
559