blob: cc48df03db8931f1d0fac13587101a0c26fe2b17 [file] [log] [blame]
mtklein9a5c47f2016-07-22 11:05:04 -07001/*
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
Herb Derbyac04fef2017-01-13 17:34:33 -05008#include "SkArenaAlloc.h"
mtklein9a5c47f2016-07-22 11:05:04 -07009#include "SkBlitter.h"
Mike Kleine902f8d2016-10-26 15:32:26 -040010#include "SkBlendModePriv.h"
mtklein9a5c47f2016-07-22 11:05:04 -070011#include "SkColor.h"
12#include "SkColorFilter.h"
Mike Klein3b840e92017-05-23 15:06:17 -040013#include "SkColorSpaceXformer.h"
Mike Kleinbaaf8ad2016-09-29 09:04:15 -040014#include "SkOpts.h"
mtklein9a5c47f2016-07-22 11:05:04 -070015#include "SkPM4f.h"
Mike Klein744908e2016-11-11 12:51:36 -050016#include "SkPM4fPriv.h"
mtklein9a5c47f2016-07-22 11:05:04 -070017#include "SkRasterPipeline.h"
18#include "SkShader.h"
Florin Malita4aed1382017-05-25 10:38:07 -040019#include "SkShaderBase.h"
Mike Klein14c8f822016-11-30 19:39:43 -050020#include "SkUtils.h"
Mike Klein581e6982017-05-03 13:05:13 -040021#include "../jumper/SkJumper.h"
mtklein9a5c47f2016-07-22 11:05:04 -070022
Mike Klein4e3bc862017-05-22 20:15:17 +000023class SkRasterPipelineBlitter final : public SkBlitter {
mtklein9a5c47f2016-07-22 11:05:04 -070024public:
Mike Klein3b840e92017-05-23 15:06:17 -040025 // This is our common entrypoint for creating the blitter once we've sorted out shaders.
Mike Kleinb35cb312017-05-19 12:01:01 -040026 static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*,
Florin Malita4aed1382017-05-25 10:38:07 -040027 const SkRasterPipeline& shaderPipeline,
28 SkShaderBase::Context* shaderCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -040029 bool is_opaque, bool is_constant, bool wants_dither);
30
Mike Klein3b840e92017-05-23 15:06:17 -040031 SkRasterPipelineBlitter(SkPixmap dst,
32 SkBlendMode blend,
33 SkArenaAlloc* alloc,
Florin Malita4aed1382017-05-25 10:38:07 -040034 SkShaderBase::Context* shaderCtx)
mtklein9a5c47f2016-07-22 11:05:04 -070035 : fDst(dst)
Mike Kleine902f8d2016-10-26 15:32:26 -040036 , fBlend(blend)
Mike Klein0a76b412017-05-22 12:01:59 -040037 , fAlloc(alloc)
Mike Klein3b840e92017-05-23 15:06:17 -040038 , fShaderCtx(shaderCtx)
Mike Kleinb24704d2017-05-24 07:53:00 -040039 , fColorPipeline(alloc)
mtklein9a5c47f2016-07-22 11:05:04 -070040 {}
41
42 void blitH (int x, int y, int w) override;
43 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
44 void blitMask (const SkMask&, const SkIRect& clip) override;
45
46 // TODO: The default implementations of the other blits look fine,
47 // but some of them like blitV could probably benefit from custom
48 // blits using something like a SkRasterPipeline::runFew() method.
49
50private:
Mike Klein14c8f822016-11-30 19:39:43 -050051 void append_load_d(SkRasterPipeline*) const;
52 void append_blend (SkRasterPipeline*) const;
53 void maybe_clamp (SkRasterPipeline*) const;
54 void append_store (SkRasterPipeline*) const;
mtklein8e4373f2016-07-22 14:20:27 -070055
Mike Klein3b840e92017-05-23 15:06:17 -040056 // If we have an SkShader::Context, use it to fill our shader buffer.
57 void maybe_shade(int x, int y, int w);
58
Florin Malita4aed1382017-05-25 10:38:07 -040059 SkPixmap fDst;
60 SkBlendMode fBlend;
61 SkArenaAlloc* fAlloc;
62 SkShaderBase::Context* fShaderCtx;
63 SkRasterPipeline fColorPipeline;
mtklein9a5c47f2016-07-22 11:05:04 -070064
Mike Klein8729e5b2017-02-16 06:51:48 -050065 // We may be able to specialize blitH() into a memset.
66 bool fCanMemsetInBlitH = false;
67 uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16.
Mike Kleinbd3fe472016-10-25 15:43:46 -040068
Mike Klein8729e5b2017-02-16 06:51:48 -050069 // Built lazily on first use.
Mike Klein0a76b412017-05-22 12:01:59 -040070 std::function<void(size_t, size_t)> fBlitH,
71 fBlitAntiH,
72 fBlitMaskA8,
73 fBlitMaskLCD16;
Mike Klein8729e5b2017-02-16 06:51:48 -050074
75 // These values are pointed to by the blit pipelines above,
76 // which allows us to adjust them from call to call.
Mike Klein3b840e92017-05-23 15:06:17 -040077 void* fShaderOutput = nullptr;
Mike Kleindb711c92017-05-03 17:57:48 -040078 void* fDstPtr = nullptr;
79 const void* fMaskPtr = nullptr;
80 float fCurrentCoverage = 0.0f;
81 int fCurrentY = 0;
82 SkJumper_DitherCtx fDitherCtx = { &fCurrentY, 0.0f };
Mike Kleinbd3fe472016-10-25 15:43:46 -040083
Mike Klein3b840e92017-05-23 15:06:17 -040084 std::vector<SkPM4f> fShaderBuffer;
85
mtklein9a5c47f2016-07-22 11:05:04 -070086 typedef SkBlitter INHERITED;
87};
88
89SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
90 const SkPaint& paint,
Mike Kleinfb191da2016-11-15 13:20:33 -050091 const SkMatrix& ctm,
Matt Sarett25834ff2017-02-15 15:54:35 -050092 SkArenaAlloc* alloc) {
Mike Klein3b840e92017-05-23 15:06:17 -040093 SkColorSpace* dstCS = dst.colorSpace();
94 auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), dstCS));
Florin Malita4aed1382017-05-25 10:38:07 -040095 auto shader = as_SB(paint.getShader());
Mike Klein3b840e92017-05-23 15:06:17 -040096
97 SkRasterPipeline_<256> shaderPipeline;
98 if (!shader) {
99 // Having no shader makes things nice and easy... just use the paint color.
100 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
101 bool is_opaque = paintColor->a() == 1.0f,
102 is_constant = true,
103 wants_dither = false;
104 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
105 shaderPipeline, nullptr,
106 is_opaque, is_constant, wants_dither);
107 }
108
109 bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f;
110 bool is_constant = shader->isConstant();
111 bool wants_dither = shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType;
112
113 // See if the shader can express itself by appending pipeline stages.
114 if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
115 if (paintColor->a() != 1.0f) {
116 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
117 }
118 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
119 shaderPipeline, nullptr,
120 is_opaque, is_constant, wants_dither);
121 }
122
123 // No, the shader wants us to create a context and call shadeSpan4f().
124 SkASSERT(!is_constant); // All constant shaders should be able to appendStages().
125
126 if (dstCS) {
127 // We need to transform the shader into the dst color space, and extend its lifetime.
128 sk_sp<SkShader> in_dstCS = SkColorSpaceXformer::Make(sk_ref_sp(dstCS))->apply(shader);
Florin Malita4aed1382017-05-25 10:38:07 -0400129 shader = as_SB(in_dstCS.get());
Mike Klein3b840e92017-05-23 15:06:17 -0400130 alloc->make<sk_sp<SkShader>>(std::move(in_dstCS));
131 }
Florin Malita4aed1382017-05-25 10:38:07 -0400132 SkShaderBase::ContextRec rec(paint, ctm, nullptr, SkShaderBase::ContextRec::kPM4f_DstType,
133 dstCS);
134 SkShaderBase::Context* shaderCtx = shader->makeContext(rec, alloc);
Mike Klein3b840e92017-05-23 15:06:17 -0400135 if (!shaderCtx) {
136 // When a shader fails to create a context, it has vetoed drawing entirely.
137 return alloc->make<SkNullBlitter>();
138 }
139 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
140 shaderPipeline, shaderCtx,
141 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400142}
143
144SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
145 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -0400146 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -0400147 bool is_opaque,
148 bool wants_dither,
Mike Reed02640952017-05-19 15:32:13 -0400149 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400150 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
151 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
Mike Klein3b840e92017-05-23 15:06:17 -0400152 shaderPipeline, nullptr,
153 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400154}
155
Mike Kleinb35cb312017-05-19 12:01:01 -0400156SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
157 const SkPaint& paint,
158 SkArenaAlloc* alloc,
159 const SkRasterPipeline& shaderPipeline,
Florin Malita4aed1382017-05-25 10:38:07 -0400160 SkShaderBase::Context* shaderCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -0400161 bool is_opaque,
162 bool is_constant,
163 bool wants_dither) {
Mike Klein3b840e92017-05-23 15:06:17 -0400164 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst,
165 paint.getBlendMode(),
166 alloc,
167 shaderCtx);
Mike Reed02640952017-05-19 15:32:13 -0400168
Mike Kleinb35cb312017-05-19 12:01:01 -0400169 // Our job in this factory is to fill out the blitter's color pipeline.
170 // This is the common front of the full blit pipelines, each constructed lazily on first use.
171 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
172 auto colorPipeline = &blitter->fColorPipeline;
173
Mike Klein3b840e92017-05-23 15:06:17 -0400174 // Let's get the shader in first.
175 if (shaderCtx) {
176 colorPipeline->append(SkRasterPipeline::load_f32, &blitter->fShaderOutput);
177 } else {
178 // If the shader's not constant, it'll need seeding with x,y.
179 if (!is_constant) {
180 colorPipeline->append(SkRasterPipeline::seed_shader, &blitter->fCurrentY);
181 }
182 colorPipeline->extend(shaderPipeline);
Mike Reed02640952017-05-19 15:32:13 -0400183 }
184
Mike Kleinb35cb312017-05-19 12:01:01 -0400185 // If there's a color filter it comes next.
186 if (auto colorFilter = paint.getColorFilter()) {
187 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700188 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700189 }
190
Mike Kleinb35cb312017-05-19 12:01:01 -0400191 // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to.
192 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
193 // We need to decide if we're going to dither now to keep is_constant accurate.
194 if (wants_dither ||
195 (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) {
196 switch (dst.info().colorType()) {
197 default: blitter->fDitherCtx.rate = 0.0f; break;
198 case kRGB_565_SkColorType: blitter->fDitherCtx.rate = 1/63.0f; break;
199 case kRGBA_8888_SkColorType:
200 case kBGRA_8888_SkColorType: blitter->fDitherCtx.rate = 1/255.0f; break;
201 }
202 }
203 is_constant = is_constant && (blitter->fDitherCtx.rate == 0.0f);
204
205 // We're logically done here. The code between here and return blitter is all optimization.
206
207 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500208 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400209 auto constantColor = alloc->make<SkPM4f>();
210 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
211 colorPipeline->run(0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400212 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400213 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700214
Mike Kleinb35cb312017-05-19 12:01:01 -0400215 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400216 }
mtklein8e4373f2016-07-22 14:20:27 -0700217
Mike Kleinb35cb312017-05-19 12:01:01 -0400218 // We can strength-reduce SrcOver into Src when opaque.
219 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
220 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700221 }
222
Mike Kleinb35cb312017-05-19 12:01:01 -0400223 // When we're drawing a constant color in Src mode, we can sometimes just memset.
224 // (The previous two optimizations help find more opportunities for this one.)
225 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
226 // Run our color pipeline all the way through to produce what we'd memset when we can.
227 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400228 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400229 p.extend(*colorPipeline);
230 blitter->fDstPtr = &blitter->fMemsetColor;
231 blitter->append_store(&p);
Mike Klein319ba3d2017-01-20 15:11:54 -0500232 p.run(0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500233
Mike Kleinb35cb312017-05-19 12:01:01 -0400234 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500235 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400236
237 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700238}
239
Mike Kleine902f8d2016-10-26 15:32:26 -0400240void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500241 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700242 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500243 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500244 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500245 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500246 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
247 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700248 default: break;
249 }
Mike Kleine03339a2016-11-28 13:24:27 -0500250 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500251 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500252 }
253 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500254 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500255 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500256 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700257}
258
Mike Klein14c8f822016-11-30 19:39:43 -0500259void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400260 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500261 p->append(SkRasterPipeline::to_srgb);
262 }
Mike Kleindb711c92017-05-03 17:57:48 -0400263 if (fDitherCtx.rate > 0.0f) {
264 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
265 // over the whole range. If we did it before, 1/255.0f is too big a rate near zero.
266 p->append(SkRasterPipeline::dither, &fDitherCtx);
267 }
268
Mike Kleine03339a2016-11-28 13:24:27 -0500269 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
270 p->append(SkRasterPipeline::swap_rb);
271 }
mtklein8e4373f2016-07-22 14:20:27 -0700272 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500273 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500274 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
275 case kBGRA_8888_SkColorType:
276 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
277 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700278 default: break;
279 }
280}
281
Mike Kleine902f8d2016-10-26 15:32:26 -0400282void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleinbb338332017-05-04 12:42:52 -0400283 SkBlendMode_AppendStages(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400284}
Mike Kleine9f74b82016-10-25 13:31:21 -0400285
Mike Klein130863e2016-10-27 11:29:36 -0400286void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleine03339a2016-11-28 13:24:27 -0500287 if (SkBlendMode_CanOverflow(fBlend)) {
288 p->append(SkRasterPipeline::clamp_a);
289 }
Mike Klein130863e2016-10-27 11:29:36 -0400290}
291
Mike Klein3b840e92017-05-23 15:06:17 -0400292void SkRasterPipelineBlitter::maybe_shade(int x, int y, int w) {
293 if (fShaderCtx) {
294 if (w > SkToInt(fShaderBuffer.size())) {
295 fShaderBuffer.resize(w);
296 }
297 fShaderCtx->shadeSpan4f(x,y, fShaderBuffer.data(), w);
298 // We'll be reading from fShaderOutput + x.
299 fShaderOutput = fShaderBuffer.data() - x;
300 }
301}
302
mtklein9a5c47f2016-07-22 11:05:04 -0700303void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500304 fDstPtr = fDst.writable_addr(0,y);
305 fCurrentY = y;
306
307 if (fCanMemsetInBlitH) {
308 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000309 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
310 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
311 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
312 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500313 default: break;
314 }
315 }
316
Mike Klein0a76b412017-05-22 12:01:59 -0400317 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400318 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400319 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400320 if (fBlend != SkBlendMode::kSrc) {
321 this->append_load_d(&p);
322 this->append_blend(&p);
323 this->maybe_clamp(&p);
324 }
Mike Kleine902f8d2016-10-26 15:32:26 -0400325 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400326 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400327 }
Mike Klein3b840e92017-05-23 15:06:17 -0400328 this->maybe_shade(x,y,w);
Mike Klein0a76b412017-05-22 12:01:59 -0400329 fBlitH(x,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700330}
331
332void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400333 if (!fBlitAntiH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400334 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400335 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400336 if (fBlend == SkBlendMode::kSrcOver) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500337 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400338 this->append_load_d(&p);
339 this->append_blend(&p);
340 } else {
341 this->append_load_d(&p);
342 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500343 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400344 }
Mike Klein130863e2016-10-27 11:29:36 -0400345 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400346 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400347 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400348 }
mtklein9a5c47f2016-07-22 11:05:04 -0700349
Mike Kleinbd3fe472016-10-25 15:43:46 -0400350 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500351 fCurrentY = y;
mtklein9a5c47f2016-07-22 11:05:04 -0700352 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500353 switch (*aa) {
354 case 0x00: break;
355 case 0xff: this->blitH(x,y,run); break;
356 default:
Mike Klein3b840e92017-05-23 15:06:17 -0400357 this->maybe_shade(x,y,run);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500358 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein0a76b412017-05-22 12:01:59 -0400359 fBlitAntiH(x,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500360 }
mtklein9a5c47f2016-07-22 11:05:04 -0700361 x += run;
362 runs += run;
363 aa += run;
364 }
365}
366
367void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
368 if (mask.fFormat == SkMask::kBW_Format) {
369 // TODO: native BW masks?
370 return INHERITED::blitMask(mask, clip);
371 }
372
Mike Klein0a76b412017-05-22 12:01:59 -0400373 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400374 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400375 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400376 if (fBlend == SkBlendMode::kSrcOver) {
377 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
378 this->append_load_d(&p);
379 this->append_blend(&p);
380 } else {
381 this->append_load_d(&p);
382 this->append_blend(&p);
383 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
384 }
Mike Klein130863e2016-10-27 11:29:36 -0400385 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400386 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400387 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400388 }
389
Mike Klein0a76b412017-05-22 12:01:59 -0400390 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400391 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400392 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400393 this->append_load_d(&p);
394 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400395 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400396 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400397 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400398 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400399 }
400
401 int x = clip.left();
402 for (int y = clip.top(); y < clip.bottom(); y++) {
403 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500404 fCurrentY = y;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400405
Mike Klein3b840e92017-05-23 15:06:17 -0400406 this->maybe_shade(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700407 switch (mask.fFormat) {
408 case SkMask::kA8_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400409 fMaskPtr = mask.getAddr8(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400410 fBlitMaskA8(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700411 break;
412 case SkMask::kLCD16_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400413 fMaskPtr = mask.getAddrLCD16(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400414 fBlitMaskLCD16(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700415 break;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400416 default:
417 // TODO
418 break;
mtklein9a5c47f2016-07-22 11:05:04 -0700419 }
mtklein9a5c47f2016-07-22 11:05:04 -0700420 }
421}