blob: 59fb172170b3c64760e14f0f1452e1c44089b57e [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 Klein761d27c2017-06-01 12:37:08 -040070 std::function<void(size_t, 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;
Mike Klein9b10f8f2017-06-01 13:11:16 -040081 float fDitherRate = 0.0f;
Mike Kleinbd3fe472016-10-25 15:43:46 -040082
Mike Klein3b840e92017-05-23 15:06:17 -040083 std::vector<SkPM4f> fShaderBuffer;
84
mtklein9a5c47f2016-07-22 11:05:04 -070085 typedef SkBlitter INHERITED;
86};
87
88SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
89 const SkPaint& paint,
Mike Kleinfb191da2016-11-15 13:20:33 -050090 const SkMatrix& ctm,
Matt Sarett25834ff2017-02-15 15:54:35 -050091 SkArenaAlloc* alloc) {
Mike Klein3b840e92017-05-23 15:06:17 -040092 SkColorSpace* dstCS = dst.colorSpace();
93 auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), dstCS));
Florin Malita4aed1382017-05-25 10:38:07 -040094 auto shader = as_SB(paint.getShader());
Mike Reed98b7a6a2017-05-26 09:32:22 -040095 bool wants_dither = paint.isDither();
96
97#ifdef SK_SUPPORT_LEGACY_RASTERPIPELINE
98 wants_dither = shader && shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType;
99#endif
Mike Klein3b840e92017-05-23 15:06:17 -0400100
101 SkRasterPipeline_<256> shaderPipeline;
102 if (!shader) {
103 // Having no shader makes things nice and easy... just use the paint color.
104 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
105 bool is_opaque = paintColor->a() == 1.0f,
Mike Reed98b7a6a2017-05-26 09:32:22 -0400106 is_constant = true;
Mike Klein3b840e92017-05-23 15:06:17 -0400107 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
108 shaderPipeline, nullptr,
109 is_opaque, is_constant, wants_dither);
110 }
111
112 bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f;
113 bool is_constant = shader->isConstant();
Mike Klein3b840e92017-05-23 15:06:17 -0400114
115 // See if the shader can express itself by appending pipeline stages.
116 if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
117 if (paintColor->a() != 1.0f) {
118 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
119 }
120 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
121 shaderPipeline, nullptr,
122 is_opaque, is_constant, wants_dither);
123 }
124
125 // No, the shader wants us to create a context and call shadeSpan4f().
126 SkASSERT(!is_constant); // All constant shaders should be able to appendStages().
127
128 if (dstCS) {
129 // We need to transform the shader into the dst color space, and extend its lifetime.
130 sk_sp<SkShader> in_dstCS = SkColorSpaceXformer::Make(sk_ref_sp(dstCS))->apply(shader);
Florin Malita4aed1382017-05-25 10:38:07 -0400131 shader = as_SB(in_dstCS.get());
Mike Klein3b840e92017-05-23 15:06:17 -0400132 alloc->make<sk_sp<SkShader>>(std::move(in_dstCS));
133 }
Florin Malita4aed1382017-05-25 10:38:07 -0400134 SkShaderBase::ContextRec rec(paint, ctm, nullptr, SkShaderBase::ContextRec::kPM4f_DstType,
135 dstCS);
136 SkShaderBase::Context* shaderCtx = shader->makeContext(rec, alloc);
Mike Klein3b840e92017-05-23 15:06:17 -0400137 if (!shaderCtx) {
138 // When a shader fails to create a context, it has vetoed drawing entirely.
139 return alloc->make<SkNullBlitter>();
140 }
141 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
142 shaderPipeline, shaderCtx,
143 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400144}
145
146SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
147 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -0400148 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -0400149 bool is_opaque,
150 bool wants_dither,
Mike Reed02640952017-05-19 15:32:13 -0400151 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400152 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
153 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
Mike Klein3b840e92017-05-23 15:06:17 -0400154 shaderPipeline, nullptr,
155 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400156}
157
Mike Kleinb35cb312017-05-19 12:01:01 -0400158SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
159 const SkPaint& paint,
160 SkArenaAlloc* alloc,
161 const SkRasterPipeline& shaderPipeline,
Florin Malita4aed1382017-05-25 10:38:07 -0400162 SkShaderBase::Context* shaderCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -0400163 bool is_opaque,
164 bool is_constant,
165 bool wants_dither) {
Mike Klein3b840e92017-05-23 15:06:17 -0400166 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst,
167 paint.getBlendMode(),
168 alloc,
169 shaderCtx);
Mike Reed02640952017-05-19 15:32:13 -0400170
Mike Kleinb35cb312017-05-19 12:01:01 -0400171 // Our job in this factory is to fill out the blitter's color pipeline.
172 // This is the common front of the full blit pipelines, each constructed lazily on first use.
173 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
174 auto colorPipeline = &blitter->fColorPipeline;
175
Mike Klein3b840e92017-05-23 15:06:17 -0400176 // Let's get the shader in first.
177 if (shaderCtx) {
178 colorPipeline->append(SkRasterPipeline::load_f32, &blitter->fShaderOutput);
179 } else {
180 // If the shader's not constant, it'll need seeding with x,y.
181 if (!is_constant) {
Mike Klein9b10f8f2017-06-01 13:11:16 -0400182 colorPipeline->append(SkRasterPipeline::seed_shader);
Mike Klein3b840e92017-05-23 15:06:17 -0400183 }
184 colorPipeline->extend(shaderPipeline);
Mike Reed02640952017-05-19 15:32:13 -0400185 }
186
Mike Kleinb35cb312017-05-19 12:01:01 -0400187 // If there's a color filter it comes next.
188 if (auto colorFilter = paint.getColorFilter()) {
189 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700190 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700191 }
192
Mike Kleinb35cb312017-05-19 12:01:01 -0400193 // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to.
194 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
195 // We need to decide if we're going to dither now to keep is_constant accurate.
196 if (wants_dither ||
197 (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) {
198 switch (dst.info().colorType()) {
Mike Klein9b10f8f2017-06-01 13:11:16 -0400199 default: blitter->fDitherRate = 0.0f; break;
200 case kRGB_565_SkColorType: blitter->fDitherRate = 1/63.0f; break;
Mike Kleinb35cb312017-05-19 12:01:01 -0400201 case kRGBA_8888_SkColorType:
Mike Klein9b10f8f2017-06-01 13:11:16 -0400202 case kBGRA_8888_SkColorType: blitter->fDitherRate = 1/255.0f; break;
Mike Kleinb35cb312017-05-19 12:01:01 -0400203 }
204 }
Mike Klein9b10f8f2017-06-01 13:11:16 -0400205 is_constant = is_constant && (blitter->fDitherRate == 0.0f);
Mike Kleinb35cb312017-05-19 12:01:01 -0400206
207 // We're logically done here. The code between here and return blitter is all optimization.
208
209 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500210 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400211 auto constantColor = alloc->make<SkPM4f>();
212 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
Mike Klein761d27c2017-06-01 12:37:08 -0400213 colorPipeline->run(0,0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400214 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400215 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700216
Mike Kleinb35cb312017-05-19 12:01:01 -0400217 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400218 }
mtklein8e4373f2016-07-22 14:20:27 -0700219
Mike Kleinb35cb312017-05-19 12:01:01 -0400220 // We can strength-reduce SrcOver into Src when opaque.
221 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
222 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700223 }
224
Mike Kleinb35cb312017-05-19 12:01:01 -0400225 // When we're drawing a constant color in Src mode, we can sometimes just memset.
226 // (The previous two optimizations help find more opportunities for this one.)
227 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
228 // Run our color pipeline all the way through to produce what we'd memset when we can.
229 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400230 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400231 p.extend(*colorPipeline);
232 blitter->fDstPtr = &blitter->fMemsetColor;
233 blitter->append_store(&p);
Mike Klein761d27c2017-06-01 12:37:08 -0400234 p.run(0,0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500235
Mike Kleinb35cb312017-05-19 12:01:01 -0400236 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500237 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400238
239 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700240}
241
Mike Kleine902f8d2016-10-26 15:32:26 -0400242void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500243 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700244 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500245 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500246 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500247 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500248 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
249 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700250 default: break;
251 }
Mike Kleine03339a2016-11-28 13:24:27 -0500252 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500253 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500254 }
255 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500256 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500257 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500258 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700259}
260
Mike Klein14c8f822016-11-30 19:39:43 -0500261void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400262 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500263 p->append(SkRasterPipeline::to_srgb);
264 }
Mike Klein9b10f8f2017-06-01 13:11:16 -0400265 if (fDitherRate > 0.0f) {
Mike Kleindb711c92017-05-03 17:57:48 -0400266 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
267 // over the whole range. If we did it before, 1/255.0f is too big a rate near zero.
Mike Klein9b10f8f2017-06-01 13:11:16 -0400268 p->append(SkRasterPipeline::dither, &fDitherRate);
Mike Kleindb711c92017-05-03 17:57:48 -0400269 }
270
Mike Kleine03339a2016-11-28 13:24:27 -0500271 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
272 p->append(SkRasterPipeline::swap_rb);
273 }
mtklein8e4373f2016-07-22 14:20:27 -0700274 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500275 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500276 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
277 case kBGRA_8888_SkColorType:
278 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
279 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700280 default: break;
281 }
282}
283
Mike Kleine902f8d2016-10-26 15:32:26 -0400284void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleinbb338332017-05-04 12:42:52 -0400285 SkBlendMode_AppendStages(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400286}
Mike Kleine9f74b82016-10-25 13:31:21 -0400287
Mike Klein130863e2016-10-27 11:29:36 -0400288void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleine03339a2016-11-28 13:24:27 -0500289 if (SkBlendMode_CanOverflow(fBlend)) {
290 p->append(SkRasterPipeline::clamp_a);
291 }
Mike Klein130863e2016-10-27 11:29:36 -0400292}
293
Mike Klein3b840e92017-05-23 15:06:17 -0400294void SkRasterPipelineBlitter::maybe_shade(int x, int y, int w) {
295 if (fShaderCtx) {
296 if (w > SkToInt(fShaderBuffer.size())) {
297 fShaderBuffer.resize(w);
298 }
299 fShaderCtx->shadeSpan4f(x,y, fShaderBuffer.data(), w);
300 // We'll be reading from fShaderOutput + x.
301 fShaderOutput = fShaderBuffer.data() - x;
302 }
303}
304
mtklein9a5c47f2016-07-22 11:05:04 -0700305void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500306 fDstPtr = fDst.writable_addr(0,y);
Mike Klein8729e5b2017-02-16 06:51:48 -0500307
308 if (fCanMemsetInBlitH) {
309 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000310 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
311 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
312 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
313 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500314 default: break;
315 }
316 }
317
Mike Klein0a76b412017-05-22 12:01:59 -0400318 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400319 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400320 p.extend(fColorPipeline);
Mike Klein50626262017-05-25 13:06:57 -0400321 if (fBlend == SkBlendMode::kSrcOver
322 && fDst.info().colorType() == kRGBA_8888_SkColorType
323 && !fDst.colorSpace()
Mike Klein9b10f8f2017-06-01 13:11:16 -0400324 && fDitherRate == 0.0f) {
Mike Klein50626262017-05-25 13:06:57 -0400325 p.append(SkRasterPipeline::srcover_rgba_8888, &fDstPtr);
326 } else {
327 if (fBlend != SkBlendMode::kSrc) {
328 this->append_load_d(&p);
329 this->append_blend(&p);
330 this->maybe_clamp(&p);
331 }
332 this->append_store(&p);
Mike Klein66866172016-11-03 12:22:01 -0400333 }
Mike Kleinb24704d2017-05-24 07:53:00 -0400334 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400335 }
Mike Klein3b840e92017-05-23 15:06:17 -0400336 this->maybe_shade(x,y,w);
Mike Klein761d27c2017-06-01 12:37:08 -0400337 fBlitH(x,y,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700338}
339
340void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400341 if (!fBlitAntiH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400342 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400343 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400344 if (fBlend == SkBlendMode::kSrcOver) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500345 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400346 this->append_load_d(&p);
347 this->append_blend(&p);
348 } else {
349 this->append_load_d(&p);
350 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500351 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400352 }
Mike Klein130863e2016-10-27 11:29:36 -0400353 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400354 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400355 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400356 }
mtklein9a5c47f2016-07-22 11:05:04 -0700357
Mike Kleinbd3fe472016-10-25 15:43:46 -0400358 fDstPtr = fDst.writable_addr(0,y);
mtklein9a5c47f2016-07-22 11:05:04 -0700359 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500360 switch (*aa) {
361 case 0x00: break;
362 case 0xff: this->blitH(x,y,run); break;
363 default:
Mike Klein3b840e92017-05-23 15:06:17 -0400364 this->maybe_shade(x,y,run);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500365 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein761d27c2017-06-01 12:37:08 -0400366 fBlitAntiH(x,y,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500367 }
mtklein9a5c47f2016-07-22 11:05:04 -0700368 x += run;
369 runs += run;
370 aa += run;
371 }
372}
373
374void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
375 if (mask.fFormat == SkMask::kBW_Format) {
376 // TODO: native BW masks?
377 return INHERITED::blitMask(mask, clip);
378 }
379
Mike Klein0a76b412017-05-22 12:01:59 -0400380 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400381 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400382 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400383 if (fBlend == SkBlendMode::kSrcOver) {
384 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
385 this->append_load_d(&p);
386 this->append_blend(&p);
387 } else {
388 this->append_load_d(&p);
389 this->append_blend(&p);
390 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
391 }
Mike Klein130863e2016-10-27 11:29:36 -0400392 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400393 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400394 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400395 }
396
Mike Klein0a76b412017-05-22 12:01:59 -0400397 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400398 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400399 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400400 this->append_load_d(&p);
401 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400402 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400403 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400404 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400405 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400406 }
407
408 int x = clip.left();
409 for (int y = clip.top(); y < clip.bottom(); y++) {
410 fDstPtr = fDst.writable_addr(0,y);
411
Mike Klein3b840e92017-05-23 15:06:17 -0400412 this->maybe_shade(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700413 switch (mask.fFormat) {
414 case SkMask::kA8_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400415 fMaskPtr = mask.getAddr8(x,y)-x;
Mike Klein761d27c2017-06-01 12:37:08 -0400416 fBlitMaskA8(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700417 break;
418 case SkMask::kLCD16_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400419 fMaskPtr = mask.getAddrLCD16(x,y)-x;
Mike Klein761d27c2017-06-01 12:37:08 -0400420 fBlitMaskLCD16(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700421 break;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400422 default:
423 // TODO
424 break;
mtklein9a5c47f2016-07-22 11:05:04 -0700425 }
mtklein9a5c47f2016-07-22 11:05:04 -0700426 }
427}