blob: 023ff1e234ef9aec283880ce388e03e5b73a626d [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"
Mike Klein14c8f822016-11-30 19:39:43 -050019#include "SkUtils.h"
Mike Klein581e6982017-05-03 13:05:13 -040020#include "../jumper/SkJumper.h"
mtklein9a5c47f2016-07-22 11:05:04 -070021
Mike Klein4e3bc862017-05-22 20:15:17 +000022class SkRasterPipelineBlitter final : public SkBlitter {
mtklein9a5c47f2016-07-22 11:05:04 -070023public:
Mike Klein3b840e92017-05-23 15:06:17 -040024 // This is our common entrypoint for creating the blitter once we've sorted out shaders.
Mike Kleinb35cb312017-05-19 12:01:01 -040025 static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*,
Mike Klein3b840e92017-05-23 15:06:17 -040026 const SkRasterPipeline& shaderPipeline, SkShader::Context* shaderCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -040027 bool is_opaque, bool is_constant, bool wants_dither);
28
Mike Klein3b840e92017-05-23 15:06:17 -040029 SkRasterPipelineBlitter(SkPixmap dst,
30 SkBlendMode blend,
31 SkArenaAlloc* alloc,
32 SkShader::Context* shaderCtx)
mtklein9a5c47f2016-07-22 11:05:04 -070033 : fDst(dst)
Mike Kleine902f8d2016-10-26 15:32:26 -040034 , fBlend(blend)
Mike Klein0a76b412017-05-22 12:01:59 -040035 , fAlloc(alloc)
Mike Klein3b840e92017-05-23 15:06:17 -040036 , fShaderCtx(shaderCtx)
Mike Kleinb24704d2017-05-24 07:53:00 -040037 , fColorPipeline(alloc)
mtklein9a5c47f2016-07-22 11:05:04 -070038 {}
39
40 void blitH (int x, int y, int w) override;
41 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
42 void blitMask (const SkMask&, const SkIRect& clip) override;
43
44 // TODO: The default implementations of the other blits look fine,
45 // but some of them like blitV could probably benefit from custom
46 // blits using something like a SkRasterPipeline::runFew() method.
47
48private:
Mike Klein14c8f822016-11-30 19:39:43 -050049 void append_load_d(SkRasterPipeline*) const;
50 void append_blend (SkRasterPipeline*) const;
51 void maybe_clamp (SkRasterPipeline*) const;
52 void append_store (SkRasterPipeline*) const;
mtklein8e4373f2016-07-22 14:20:27 -070053
Mike Klein3b840e92017-05-23 15:06:17 -040054 // If we have an SkShader::Context, use it to fill our shader buffer.
55 void maybe_shade(int x, int y, int w);
56
57 SkPixmap fDst;
58 SkBlendMode fBlend;
59 SkArenaAlloc* fAlloc;
60 SkShader::Context* fShaderCtx;
61 SkRasterPipeline fColorPipeline;
mtklein9a5c47f2016-07-22 11:05:04 -070062
Mike Klein8729e5b2017-02-16 06:51:48 -050063 // We may be able to specialize blitH() into a memset.
64 bool fCanMemsetInBlitH = false;
65 uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16.
Mike Kleinbd3fe472016-10-25 15:43:46 -040066
Mike Klein8729e5b2017-02-16 06:51:48 -050067 // Built lazily on first use.
Mike Klein0a76b412017-05-22 12:01:59 -040068 std::function<void(size_t, size_t)> fBlitH,
69 fBlitAntiH,
70 fBlitMaskA8,
71 fBlitMaskLCD16;
Mike Klein8729e5b2017-02-16 06:51:48 -050072
73 // These values are pointed to by the blit pipelines above,
74 // which allows us to adjust them from call to call.
Mike Klein3b840e92017-05-23 15:06:17 -040075 void* fShaderOutput = nullptr;
Mike Kleindb711c92017-05-03 17:57:48 -040076 void* fDstPtr = nullptr;
77 const void* fMaskPtr = nullptr;
78 float fCurrentCoverage = 0.0f;
79 int fCurrentY = 0;
80 SkJumper_DitherCtx fDitherCtx = { &fCurrentY, 0.0f };
Mike Kleinbd3fe472016-10-25 15:43:46 -040081
Mike Klein3b840e92017-05-23 15:06:17 -040082 std::vector<SkPM4f> fShaderBuffer;
83
mtklein9a5c47f2016-07-22 11:05:04 -070084 typedef SkBlitter INHERITED;
85};
86
87SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
88 const SkPaint& paint,
Mike Kleinfb191da2016-11-15 13:20:33 -050089 const SkMatrix& ctm,
Matt Sarett25834ff2017-02-15 15:54:35 -050090 SkArenaAlloc* alloc) {
Mike Klein3b840e92017-05-23 15:06:17 -040091 SkColorSpace* dstCS = dst.colorSpace();
92 auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), dstCS));
93 auto shader = paint.getShader();
94
95 SkRasterPipeline_<256> shaderPipeline;
96 if (!shader) {
97 // Having no shader makes things nice and easy... just use the paint color.
98 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
99 bool is_opaque = paintColor->a() == 1.0f,
100 is_constant = true,
101 wants_dither = false;
102 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
103 shaderPipeline, nullptr,
104 is_opaque, is_constant, wants_dither);
105 }
106
107 bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f;
108 bool is_constant = shader->isConstant();
109 bool wants_dither = shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType;
110
111 // See if the shader can express itself by appending pipeline stages.
112 if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
113 if (paintColor->a() != 1.0f) {
114 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
115 }
116 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
117 shaderPipeline, nullptr,
118 is_opaque, is_constant, wants_dither);
119 }
120
121 // No, the shader wants us to create a context and call shadeSpan4f().
122 SkASSERT(!is_constant); // All constant shaders should be able to appendStages().
123
124 if (dstCS) {
125 // We need to transform the shader into the dst color space, and extend its lifetime.
126 sk_sp<SkShader> in_dstCS = SkColorSpaceXformer::Make(sk_ref_sp(dstCS))->apply(shader);
127 shader = in_dstCS.get();
128 alloc->make<sk_sp<SkShader>>(std::move(in_dstCS));
129 }
130 SkShader::ContextRec rec(paint, ctm, nullptr, SkShader::ContextRec::kPM4f_DstType, dstCS);
131 SkShader::Context* shaderCtx = shader->makeContext(rec, alloc);
132 if (!shaderCtx) {
133 // When a shader fails to create a context, it has vetoed drawing entirely.
134 return alloc->make<SkNullBlitter>();
135 }
136 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
137 shaderPipeline, shaderCtx,
138 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400139}
140
141SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
142 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -0400143 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -0400144 bool is_opaque,
145 bool wants_dither,
Mike Reed02640952017-05-19 15:32:13 -0400146 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400147 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
148 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
Mike Klein3b840e92017-05-23 15:06:17 -0400149 shaderPipeline, nullptr,
150 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400151}
152
Mike Kleinb35cb312017-05-19 12:01:01 -0400153SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
154 const SkPaint& paint,
155 SkArenaAlloc* alloc,
156 const SkRasterPipeline& shaderPipeline,
Mike Klein3b840e92017-05-23 15:06:17 -0400157 SkShader::Context* shaderCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -0400158 bool is_opaque,
159 bool is_constant,
160 bool wants_dither) {
Mike Klein3b840e92017-05-23 15:06:17 -0400161 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst,
162 paint.getBlendMode(),
163 alloc,
164 shaderCtx);
Mike Reed02640952017-05-19 15:32:13 -0400165
Mike Kleinb35cb312017-05-19 12:01:01 -0400166 // Our job in this factory is to fill out the blitter's color pipeline.
167 // This is the common front of the full blit pipelines, each constructed lazily on first use.
168 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
169 auto colorPipeline = &blitter->fColorPipeline;
170
Mike Klein3b840e92017-05-23 15:06:17 -0400171 // Let's get the shader in first.
172 if (shaderCtx) {
173 colorPipeline->append(SkRasterPipeline::load_f32, &blitter->fShaderOutput);
174 } else {
175 // If the shader's not constant, it'll need seeding with x,y.
176 if (!is_constant) {
177 colorPipeline->append(SkRasterPipeline::seed_shader, &blitter->fCurrentY);
178 }
179 colorPipeline->extend(shaderPipeline);
Mike Reed02640952017-05-19 15:32:13 -0400180 }
181
Mike Kleinb35cb312017-05-19 12:01:01 -0400182 // If there's a color filter it comes next.
183 if (auto colorFilter = paint.getColorFilter()) {
184 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700185 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700186 }
187
Mike Kleinb35cb312017-05-19 12:01:01 -0400188 // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to.
189 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
190 // We need to decide if we're going to dither now to keep is_constant accurate.
191 if (wants_dither ||
192 (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) {
193 switch (dst.info().colorType()) {
194 default: blitter->fDitherCtx.rate = 0.0f; break;
195 case kRGB_565_SkColorType: blitter->fDitherCtx.rate = 1/63.0f; break;
196 case kRGBA_8888_SkColorType:
197 case kBGRA_8888_SkColorType: blitter->fDitherCtx.rate = 1/255.0f; break;
198 }
199 }
200 is_constant = is_constant && (blitter->fDitherCtx.rate == 0.0f);
201
202 // We're logically done here. The code between here and return blitter is all optimization.
203
204 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500205 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400206 auto constantColor = alloc->make<SkPM4f>();
207 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
208 colorPipeline->run(0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400209 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400210 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700211
Mike Kleinb35cb312017-05-19 12:01:01 -0400212 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400213 }
mtklein8e4373f2016-07-22 14:20:27 -0700214
Mike Kleinb35cb312017-05-19 12:01:01 -0400215 // We can strength-reduce SrcOver into Src when opaque.
216 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
217 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700218 }
219
Mike Kleinb35cb312017-05-19 12:01:01 -0400220 // When we're drawing a constant color in Src mode, we can sometimes just memset.
221 // (The previous two optimizations help find more opportunities for this one.)
222 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
223 // Run our color pipeline all the way through to produce what we'd memset when we can.
224 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400225 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400226 p.extend(*colorPipeline);
227 blitter->fDstPtr = &blitter->fMemsetColor;
228 blitter->append_store(&p);
Mike Klein319ba3d2017-01-20 15:11:54 -0500229 p.run(0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500230
Mike Kleinb35cb312017-05-19 12:01:01 -0400231 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500232 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400233
234 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700235}
236
Mike Kleine902f8d2016-10-26 15:32:26 -0400237void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500238 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700239 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500240 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500241 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500242 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500243 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
244 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700245 default: break;
246 }
Mike Kleine03339a2016-11-28 13:24:27 -0500247 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500248 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500249 }
250 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500251 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500252 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500253 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700254}
255
Mike Klein14c8f822016-11-30 19:39:43 -0500256void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400257 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500258 p->append(SkRasterPipeline::to_srgb);
259 }
Mike Kleindb711c92017-05-03 17:57:48 -0400260 if (fDitherCtx.rate > 0.0f) {
261 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
262 // over the whole range. If we did it before, 1/255.0f is too big a rate near zero.
263 p->append(SkRasterPipeline::dither, &fDitherCtx);
264 }
265
Mike Kleine03339a2016-11-28 13:24:27 -0500266 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
267 p->append(SkRasterPipeline::swap_rb);
268 }
mtklein8e4373f2016-07-22 14:20:27 -0700269 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500270 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500271 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
272 case kBGRA_8888_SkColorType:
273 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
274 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700275 default: break;
276 }
277}
278
Mike Kleine902f8d2016-10-26 15:32:26 -0400279void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleinbb338332017-05-04 12:42:52 -0400280 SkBlendMode_AppendStages(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400281}
Mike Kleine9f74b82016-10-25 13:31:21 -0400282
Mike Klein130863e2016-10-27 11:29:36 -0400283void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleine03339a2016-11-28 13:24:27 -0500284 if (SkBlendMode_CanOverflow(fBlend)) {
285 p->append(SkRasterPipeline::clamp_a);
286 }
Mike Klein130863e2016-10-27 11:29:36 -0400287}
288
Mike Klein3b840e92017-05-23 15:06:17 -0400289void SkRasterPipelineBlitter::maybe_shade(int x, int y, int w) {
290 if (fShaderCtx) {
291 if (w > SkToInt(fShaderBuffer.size())) {
292 fShaderBuffer.resize(w);
293 }
294 fShaderCtx->shadeSpan4f(x,y, fShaderBuffer.data(), w);
295 // We'll be reading from fShaderOutput + x.
296 fShaderOutput = fShaderBuffer.data() - x;
297 }
298}
299
mtklein9a5c47f2016-07-22 11:05:04 -0700300void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500301 fDstPtr = fDst.writable_addr(0,y);
302 fCurrentY = y;
303
304 if (fCanMemsetInBlitH) {
305 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000306 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
307 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
308 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
309 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500310 default: break;
311 }
312 }
313
Mike Klein0a76b412017-05-22 12:01:59 -0400314 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400315 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400316 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400317 if (fBlend != SkBlendMode::kSrc) {
318 this->append_load_d(&p);
319 this->append_blend(&p);
320 this->maybe_clamp(&p);
321 }
Mike Kleine902f8d2016-10-26 15:32:26 -0400322 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400323 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400324 }
Mike Klein3b840e92017-05-23 15:06:17 -0400325 this->maybe_shade(x,y,w);
Mike Klein0a76b412017-05-22 12:01:59 -0400326 fBlitH(x,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700327}
328
329void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400330 if (!fBlitAntiH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400331 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400332 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400333 if (fBlend == SkBlendMode::kSrcOver) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500334 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400335 this->append_load_d(&p);
336 this->append_blend(&p);
337 } else {
338 this->append_load_d(&p);
339 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500340 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400341 }
Mike Klein130863e2016-10-27 11:29:36 -0400342 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400343 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400344 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400345 }
mtklein9a5c47f2016-07-22 11:05:04 -0700346
Mike Kleinbd3fe472016-10-25 15:43:46 -0400347 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500348 fCurrentY = y;
mtklein9a5c47f2016-07-22 11:05:04 -0700349 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500350 switch (*aa) {
351 case 0x00: break;
352 case 0xff: this->blitH(x,y,run); break;
353 default:
Mike Klein3b840e92017-05-23 15:06:17 -0400354 this->maybe_shade(x,y,run);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500355 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein0a76b412017-05-22 12:01:59 -0400356 fBlitAntiH(x,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500357 }
mtklein9a5c47f2016-07-22 11:05:04 -0700358 x += run;
359 runs += run;
360 aa += run;
361 }
362}
363
364void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
365 if (mask.fFormat == SkMask::kBW_Format) {
366 // TODO: native BW masks?
367 return INHERITED::blitMask(mask, clip);
368 }
369
Mike Klein0a76b412017-05-22 12:01:59 -0400370 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400371 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400372 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400373 if (fBlend == SkBlendMode::kSrcOver) {
374 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
375 this->append_load_d(&p);
376 this->append_blend(&p);
377 } else {
378 this->append_load_d(&p);
379 this->append_blend(&p);
380 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
381 }
Mike Klein130863e2016-10-27 11:29:36 -0400382 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400383 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400384 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400385 }
386
Mike Klein0a76b412017-05-22 12:01:59 -0400387 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400388 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400389 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400390 this->append_load_d(&p);
391 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400392 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400393 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400394 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400395 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400396 }
397
398 int x = clip.left();
399 for (int y = clip.top(); y < clip.bottom(); y++) {
400 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500401 fCurrentY = y;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400402
Mike Klein3b840e92017-05-23 15:06:17 -0400403 this->maybe_shade(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700404 switch (mask.fFormat) {
405 case SkMask::kA8_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400406 fMaskPtr = mask.getAddr8(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400407 fBlitMaskA8(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700408 break;
409 case SkMask::kLCD16_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400410 fMaskPtr = mask.getAddrLCD16(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400411 fBlitMaskLCD16(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700412 break;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400413 default:
414 // TODO
415 break;
mtklein9a5c47f2016-07-22 11:05:04 -0700416 }
mtklein9a5c47f2016-07-22 11:05:04 -0700417 }
418}