blob: 3d60d756f615525e8b21c41b41ef709d06b73d5d [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,
Mike Kleinb35cb312017-05-19 12:01:01 -040028 bool is_opaque, bool is_constant, bool wants_dither);
29
Mike Klein3b840e92017-05-23 15:06:17 -040030 SkRasterPipelineBlitter(SkPixmap dst,
31 SkBlendMode blend,
Mike Reed6867eee2017-06-02 13:25:15 -040032 SkArenaAlloc* alloc)
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 Kleinb24704d2017-05-24 07:53:00 -040036 , fColorPipeline(alloc)
mtklein9a5c47f2016-07-22 11:05:04 -070037 {}
38
39 void blitH (int x, int y, int w) override;
40 void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override;
41 void blitMask (const SkMask&, const SkIRect& clip) override;
42
43 // TODO: The default implementations of the other blits look fine,
44 // but some of them like blitV could probably benefit from custom
45 // blits using something like a SkRasterPipeline::runFew() method.
46
47private:
Mike Klein14c8f822016-11-30 19:39:43 -050048 void append_load_d(SkRasterPipeline*) const;
49 void append_blend (SkRasterPipeline*) const;
50 void maybe_clamp (SkRasterPipeline*) const;
51 void append_store (SkRasterPipeline*) const;
mtklein8e4373f2016-07-22 14:20:27 -070052
Florin Malita4aed1382017-05-25 10:38:07 -040053 SkPixmap fDst;
54 SkBlendMode fBlend;
55 SkArenaAlloc* fAlloc;
Florin Malita4aed1382017-05-25 10:38:07 -040056 SkRasterPipeline fColorPipeline;
mtklein9a5c47f2016-07-22 11:05:04 -070057
Mike Klein8729e5b2017-02-16 06:51:48 -050058 // We may be able to specialize blitH() into a memset.
59 bool fCanMemsetInBlitH = false;
60 uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16.
Mike Kleinbd3fe472016-10-25 15:43:46 -040061
Mike Klein8729e5b2017-02-16 06:51:48 -050062 // Built lazily on first use.
Mike Klein761d27c2017-06-01 12:37:08 -040063 std::function<void(size_t, size_t, size_t)> fBlitH,
64 fBlitAntiH,
65 fBlitMaskA8,
66 fBlitMaskLCD16;
Mike Klein8729e5b2017-02-16 06:51:48 -050067
68 // These values are pointed to by the blit pipelines above,
69 // which allows us to adjust them from call to call.
Mike Kleindb711c92017-05-03 17:57:48 -040070 void* fDstPtr = nullptr;
71 const void* fMaskPtr = nullptr;
72 float fCurrentCoverage = 0.0f;
Mike Klein9b10f8f2017-06-01 13:11:16 -040073 float fDitherRate = 0.0f;
Mike Kleinbd3fe472016-10-25 15:43:46 -040074
mtklein9a5c47f2016-07-22 11:05:04 -070075 typedef SkBlitter INHERITED;
76};
77
78SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
79 const SkPaint& paint,
Mike Kleinfb191da2016-11-15 13:20:33 -050080 const SkMatrix& ctm,
Matt Sarett25834ff2017-02-15 15:54:35 -050081 SkArenaAlloc* alloc) {
Mike Klein3b840e92017-05-23 15:06:17 -040082 SkColorSpace* dstCS = dst.colorSpace();
83 auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), dstCS));
Florin Malita4aed1382017-05-25 10:38:07 -040084 auto shader = as_SB(paint.getShader());
Mike Reed98b7a6a2017-05-26 09:32:22 -040085 bool wants_dither = paint.isDither();
86
87#ifdef SK_SUPPORT_LEGACY_RASTERPIPELINE
88 wants_dither = shader && shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType;
89#endif
Mike Klein3b840e92017-05-23 15:06:17 -040090
91 SkRasterPipeline_<256> shaderPipeline;
92 if (!shader) {
93 // Having no shader makes things nice and easy... just use the paint color.
94 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
95 bool is_opaque = paintColor->a() == 1.0f,
Mike Reed98b7a6a2017-05-26 09:32:22 -040096 is_constant = true;
Mike Klein3b840e92017-05-23 15:06:17 -040097 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
Mike Reed6867eee2017-06-02 13:25:15 -040098 shaderPipeline,
Mike Klein3b840e92017-05-23 15:06:17 -040099 is_opaque, is_constant, wants_dither);
100 }
101
102 bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f;
103 bool is_constant = shader->isConstant();
Mike Klein3b840e92017-05-23 15:06:17 -0400104 if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
105 if (paintColor->a() != 1.0f) {
106 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
107 }
Mike Reed6867eee2017-06-02 13:25:15 -0400108 return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline,
Mike Klein3b840e92017-05-23 15:06:17 -0400109 is_opaque, is_constant, wants_dither);
110 }
111
Mike Reed6867eee2017-06-02 13:25:15 -0400112 return alloc->make<SkNullBlitter>();
Mike Reed02640952017-05-19 15:32:13 -0400113}
114
115SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
116 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -0400117 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -0400118 bool is_opaque,
119 bool wants_dither,
Mike Reed02640952017-05-19 15:32:13 -0400120 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400121 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
Mike Reed6867eee2017-06-02 13:25:15 -0400122 return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline,
Mike Klein3b840e92017-05-23 15:06:17 -0400123 is_opaque, is_constant, wants_dither);
Mike Reed02640952017-05-19 15:32:13 -0400124}
125
Mike Kleinb35cb312017-05-19 12:01:01 -0400126SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
127 const SkPaint& paint,
128 SkArenaAlloc* alloc,
129 const SkRasterPipeline& shaderPipeline,
130 bool is_opaque,
131 bool is_constant,
132 bool wants_dither) {
Mike Klein3b840e92017-05-23 15:06:17 -0400133 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst,
134 paint.getBlendMode(),
Mike Reed6867eee2017-06-02 13:25:15 -0400135 alloc);
Mike Reed02640952017-05-19 15:32:13 -0400136
Mike Kleinb35cb312017-05-19 12:01:01 -0400137 // Our job in this factory is to fill out the blitter's color pipeline.
138 // This is the common front of the full blit pipelines, each constructed lazily on first use.
139 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
140 auto colorPipeline = &blitter->fColorPipeline;
141
Mike Klein3b840e92017-05-23 15:06:17 -0400142 // Let's get the shader in first.
Mike Reed6867eee2017-06-02 13:25:15 -0400143 colorPipeline->extend(shaderPipeline);
Mike Reed02640952017-05-19 15:32:13 -0400144
Mike Kleinb35cb312017-05-19 12:01:01 -0400145 // If there's a color filter it comes next.
146 if (auto colorFilter = paint.getColorFilter()) {
147 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700148 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700149 }
150
Mike Kleinb35cb312017-05-19 12:01:01 -0400151 // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to.
152 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
153 // We need to decide if we're going to dither now to keep is_constant accurate.
154 if (wants_dither ||
155 (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) {
156 switch (dst.info().colorType()) {
Mike Klein9b10f8f2017-06-01 13:11:16 -0400157 default: blitter->fDitherRate = 0.0f; break;
158 case kRGB_565_SkColorType: blitter->fDitherRate = 1/63.0f; break;
Mike Kleinb35cb312017-05-19 12:01:01 -0400159 case kRGBA_8888_SkColorType:
Mike Klein9b10f8f2017-06-01 13:11:16 -0400160 case kBGRA_8888_SkColorType: blitter->fDitherRate = 1/255.0f; break;
Mike Kleinb35cb312017-05-19 12:01:01 -0400161 }
162 }
Mike Klein9b10f8f2017-06-01 13:11:16 -0400163 is_constant = is_constant && (blitter->fDitherRate == 0.0f);
Mike Kleinb35cb312017-05-19 12:01:01 -0400164
165 // We're logically done here. The code between here and return blitter is all optimization.
166
167 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500168 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400169 auto constantColor = alloc->make<SkPM4f>();
170 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
Mike Klein761d27c2017-06-01 12:37:08 -0400171 colorPipeline->run(0,0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400172 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400173 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700174
Mike Kleinb35cb312017-05-19 12:01:01 -0400175 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400176 }
mtklein8e4373f2016-07-22 14:20:27 -0700177
Mike Kleinb35cb312017-05-19 12:01:01 -0400178 // We can strength-reduce SrcOver into Src when opaque.
179 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
180 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700181 }
182
Mike Kleinb35cb312017-05-19 12:01:01 -0400183 // When we're drawing a constant color in Src mode, we can sometimes just memset.
184 // (The previous two optimizations help find more opportunities for this one.)
185 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
186 // Run our color pipeline all the way through to produce what we'd memset when we can.
187 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400188 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400189 p.extend(*colorPipeline);
190 blitter->fDstPtr = &blitter->fMemsetColor;
191 blitter->append_store(&p);
Mike Klein761d27c2017-06-01 12:37:08 -0400192 p.run(0,0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500193
Mike Kleinb35cb312017-05-19 12:01:01 -0400194 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500195 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400196
197 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700198}
199
Mike Kleine902f8d2016-10-26 15:32:26 -0400200void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500201 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700202 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500203 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500204 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500205 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500206 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
207 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700208 default: break;
209 }
Mike Kleine03339a2016-11-28 13:24:27 -0500210 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500211 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500212 }
213 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500214 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500215 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500216 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700217}
218
Mike Klein14c8f822016-11-30 19:39:43 -0500219void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400220 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500221 p->append(SkRasterPipeline::to_srgb);
222 }
Mike Klein9b10f8f2017-06-01 13:11:16 -0400223 if (fDitherRate > 0.0f) {
Mike Kleindb711c92017-05-03 17:57:48 -0400224 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
225 // 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 -0400226 p->append(SkRasterPipeline::dither, &fDitherRate);
Mike Kleindb711c92017-05-03 17:57:48 -0400227 }
228
Mike Kleine03339a2016-11-28 13:24:27 -0500229 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
230 p->append(SkRasterPipeline::swap_rb);
231 }
mtklein8e4373f2016-07-22 14:20:27 -0700232 switch (fDst.info().colorType()) {
Mike Kleine71b1672017-01-13 07:59:23 -0500233 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500234 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
235 case kBGRA_8888_SkColorType:
236 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
237 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700238 default: break;
239 }
240}
241
Mike Kleine902f8d2016-10-26 15:32:26 -0400242void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleinbb338332017-05-04 12:42:52 -0400243 SkBlendMode_AppendStages(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400244}
Mike Kleine9f74b82016-10-25 13:31:21 -0400245
Mike Klein130863e2016-10-27 11:29:36 -0400246void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleine03339a2016-11-28 13:24:27 -0500247 if (SkBlendMode_CanOverflow(fBlend)) {
248 p->append(SkRasterPipeline::clamp_a);
249 }
Mike Klein130863e2016-10-27 11:29:36 -0400250}
251
mtklein9a5c47f2016-07-22 11:05:04 -0700252void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500253 fDstPtr = fDst.writable_addr(0,y);
Mike Klein8729e5b2017-02-16 06:51:48 -0500254
255 if (fCanMemsetInBlitH) {
256 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000257 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
258 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
259 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
260 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500261 default: break;
262 }
263 }
264
Mike Klein0a76b412017-05-22 12:01:59 -0400265 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400266 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400267 p.extend(fColorPipeline);
Mike Klein50626262017-05-25 13:06:57 -0400268 if (fBlend == SkBlendMode::kSrcOver
269 && fDst.info().colorType() == kRGBA_8888_SkColorType
270 && !fDst.colorSpace()
Mike Klein9b10f8f2017-06-01 13:11:16 -0400271 && fDitherRate == 0.0f) {
Mike Klein50626262017-05-25 13:06:57 -0400272 p.append(SkRasterPipeline::srcover_rgba_8888, &fDstPtr);
273 } else {
274 if (fBlend != SkBlendMode::kSrc) {
275 this->append_load_d(&p);
276 this->append_blend(&p);
277 this->maybe_clamp(&p);
278 }
279 this->append_store(&p);
Mike Klein66866172016-11-03 12:22:01 -0400280 }
Mike Kleinb24704d2017-05-24 07:53:00 -0400281 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400282 }
Mike Klein761d27c2017-06-01 12:37:08 -0400283 fBlitH(x,y,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700284}
285
286void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400287 if (!fBlitAntiH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400288 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400289 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400290 if (fBlend == SkBlendMode::kSrcOver) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500291 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400292 this->append_load_d(&p);
293 this->append_blend(&p);
294 } else {
295 this->append_load_d(&p);
296 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500297 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400298 }
Mike Klein130863e2016-10-27 11:29:36 -0400299 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400300 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400301 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400302 }
mtklein9a5c47f2016-07-22 11:05:04 -0700303
Mike Kleinbd3fe472016-10-25 15:43:46 -0400304 fDstPtr = fDst.writable_addr(0,y);
mtklein9a5c47f2016-07-22 11:05:04 -0700305 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500306 switch (*aa) {
307 case 0x00: break;
308 case 0xff: this->blitH(x,y,run); break;
309 default:
Mike Kleinbabd93e2016-11-30 16:05:10 -0500310 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein761d27c2017-06-01 12:37:08 -0400311 fBlitAntiH(x,y,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500312 }
mtklein9a5c47f2016-07-22 11:05:04 -0700313 x += run;
314 runs += run;
315 aa += run;
316 }
317}
318
319void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
320 if (mask.fFormat == SkMask::kBW_Format) {
321 // TODO: native BW masks?
322 return INHERITED::blitMask(mask, clip);
323 }
324
Mike Klein0a76b412017-05-22 12:01:59 -0400325 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400326 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400327 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400328 if (fBlend == SkBlendMode::kSrcOver) {
329 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
330 this->append_load_d(&p);
331 this->append_blend(&p);
332 } else {
333 this->append_load_d(&p);
334 this->append_blend(&p);
335 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
336 }
Mike Klein130863e2016-10-27 11:29:36 -0400337 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400338 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400339 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400340 }
341
Mike Klein0a76b412017-05-22 12:01:59 -0400342 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400343 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400344 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400345 this->append_load_d(&p);
346 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400347 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400348 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400349 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400350 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400351 }
352
353 int x = clip.left();
354 for (int y = clip.top(); y < clip.bottom(); y++) {
355 fDstPtr = fDst.writable_addr(0,y);
356
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 Klein761d27c2017-06-01 12:37:08 -0400360 fBlitMaskA8(x,y,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 Klein761d27c2017-06-01 12:37:08 -0400364 fBlitMaskLCD16(x,y,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}