blob: e5c532597a433b2baea501fa3fe98fc1acc1ee56 [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 Kleinbaaf8ad2016-09-29 09:04:15 -040013#include "SkOpts.h"
mtklein9a5c47f2016-07-22 11:05:04 -070014#include "SkPM4f.h"
Mike Klein744908e2016-11-11 12:51:36 -050015#include "SkPM4fPriv.h"
mtklein9a5c47f2016-07-22 11:05:04 -070016#include "SkRasterPipeline.h"
17#include "SkShader.h"
Mike Klein14c8f822016-11-30 19:39:43 -050018#include "SkUtils.h"
Mike Klein581e6982017-05-03 13:05:13 -040019#include "../jumper/SkJumper.h"
mtklein9a5c47f2016-07-22 11:05:04 -070020
Mike Klein4e3bc862017-05-22 20:15:17 +000021class SkRasterPipelineBlitter final : public SkBlitter {
mtklein9a5c47f2016-07-22 11:05:04 -070022public:
Mike Kleinb35cb312017-05-19 12:01:01 -040023 // Create using paint.getShader() or paint.getColor() if there is no shader.
24 // If there's a shader, we will modulate the shader color by the paint alpha.
25 static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*, const SkMatrix& ctm);
mtklein9a5c47f2016-07-22 11:05:04 -070026
Mike Kleinb35cb312017-05-19 12:01:01 -040027 // Create using pre-built shader pipeline.
28 // This pre-built pipeline must already have handled modulating with the paint alpha.
29 static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*,
30 const SkRasterPipeline& shaderPipeline,
31 bool is_opaque, bool is_constant, bool wants_dither);
32
Mike Klein0a76b412017-05-22 12:01:59 -040033 SkRasterPipelineBlitter(SkPixmap dst, SkBlendMode blend, SkArenaAlloc* alloc)
mtklein9a5c47f2016-07-22 11:05:04 -070034 : fDst(dst)
Mike Kleine902f8d2016-10-26 15:32:26 -040035 , fBlend(blend)
Mike Klein0a76b412017-05-22 12:01:59 -040036 , fAlloc(alloc)
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
mtklein9a5c47f2016-07-22 11:05:04 -070054 SkPixmap fDst;
Mike Kleine902f8d2016-10-26 15:32:26 -040055 SkBlendMode fBlend;
Mike Klein0a76b412017-05-22 12:01:59 -040056 SkArenaAlloc* fAlloc;
Mike Kleinb35cb312017-05-19 12:01:01 -040057 SkRasterPipeline fColorPipeline;
mtklein9a5c47f2016-07-22 11:05:04 -070058
Mike Klein8729e5b2017-02-16 06:51:48 -050059 // We may be able to specialize blitH() into a memset.
60 bool fCanMemsetInBlitH = false;
61 uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16.
Mike Kleinbd3fe472016-10-25 15:43:46 -040062
Mike Klein8729e5b2017-02-16 06:51:48 -050063 // Built lazily on first use.
Mike Klein0a76b412017-05-22 12:01:59 -040064 std::function<void(size_t, size_t)> fBlitH,
65 fBlitAntiH,
66 fBlitMaskA8,
67 fBlitMaskLCD16;
Mike Klein8729e5b2017-02-16 06:51:48 -050068
69 // These values are pointed to by the blit pipelines above,
70 // which allows us to adjust them from call to call.
Mike Kleindb711c92017-05-03 17:57:48 -040071 void* fDstPtr = nullptr;
72 const void* fMaskPtr = nullptr;
73 float fCurrentCoverage = 0.0f;
74 int fCurrentY = 0;
75 SkJumper_DitherCtx fDitherCtx = { &fCurrentY, 0.0f };
Mike Kleinbd3fe472016-10-25 15:43:46 -040076
mtklein9a5c47f2016-07-22 11:05:04 -070077 typedef SkBlitter INHERITED;
78};
79
80SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
81 const SkPaint& paint,
Mike Kleinfb191da2016-11-15 13:20:33 -050082 const SkMatrix& ctm,
Matt Sarett25834ff2017-02-15 15:54:35 -050083 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -040084 return SkRasterPipelineBlitter::Create(dst, paint, alloc, ctm);
Mike Reed02640952017-05-19 15:32:13 -040085}
86
87SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
88 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -040089 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -040090 bool is_opaque,
91 bool wants_dither,
Mike Reed02640952017-05-19 15:32:13 -040092 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -040093 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
94 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
95 shaderPipeline, is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -040096}
97
98SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
99 const SkPaint& paint,
Mike Kleinb35cb312017-05-19 12:01:01 -0400100 SkArenaAlloc* alloc,
101 const SkMatrix& ctm) {
102 auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(),
103 dst.colorSpace()));
Mike Kleinb24704d2017-05-24 07:53:00 -0400104 SkRasterPipeline_<256> shaderPipeline;
Mike Kleinb35cb312017-05-19 12:01:01 -0400105 if (auto shader = paint.getShader()) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400106 if (!shader->appendStages(&shaderPipeline, dst.colorSpace(), alloc, ctm, paint)) {
107 // When a shader fails to append stages, it means it has vetoed drawing entirely.
108 return alloc->make<SkNullBlitter>();
109 }
Mike Reed02640952017-05-19 15:32:13 -0400110
Mike Kleinb35cb312017-05-19 12:01:01 -0400111 bool is_opaque = shader->isOpaque();
112 if (paintColor->a() != 1.0f) {
113 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
114 is_opaque = false;
115 }
Mike Reed02640952017-05-19 15:32:13 -0400116
Mike Kleinb35cb312017-05-19 12:01:01 -0400117 bool is_constant = shader->isConstant();
118 bool wants_dither = shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType;
119 return Create(dst, paint, alloc, shaderPipeline, is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400120 }
121
Mike Kleinb35cb312017-05-19 12:01:01 -0400122 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
123 bool is_opaque = paintColor->a() == 1.0f,
124 is_constant = true,
125 wants_dither = false;
126 return Create(dst, paint, alloc, shaderPipeline, is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400127}
128
Mike Kleinb35cb312017-05-19 12:01:01 -0400129SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
130 const SkPaint& paint,
131 SkArenaAlloc* alloc,
132 const SkRasterPipeline& shaderPipeline,
133 bool is_opaque,
134 bool is_constant,
135 bool wants_dither) {
Mike Klein0a76b412017-05-22 12:01:59 -0400136 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst, paint.getBlendMode(), alloc);
Mike Reed02640952017-05-19 15:32:13 -0400137
Mike Kleinb35cb312017-05-19 12:01:01 -0400138 // Our job in this factory is to fill out the blitter's color pipeline.
139 // This is the common front of the full blit pipelines, each constructed lazily on first use.
140 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
141 auto colorPipeline = &blitter->fColorPipeline;
142
143 // Let's get the shader in first. If the shader's not constant, it'll need seeding with x,y.
144 if (!is_constant) {
145 colorPipeline->append(SkRasterPipeline::seed_shader, &blitter->fCurrentY);
Mike Reed02640952017-05-19 15:32:13 -0400146 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400147 colorPipeline->extend(shaderPipeline);
Mike Reed02640952017-05-19 15:32:13 -0400148
Mike Kleinb35cb312017-05-19 12:01:01 -0400149 // If there's a color filter it comes next.
150 if (auto colorFilter = paint.getColorFilter()) {
151 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700152 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700153 }
154
Mike Kleinb35cb312017-05-19 12:01:01 -0400155 // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to.
156 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
157 // We need to decide if we're going to dither now to keep is_constant accurate.
158 if (wants_dither ||
159 (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) {
160 switch (dst.info().colorType()) {
161 default: blitter->fDitherCtx.rate = 0.0f; break;
162 case kRGB_565_SkColorType: blitter->fDitherCtx.rate = 1/63.0f; break;
163 case kRGBA_8888_SkColorType:
164 case kBGRA_8888_SkColorType: blitter->fDitherCtx.rate = 1/255.0f; break;
165 }
166 }
167 is_constant = is_constant && (blitter->fDitherCtx.rate == 0.0f);
168
169 // We're logically done here. The code between here and return blitter is all optimization.
170
171 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500172 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400173 auto constantColor = alloc->make<SkPM4f>();
174 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
175 colorPipeline->run(0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400176 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400177 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700178
Mike Kleinb35cb312017-05-19 12:01:01 -0400179 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400180 }
mtklein8e4373f2016-07-22 14:20:27 -0700181
Mike Kleinb35cb312017-05-19 12:01:01 -0400182 // We can strength-reduce SrcOver into Src when opaque.
183 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
184 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700185 }
186
Mike Kleinb35cb312017-05-19 12:01:01 -0400187 // When we're drawing a constant color in Src mode, we can sometimes just memset.
188 // (The previous two optimizations help find more opportunities for this one.)
189 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
190 // Run our color pipeline all the way through to produce what we'd memset when we can.
191 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400192 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400193 p.extend(*colorPipeline);
194 blitter->fDstPtr = &blitter->fMemsetColor;
195 blitter->append_store(&p);
Mike Klein319ba3d2017-01-20 15:11:54 -0500196 p.run(0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500197
Mike Kleinb35cb312017-05-19 12:01:01 -0400198 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500199 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400200
201 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700202}
203
Mike Kleine902f8d2016-10-26 15:32:26 -0400204void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500205 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700206 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500207 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500208 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500209 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500210 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
211 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700212 default: break;
213 }
Mike Kleine03339a2016-11-28 13:24:27 -0500214 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500215 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500216 }
217 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500218 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500219 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500220 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700221}
222
Mike Klein14c8f822016-11-30 19:39:43 -0500223void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400224 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500225 p->append(SkRasterPipeline::to_srgb);
226 }
Mike Kleindb711c92017-05-03 17:57:48 -0400227 if (fDitherCtx.rate > 0.0f) {
228 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
229 // over the whole range. If we did it before, 1/255.0f is too big a rate near zero.
230 p->append(SkRasterPipeline::dither, &fDitherCtx);
231 }
232
Mike Kleine03339a2016-11-28 13:24:27 -0500233 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
234 p->append(SkRasterPipeline::swap_rb);
235 }
mtklein8e4373f2016-07-22 14:20:27 -0700236 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500237 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500238 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
239 case kBGRA_8888_SkColorType:
240 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
241 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700242 default: break;
243 }
244}
245
Mike Kleine902f8d2016-10-26 15:32:26 -0400246void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleinbb338332017-05-04 12:42:52 -0400247 SkBlendMode_AppendStages(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400248}
Mike Kleine9f74b82016-10-25 13:31:21 -0400249
Mike Klein130863e2016-10-27 11:29:36 -0400250void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleine03339a2016-11-28 13:24:27 -0500251 if (SkBlendMode_CanOverflow(fBlend)) {
252 p->append(SkRasterPipeline::clamp_a);
253 }
Mike Klein130863e2016-10-27 11:29:36 -0400254}
255
mtklein9a5c47f2016-07-22 11:05:04 -0700256void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500257 fDstPtr = fDst.writable_addr(0,y);
258 fCurrentY = y;
259
260 if (fCanMemsetInBlitH) {
261 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000262 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
263 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
264 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
265 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500266 default: break;
267 }
268 }
269
Mike Klein0a76b412017-05-22 12:01:59 -0400270 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400271 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400272 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400273 if (fBlend != SkBlendMode::kSrc) {
274 this->append_load_d(&p);
275 this->append_blend(&p);
276 this->maybe_clamp(&p);
277 }
Mike Kleine902f8d2016-10-26 15:32:26 -0400278 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400279 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400280 }
Mike Klein0a76b412017-05-22 12:01:59 -0400281 fBlitH(x,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700282}
283
284void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400285 if (!fBlitAntiH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400286 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400287 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400288 if (fBlend == SkBlendMode::kSrcOver) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500289 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400290 this->append_load_d(&p);
291 this->append_blend(&p);
292 } else {
293 this->append_load_d(&p);
294 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500295 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400296 }
Mike Klein130863e2016-10-27 11:29:36 -0400297 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400298 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400299 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400300 }
mtklein9a5c47f2016-07-22 11:05:04 -0700301
Mike Kleinbd3fe472016-10-25 15:43:46 -0400302 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500303 fCurrentY = y;
mtklein9a5c47f2016-07-22 11:05:04 -0700304 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500305 switch (*aa) {
306 case 0x00: break;
307 case 0xff: this->blitH(x,y,run); break;
308 default:
Mike Kleinbabd93e2016-11-30 16:05:10 -0500309 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein0a76b412017-05-22 12:01:59 -0400310 fBlitAntiH(x,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500311 }
mtklein9a5c47f2016-07-22 11:05:04 -0700312 x += run;
313 runs += run;
314 aa += run;
315 }
316}
317
318void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
319 if (mask.fFormat == SkMask::kBW_Format) {
320 // TODO: native BW masks?
321 return INHERITED::blitMask(mask, clip);
322 }
323
Mike Klein0a76b412017-05-22 12:01:59 -0400324 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400325 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400326 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400327 if (fBlend == SkBlendMode::kSrcOver) {
328 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
329 this->append_load_d(&p);
330 this->append_blend(&p);
331 } else {
332 this->append_load_d(&p);
333 this->append_blend(&p);
334 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
335 }
Mike Klein130863e2016-10-27 11:29:36 -0400336 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400337 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400338 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400339 }
340
Mike Klein0a76b412017-05-22 12:01:59 -0400341 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400342 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400343 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400344 this->append_load_d(&p);
345 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400346 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400347 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400348 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400349 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400350 }
351
352 int x = clip.left();
353 for (int y = clip.top(); y < clip.bottom(); y++) {
354 fDstPtr = fDst.writable_addr(0,y);
Mike Klein319ba3d2017-01-20 15:11:54 -0500355 fCurrentY = y;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400356
mtklein9a5c47f2016-07-22 11:05:04 -0700357 switch (mask.fFormat) {
358 case SkMask::kA8_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400359 fMaskPtr = mask.getAddr8(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400360 fBlitMaskA8(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700361 break;
362 case SkMask::kLCD16_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400363 fMaskPtr = mask.getAddrLCD16(x,y)-x;
Mike Klein0a76b412017-05-22 12:01:59 -0400364 fBlitMaskLCD16(x,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700365 break;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400366 default:
367 // TODO
368 break;
mtklein9a5c47f2016-07-22 11:05:04 -0700369 }
mtklein9a5c47f2016-07-22 11:05:04 -0700370 }
371}