blob: a34609ff80d37899fbdbd3938c4c258659d4f103 [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 Reed98b7a6a2017-05-26 09:32:22 -040096 bool wants_dither = paint.isDither();
97
98#ifdef SK_SUPPORT_LEGACY_RASTERPIPELINE
99 wants_dither = shader && shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType;
100#endif
Mike Klein3b840e92017-05-23 15:06:17 -0400101
102 SkRasterPipeline_<256> shaderPipeline;
103 if (!shader) {
104 // Having no shader makes things nice and easy... just use the paint color.
105 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
106 bool is_opaque = paintColor->a() == 1.0f,
Mike Reed98b7a6a2017-05-26 09:32:22 -0400107 is_constant = true;
Mike Klein3b840e92017-05-23 15:06:17 -0400108 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
109 shaderPipeline, nullptr,
110 is_opaque, is_constant, wants_dither);
111 }
112
113 bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f;
114 bool is_constant = shader->isConstant();
Mike Klein3b840e92017-05-23 15:06:17 -0400115
116 // See if the shader can express itself by appending pipeline stages.
117 if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
118 if (paintColor->a() != 1.0f) {
119 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
120 }
121 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
122 shaderPipeline, nullptr,
123 is_opaque, is_constant, wants_dither);
124 }
125
126 // No, the shader wants us to create a context and call shadeSpan4f().
127 SkASSERT(!is_constant); // All constant shaders should be able to appendStages().
128
129 if (dstCS) {
130 // We need to transform the shader into the dst color space, and extend its lifetime.
131 sk_sp<SkShader> in_dstCS = SkColorSpaceXformer::Make(sk_ref_sp(dstCS))->apply(shader);
Florin Malita4aed1382017-05-25 10:38:07 -0400132 shader = as_SB(in_dstCS.get());
Mike Klein3b840e92017-05-23 15:06:17 -0400133 alloc->make<sk_sp<SkShader>>(std::move(in_dstCS));
134 }
Florin Malita4aed1382017-05-25 10:38:07 -0400135 SkShaderBase::ContextRec rec(paint, ctm, nullptr, SkShaderBase::ContextRec::kPM4f_DstType,
136 dstCS);
137 SkShaderBase::Context* shaderCtx = shader->makeContext(rec, alloc);
Mike Klein3b840e92017-05-23 15:06:17 -0400138 if (!shaderCtx) {
139 // When a shader fails to create a context, it has vetoed drawing entirely.
140 return alloc->make<SkNullBlitter>();
141 }
142 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
143 shaderPipeline, shaderCtx,
144 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400145}
146
147SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
148 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -0400149 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -0400150 bool is_opaque,
151 bool wants_dither,
Mike Reed02640952017-05-19 15:32:13 -0400152 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400153 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
154 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
Mike Klein3b840e92017-05-23 15:06:17 -0400155 shaderPipeline, nullptr,
156 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400157}
158
Mike Kleinb35cb312017-05-19 12:01:01 -0400159SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
160 const SkPaint& paint,
161 SkArenaAlloc* alloc,
162 const SkRasterPipeline& shaderPipeline,
Florin Malita4aed1382017-05-25 10:38:07 -0400163 SkShaderBase::Context* shaderCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -0400164 bool is_opaque,
165 bool is_constant,
166 bool wants_dither) {
Mike Klein3b840e92017-05-23 15:06:17 -0400167 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst,
168 paint.getBlendMode(),
169 alloc,
170 shaderCtx);
Mike Reed02640952017-05-19 15:32:13 -0400171
Mike Kleinb35cb312017-05-19 12:01:01 -0400172 // Our job in this factory is to fill out the blitter's color pipeline.
173 // This is the common front of the full blit pipelines, each constructed lazily on first use.
174 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
175 auto colorPipeline = &blitter->fColorPipeline;
176
Mike Klein3b840e92017-05-23 15:06:17 -0400177 // Let's get the shader in first.
178 if (shaderCtx) {
179 colorPipeline->append(SkRasterPipeline::load_f32, &blitter->fShaderOutput);
180 } else {
181 // If the shader's not constant, it'll need seeding with x,y.
182 if (!is_constant) {
183 colorPipeline->append(SkRasterPipeline::seed_shader, &blitter->fCurrentY);
184 }
185 colorPipeline->extend(shaderPipeline);
Mike Reed02640952017-05-19 15:32:13 -0400186 }
187
Mike Kleinb35cb312017-05-19 12:01:01 -0400188 // If there's a color filter it comes next.
189 if (auto colorFilter = paint.getColorFilter()) {
190 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700191 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700192 }
193
Mike Kleinb35cb312017-05-19 12:01:01 -0400194 // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to.
195 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
196 // We need to decide if we're going to dither now to keep is_constant accurate.
197 if (wants_dither ||
198 (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) {
199 switch (dst.info().colorType()) {
200 default: blitter->fDitherCtx.rate = 0.0f; break;
201 case kRGB_565_SkColorType: blitter->fDitherCtx.rate = 1/63.0f; break;
202 case kRGBA_8888_SkColorType:
203 case kBGRA_8888_SkColorType: blitter->fDitherCtx.rate = 1/255.0f; break;
204 }
205 }
206 is_constant = is_constant && (blitter->fDitherCtx.rate == 0.0f);
207
208 // We're logically done here. The code between here and return blitter is all optimization.
209
210 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500211 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400212 auto constantColor = alloc->make<SkPM4f>();
213 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
214 colorPipeline->run(0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400215 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400216 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700217
Mike Kleinb35cb312017-05-19 12:01:01 -0400218 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400219 }
mtklein8e4373f2016-07-22 14:20:27 -0700220
Mike Kleinb35cb312017-05-19 12:01:01 -0400221 // We can strength-reduce SrcOver into Src when opaque.
222 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
223 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700224 }
225
Mike Kleinb35cb312017-05-19 12:01:01 -0400226 // When we're drawing a constant color in Src mode, we can sometimes just memset.
227 // (The previous two optimizations help find more opportunities for this one.)
228 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
229 // Run our color pipeline all the way through to produce what we'd memset when we can.
230 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400231 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400232 p.extend(*colorPipeline);
233 blitter->fDstPtr = &blitter->fMemsetColor;
234 blitter->append_store(&p);
Mike Klein319ba3d2017-01-20 15:11:54 -0500235 p.run(0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500236
Mike Kleinb35cb312017-05-19 12:01:01 -0400237 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500238 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400239
240 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700241}
242
Mike Kleine902f8d2016-10-26 15:32:26 -0400243void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500244 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700245 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500246 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500247 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500248 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500249 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
250 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700251 default: break;
252 }
Mike Kleine03339a2016-11-28 13:24:27 -0500253 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500254 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500255 }
256 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500257 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500258 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500259 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700260}
261
Mike Klein14c8f822016-11-30 19:39:43 -0500262void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400263 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500264 p->append(SkRasterPipeline::to_srgb);
265 }
Mike Kleindb711c92017-05-03 17:57:48 -0400266 if (fDitherCtx.rate > 0.0f) {
267 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
268 // over the whole range. If we did it before, 1/255.0f is too big a rate near zero.
269 p->append(SkRasterPipeline::dither, &fDitherCtx);
270 }
271
Mike Kleine03339a2016-11-28 13:24:27 -0500272 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
273 p->append(SkRasterPipeline::swap_rb);
274 }
mtklein8e4373f2016-07-22 14:20:27 -0700275 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500276 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500277 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
278 case kBGRA_8888_SkColorType:
279 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
280 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700281 default: break;
282 }
283}
284
Mike Kleine902f8d2016-10-26 15:32:26 -0400285void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleinbb338332017-05-04 12:42:52 -0400286 SkBlendMode_AppendStages(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400287}
Mike Kleine9f74b82016-10-25 13:31:21 -0400288
Mike Klein130863e2016-10-27 11:29:36 -0400289void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleine03339a2016-11-28 13:24:27 -0500290 if (SkBlendMode_CanOverflow(fBlend)) {
291 p->append(SkRasterPipeline::clamp_a);
292 }
Mike Klein130863e2016-10-27 11:29:36 -0400293}
294
Mike Klein3b840e92017-05-23 15:06:17 -0400295void SkRasterPipelineBlitter::maybe_shade(int x, int y, int w) {
296 if (fShaderCtx) {
297 if (w > SkToInt(fShaderBuffer.size())) {
298 fShaderBuffer.resize(w);
299 }
300 fShaderCtx->shadeSpan4f(x,y, fShaderBuffer.data(), w);
301 // We'll be reading from fShaderOutput + x.
302 fShaderOutput = fShaderBuffer.data() - x;
303 }
304}
305
mtklein9a5c47f2016-07-22 11:05:04 -0700306void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500307 fDstPtr = fDst.writable_addr(0,y);
308 fCurrentY = y;
309
310 if (fCanMemsetInBlitH) {
311 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000312 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
313 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
314 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
315 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500316 default: break;
317 }
318 }
319
Mike Klein0a76b412017-05-22 12:01:59 -0400320 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400321 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400322 p.extend(fColorPipeline);
Mike Klein50626262017-05-25 13:06:57 -0400323 if (fBlend == SkBlendMode::kSrcOver
324 && fDst.info().colorType() == kRGBA_8888_SkColorType
325 && !fDst.colorSpace()
326 && fDitherCtx.rate == 0.0f) {
327 p.append(SkRasterPipeline::srcover_rgba_8888, &fDstPtr);
328 } else {
329 if (fBlend != SkBlendMode::kSrc) {
330 this->append_load_d(&p);
331 this->append_blend(&p);
332 this->maybe_clamp(&p);
333 }
334 this->append_store(&p);
Mike Klein66866172016-11-03 12:22:01 -0400335 }
Mike Kleinb24704d2017-05-24 07:53:00 -0400336 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400337 }
Mike Klein3b840e92017-05-23 15:06:17 -0400338 this->maybe_shade(x,y,w);
Mike Klein0a76b412017-05-22 12:01:59 -0400339 fBlitH(x,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700340}
341
342void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400343 if (!fBlitAntiH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400344 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400345 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400346 if (fBlend == SkBlendMode::kSrcOver) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500347 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400348 this->append_load_d(&p);
349 this->append_blend(&p);
350 } else {
351 this->append_load_d(&p);
352 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500353 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400354 }
Mike Klein130863e2016-10-27 11:29:36 -0400355 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400356 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400357 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400358 }
mtklein9a5c47f2016-07-22 11:05:04 -0700359
Mike Kleinbd3fe472016-10-25 15:43:46 -0400360 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500361 fCurrentY = y;
mtklein9a5c47f2016-07-22 11:05:04 -0700362 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500363 switch (*aa) {
364 case 0x00: break;
365 case 0xff: this->blitH(x,y,run); break;
366 default:
Mike Klein3b840e92017-05-23 15:06:17 -0400367 this->maybe_shade(x,y,run);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500368 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein0a76b412017-05-22 12:01:59 -0400369 fBlitAntiH(x,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500370 }
mtklein9a5c47f2016-07-22 11:05:04 -0700371 x += run;
372 runs += run;
373 aa += run;
374 }
375}
376
377void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
378 if (mask.fFormat == SkMask::kBW_Format) {
379 // TODO: native BW masks?
380 return INHERITED::blitMask(mask, clip);
381 }
382
Mike Klein0a76b412017-05-22 12:01:59 -0400383 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400384 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400385 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400386 if (fBlend == SkBlendMode::kSrcOver) {
387 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
388 this->append_load_d(&p);
389 this->append_blend(&p);
390 } else {
391 this->append_load_d(&p);
392 this->append_blend(&p);
393 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
394 }
Mike Klein130863e2016-10-27 11:29:36 -0400395 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400396 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400397 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400398 }
399
Mike Klein0a76b412017-05-22 12:01:59 -0400400 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400401 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400402 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400403 this->append_load_d(&p);
404 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400405 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400406 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400407 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400408 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400409 }
410
411 int x = clip.left();
412 for (int y = clip.top(); y < clip.bottom(); y++) {
413 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500414 fCurrentY = y;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400415
Mike Klein3b840e92017-05-23 15:06:17 -0400416 this->maybe_shade(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700417 switch (mask.fFormat) {
418 case SkMask::kA8_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400419 fMaskPtr = mask.getAddr8(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400420 fBlitMaskA8(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700421 break;
422 case SkMask::kLCD16_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400423 fMaskPtr = mask.getAddrLCD16(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400424 fBlitMaskLCD16(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700425 break;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400426 default:
427 // TODO
428 break;
mtklein9a5c47f2016-07-22 11:05:04 -0700429 }
mtklein9a5c47f2016-07-22 11:05:04 -0700430 }
431}