blob: 9cb955791cfe30eb02d520a4ca2dd9b6641e806e [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,
Florin Malita47e55a52017-06-06 12:26:54 -040028 SkShaderBase::Context*,
Mike Reedeb7dc792017-06-12 12:48:45 -040029 bool is_opaque, bool is_constant);
Mike Kleinb35cb312017-05-19 12:01:01 -040030
Mike Klein3b840e92017-05-23 15:06:17 -040031 SkRasterPipelineBlitter(SkPixmap dst,
32 SkBlendMode blend,
Florin Malita47e55a52017-06-06 12:26:54 -040033 SkArenaAlloc* alloc,
34 SkShaderBase::Context* burstCtx)
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)
Florin Malita47e55a52017-06-06 12:26:54 -040038 , fBurstCtx(burstCtx)
Mike Kleinb24704d2017-05-24 07:53:00 -040039 , fColorPipeline(alloc)
mtklein9a5c47f2016-07-22 11:05:04 -070040 {}
41
Mike Klein34d10d72017-06-05 07:10:01 -040042 void blitH (int x, int y, int w) override;
43 void blitAntiH (int x, int y, const SkAlpha[], const int16_t[]) override;
44 void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override;
45 void blitMask (const SkMask&, const SkIRect& clip) override;
mtklein9a5c47f2016-07-22 11:05:04 -070046
47 // TODO: The default implementations of the other blits look fine,
48 // but some of them like blitV could probably benefit from custom
49 // blits using something like a SkRasterPipeline::runFew() method.
50
51private:
Mike Klein14c8f822016-11-30 19:39:43 -050052 void append_load_d(SkRasterPipeline*) const;
53 void append_blend (SkRasterPipeline*) const;
54 void maybe_clamp (SkRasterPipeline*) const;
55 void append_store (SkRasterPipeline*) const;
mtklein8e4373f2016-07-22 14:20:27 -070056
Florin Malita47e55a52017-06-06 12:26:54 -040057 // If we have an burst context, use it to fill our shader buffer.
58 void maybe_shade(int x, int y, int w);
59
Florin Malita4aed1382017-05-25 10:38:07 -040060 SkPixmap fDst;
61 SkBlendMode fBlend;
62 SkArenaAlloc* fAlloc;
Florin Malita47e55a52017-06-06 12:26:54 -040063 SkShaderBase::Context* fBurstCtx;
Florin Malita4aed1382017-05-25 10:38:07 -040064 SkRasterPipeline fColorPipeline;
mtklein9a5c47f2016-07-22 11:05:04 -070065
Mike Klein8729e5b2017-02-16 06:51:48 -050066 // We may be able to specialize blitH() into a memset.
67 bool fCanMemsetInBlitH = false;
68 uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16.
Mike Kleinbd3fe472016-10-25 15:43:46 -040069
Mike Klein8729e5b2017-02-16 06:51:48 -050070 // Built lazily on first use.
Mike Klein761d27c2017-06-01 12:37:08 -040071 std::function<void(size_t, size_t, size_t)> fBlitH,
72 fBlitAntiH,
73 fBlitMaskA8,
74 fBlitMaskLCD16;
Mike Klein8729e5b2017-02-16 06:51:48 -050075
76 // These values are pointed to by the blit pipelines above,
77 // which allows us to adjust them from call to call.
Florin Malita47e55a52017-06-06 12:26:54 -040078 void* fShaderOutput = nullptr;
Mike Kleindb711c92017-05-03 17:57:48 -040079 void* fDstPtr = nullptr;
80 const void* fMaskPtr = nullptr;
81 float fCurrentCoverage = 0.0f;
Mike Klein9b10f8f2017-06-01 13:11:16 -040082 float fDitherRate = 0.0f;
Mike Kleinbd3fe472016-10-25 15:43:46 -040083
Florin Malita47e55a52017-06-06 12:26:54 -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 Klein3b840e92017-05-23 15:06:17 -040096
97 SkRasterPipeline_<256> shaderPipeline;
98 if (!shader) {
99 // Having no shader makes things nice and easy... just use the paint color.
100 shaderPipeline.append(SkRasterPipeline::constant_color, paintColor);
101 bool is_opaque = paintColor->a() == 1.0f,
Mike Reed98b7a6a2017-05-26 09:32:22 -0400102 is_constant = true;
Mike Klein3b840e92017-05-23 15:06:17 -0400103 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
Florin Malita47e55a52017-06-06 12:26:54 -0400104 shaderPipeline, nullptr,
Mike Reedeb7dc792017-06-12 12:48:45 -0400105 is_opaque, is_constant);
Mike Klein3b840e92017-05-23 15:06:17 -0400106 }
107
108 bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f;
109 bool is_constant = shader->isConstant();
Florin Malita47e55a52017-06-06 12:26:54 -0400110
111 // Check whether the shader prefers to run in burst mode.
112 if (auto* burstCtx = shader->makeBurstPipelineContext(
113 SkShaderBase::ContextRec(paint, ctm, nullptr, SkShaderBase::ContextRec::kPM4f_DstType,
114 dstCS), alloc)) {
115 return SkRasterPipelineBlitter::Create(dst, paint, alloc,
116 shaderPipeline, burstCtx,
Mike Reedeb7dc792017-06-12 12:48:45 -0400117 is_opaque, is_constant);
Florin Malita47e55a52017-06-06 12:26:54 -0400118 }
119
Mike Klein3b840e92017-05-23 15:06:17 -0400120 if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) {
121 if (paintColor->a() != 1.0f) {
122 shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]);
123 }
Florin Malita47e55a52017-06-06 12:26:54 -0400124 return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline, nullptr,
Mike Reedeb7dc792017-06-12 12:48:45 -0400125 is_opaque, is_constant);
Mike Klein3b840e92017-05-23 15:06:17 -0400126 }
127
Florin Malita47e55a52017-06-06 12:26:54 -0400128 // The shader has opted out of drawing anything.
Mike Reed6867eee2017-06-02 13:25:15 -0400129 return alloc->make<SkNullBlitter>();
Mike Reed02640952017-05-19 15:32:13 -0400130}
131
132SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst,
133 const SkPaint& paint,
Mike Reed02640952017-05-19 15:32:13 -0400134 const SkRasterPipeline& shaderPipeline,
Mike Kleinb35cb312017-05-19 12:01:01 -0400135 bool is_opaque,
Mike Reed02640952017-05-19 15:32:13 -0400136 SkArenaAlloc* alloc) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400137 bool is_constant = false; // If this were the case, it'd be better to just set a paint color.
Florin Malita47e55a52017-06-06 12:26:54 -0400138 return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline, nullptr,
Mike Reedeb7dc792017-06-12 12:48:45 -0400139 is_opaque, is_constant);
Mike Reed02640952017-05-19 15:32:13 -0400140}
141
Mike Kleinb35cb312017-05-19 12:01:01 -0400142SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst,
143 const SkPaint& paint,
144 SkArenaAlloc* alloc,
145 const SkRasterPipeline& shaderPipeline,
Florin Malita47e55a52017-06-06 12:26:54 -0400146 SkShaderBase::Context* burstCtx,
Mike Kleinb35cb312017-05-19 12:01:01 -0400147 bool is_opaque,
Mike Reedeb7dc792017-06-12 12:48:45 -0400148 bool is_constant) {
Mike Klein3b840e92017-05-23 15:06:17 -0400149 auto blitter = alloc->make<SkRasterPipelineBlitter>(dst,
150 paint.getBlendMode(),
Florin Malita47e55a52017-06-06 12:26:54 -0400151 alloc,
152 burstCtx);
Mike Reed02640952017-05-19 15:32:13 -0400153
Mike Kleinb35cb312017-05-19 12:01:01 -0400154 // Our job in this factory is to fill out the blitter's color pipeline.
155 // This is the common front of the full blit pipelines, each constructed lazily on first use.
156 // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering.
157 auto colorPipeline = &blitter->fColorPipeline;
158
Mike Klein3b840e92017-05-23 15:06:17 -0400159 // Let's get the shader in first.
Florin Malita47e55a52017-06-06 12:26:54 -0400160 if (burstCtx) {
161 colorPipeline->append(SkRasterPipeline::load_f32, &blitter->fShaderOutput);
162 } else {
163 colorPipeline->extend(shaderPipeline);
164 }
Mike Reed02640952017-05-19 15:32:13 -0400165
Mike Kleinb35cb312017-05-19 12:01:01 -0400166 // If there's a color filter it comes next.
167 if (auto colorFilter = paint.getColorFilter()) {
168 colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque);
mtkleina4a44882016-11-04 13:20:07 -0700169 is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag);
mtklein9a5c47f2016-07-22 11:05:04 -0700170 }
171
Mike Kleinb35cb312017-05-19 12:01:01 -0400172 // Not all formats make sense to dither (think, F16). We set their dither rate to zero.
173 // We need to decide if we're going to dither now to keep is_constant accurate.
Mike Reedeb7dc792017-06-12 12:48:45 -0400174 if (paint.isDither()) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400175 switch (dst.info().colorType()) {
Mike Klein9b10f8f2017-06-01 13:11:16 -0400176 default: blitter->fDitherRate = 0.0f; break;
Mike Klein95d19f32017-06-15 07:40:24 -0700177 case kARGB_4444_SkColorType: blitter->fDitherRate = 1/15.0f; break;
Mike Klein9b10f8f2017-06-01 13:11:16 -0400178 case kRGB_565_SkColorType: blitter->fDitherRate = 1/63.0f; break;
Mike Klein95d19f32017-06-15 07:40:24 -0700179 case kGray_8_SkColorType:
Mike Kleinb35cb312017-05-19 12:01:01 -0400180 case kRGBA_8888_SkColorType:
Mike Klein9b10f8f2017-06-01 13:11:16 -0400181 case kBGRA_8888_SkColorType: blitter->fDitherRate = 1/255.0f; break;
Mike Kleinb35cb312017-05-19 12:01:01 -0400182 }
Mike Reedeb7dc792017-06-12 12:48:45 -0400183 // TODO: for constant colors, we could try to measure the effect of dithering, and if
184 // it has no value (i.e. all variations result in the same 32bit color, then we
185 // could disable it (for speed, by not adding the stage).
Mike Kleinb35cb312017-05-19 12:01:01 -0400186 }
Mike Klein9b10f8f2017-06-01 13:11:16 -0400187 is_constant = is_constant && (blitter->fDitherRate == 0.0f);
Mike Kleinb35cb312017-05-19 12:01:01 -0400188
189 // We're logically done here. The code between here and return blitter is all optimization.
190
191 // A pipeline that's still constant here can collapse back into a constant color.
Mike Klein14c8f822016-11-30 19:39:43 -0500192 if (is_constant) {
Mike Kleinb35cb312017-05-19 12:01:01 -0400193 auto constantColor = alloc->make<SkPM4f>();
194 colorPipeline->append(SkRasterPipeline::store_f32, &constantColor);
Mike Klein761d27c2017-06-01 12:37:08 -0400195 colorPipeline->run(0,0,1);
Mike Kleinb24704d2017-05-24 07:53:00 -0400196 colorPipeline->reset();
Mike Kleinb35cb312017-05-19 12:01:01 -0400197 colorPipeline->append(SkRasterPipeline::constant_color, constantColor);
mtkleina4a44882016-11-04 13:20:07 -0700198
Mike Kleinb35cb312017-05-19 12:01:01 -0400199 is_opaque = constantColor->a() == 1.0f;
Mike Klein66866172016-11-03 12:22:01 -0400200 }
mtklein8e4373f2016-07-22 14:20:27 -0700201
Mike Kleinb35cb312017-05-19 12:01:01 -0400202 // We can strength-reduce SrcOver into Src when opaque.
203 if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) {
204 blitter->fBlend = SkBlendMode::kSrc;
mtklein8e4373f2016-07-22 14:20:27 -0700205 }
206
Mike Kleinb35cb312017-05-19 12:01:01 -0400207 // When we're drawing a constant color in Src mode, we can sometimes just memset.
208 // (The previous two optimizations help find more opportunities for this one.)
209 if (is_constant && blitter->fBlend == SkBlendMode::kSrc) {
210 // Run our color pipeline all the way through to produce what we'd memset when we can.
211 // Not all blits can memset, so we need to keep colorPipeline too.
Mike Kleinb24704d2017-05-24 07:53:00 -0400212 SkRasterPipeline_<256> p;
Mike Kleinb35cb312017-05-19 12:01:01 -0400213 p.extend(*colorPipeline);
214 blitter->fDstPtr = &blitter->fMemsetColor;
215 blitter->append_store(&p);
Mike Klein761d27c2017-06-01 12:37:08 -0400216 p.run(0,0,1);
Mike Klein14c8f822016-11-30 19:39:43 -0500217
Mike Kleinb35cb312017-05-19 12:01:01 -0400218 blitter->fCanMemsetInBlitH = true;
Mike Klein14c8f822016-11-30 19:39:43 -0500219 }
Mike Kleinb35cb312017-05-19 12:01:01 -0400220
221 return blitter;
mtklein9a5c47f2016-07-22 11:05:04 -0700222}
223
Mike Kleine902f8d2016-10-26 15:32:26 -0400224void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500225 p->append(SkRasterPipeline::move_src_dst);
mtklein8e4373f2016-07-22 14:20:27 -0700226 switch (fDst.info().colorType()) {
Mike Klein95d19f32017-06-15 07:40:24 -0700227 case kGray_8_SkColorType: p->append(SkRasterPipeline::load_g8, &fDstPtr); break;
Mike Kleine71b1672017-01-13 07:59:23 -0500228 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break;
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500229 case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break;
Mike Klein95d19f32017-06-15 07:40:24 -0700230 case kARGB_4444_SkColorType: p->append(SkRasterPipeline::load_4444, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500231 case kBGRA_8888_SkColorType:
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500232 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break;
233 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700234 default: break;
235 }
Mike Kleine03339a2016-11-28 13:24:27 -0500236 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500237 p->append(SkRasterPipeline::swap_rb);
Mike Kleine03339a2016-11-28 13:24:27 -0500238 }
239 if (fDst.info().gammaCloseToSRGB()) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500240 p->append_from_srgb(fDst.info().alphaType());
Mike Kleine03339a2016-11-28 13:24:27 -0500241 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -0500242 p->append(SkRasterPipeline::swap);
mtklein8e4373f2016-07-22 14:20:27 -0700243}
244
Mike Klein14c8f822016-11-30 19:39:43 -0500245void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const {
Matt Sarettf3880932017-03-24 10:06:03 -0400246 if (fDst.info().gammaCloseToSRGB()) {
Mike Kleine03339a2016-11-28 13:24:27 -0500247 p->append(SkRasterPipeline::to_srgb);
248 }
Mike Klein9b10f8f2017-06-01 13:11:16 -0400249 if (fDitherRate > 0.0f) {
Mike Kleindb711c92017-05-03 17:57:48 -0400250 // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible
251 // 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 -0400252 p->append(SkRasterPipeline::dither, &fDitherRate);
Mike Kleindb711c92017-05-03 17:57:48 -0400253 }
254
Mike Kleine03339a2016-11-28 13:24:27 -0500255 if (fDst.info().colorType() == kBGRA_8888_SkColorType) {
256 p->append(SkRasterPipeline::swap_rb);
257 }
mtklein8e4373f2016-07-22 14:20:27 -0700258 switch (fDst.info().colorType()) {
Mike Klein95d19f32017-06-15 07:40:24 -0700259 case kGray_8_SkColorType: p->append(SkRasterPipeline::luminance_to_alpha); // fallthru
Mike Kleine71b1672017-01-13 07:59:23 -0500260 case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500261 case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break;
Mike Klein95d19f32017-06-15 07:40:24 -0700262 case kARGB_4444_SkColorType: p->append(SkRasterPipeline::store_4444, &fDstPtr); break;
Mike Kleine03339a2016-11-28 13:24:27 -0500263 case kBGRA_8888_SkColorType:
264 case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break;
265 case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break;
mtklein8e4373f2016-07-22 14:20:27 -0700266 default: break;
267 }
268}
269
Mike Kleine902f8d2016-10-26 15:32:26 -0400270void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const {
Mike Kleincb3ceb72017-06-09 15:58:37 -0400271 SkBlendMode_AppendStagesNoClamp(fBlend, p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400272}
Mike Kleine9f74b82016-10-25 13:31:21 -0400273
Mike Klein130863e2016-10-27 11:29:36 -0400274void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const {
Mike Kleincb3ceb72017-06-09 15:58:37 -0400275 SkBlendMode_AppendClampIfNeeded(fBlend, p);
Mike Klein130863e2016-10-27 11:29:36 -0400276}
277
Florin Malita47e55a52017-06-06 12:26:54 -0400278void SkRasterPipelineBlitter::maybe_shade(int x, int y, int w) {
279 if (fBurstCtx) {
280 if (w > SkToInt(fShaderBuffer.size())) {
281 fShaderBuffer.resize(w);
282 }
283 fBurstCtx->shadeSpan4f(x,y, fShaderBuffer.data(), w);
284 // We'll be reading from fShaderOutput + x.
285 fShaderOutput = fShaderBuffer.data() - x;
286 }
287}
288
mtklein9a5c47f2016-07-22 11:05:04 -0700289void SkRasterPipelineBlitter::blitH(int x, int y, int w) {
Mike Klein8729e5b2017-02-16 06:51:48 -0500290 fDstPtr = fDst.writable_addr(0,y);
Mike Klein8729e5b2017-02-16 06:51:48 -0500291
292 if (fCanMemsetInBlitH) {
293 switch (fDst.shiftPerPixel()) {
Mike Klein86125482017-02-17 16:10:46 +0000294 case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return;
295 case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return;
296 case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return;
297 case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return;
Mike Klein8729e5b2017-02-16 06:51:48 -0500298 default: break;
299 }
300 }
301
Mike Klein0a76b412017-05-22 12:01:59 -0400302 if (!fBlitH) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400303 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400304 p.extend(fColorPipeline);
Mike Klein50626262017-05-25 13:06:57 -0400305 if (fBlend == SkBlendMode::kSrcOver
306 && fDst.info().colorType() == kRGBA_8888_SkColorType
307 && !fDst.colorSpace()
Mike Klein9b10f8f2017-06-01 13:11:16 -0400308 && fDitherRate == 0.0f) {
Mike Klein50626262017-05-25 13:06:57 -0400309 p.append(SkRasterPipeline::srcover_rgba_8888, &fDstPtr);
310 } else {
311 if (fBlend != SkBlendMode::kSrc) {
312 this->append_load_d(&p);
313 this->append_blend(&p);
314 this->maybe_clamp(&p);
315 }
316 this->append_store(&p);
Mike Klein66866172016-11-03 12:22:01 -0400317 }
Mike Kleinb24704d2017-05-24 07:53:00 -0400318 fBlitH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400319 }
Florin Malita47e55a52017-06-06 12:26:54 -0400320 this->maybe_shade(x,y,w);
Mike Klein761d27c2017-06-01 12:37:08 -0400321 fBlitH(x,y,w);
mtklein9a5c47f2016-07-22 11:05:04 -0700322}
323
324void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) {
Mike Klein0a76b412017-05-22 12:01:59 -0400325 if (!fBlitAntiH) {
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) {
Mike Kleinbabd93e2016-11-30 16:05:10 -0500329 p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400330 this->append_load_d(&p);
331 this->append_blend(&p);
332 } else {
333 this->append_load_d(&p);
334 this->append_blend(&p);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500335 p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage);
Mike Klein66866172016-11-03 12:22:01 -0400336 }
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 fBlitAntiH = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400340 }
mtklein9a5c47f2016-07-22 11:05:04 -0700341
Mike Kleinbd3fe472016-10-25 15:43:46 -0400342 fDstPtr = fDst.writable_addr(0,y);
mtklein9a5c47f2016-07-22 11:05:04 -0700343 for (int16_t run = *runs; run > 0; run = *runs) {
Mike Kleinaeb79592016-11-07 09:29:07 -0500344 switch (*aa) {
345 case 0x00: break;
346 case 0xff: this->blitH(x,y,run); break;
347 default:
Florin Malita47e55a52017-06-06 12:26:54 -0400348 this->maybe_shade(x,y,run);
Mike Kleinbabd93e2016-11-30 16:05:10 -0500349 fCurrentCoverage = *aa * (1/255.0f);
Mike Klein761d27c2017-06-01 12:37:08 -0400350 fBlitAntiH(x,y,run);
Mike Kleinaeb79592016-11-07 09:29:07 -0500351 }
mtklein9a5c47f2016-07-22 11:05:04 -0700352 x += run;
353 runs += run;
354 aa += run;
355 }
356}
357
Mike Klein34d10d72017-06-05 07:10:01 -0400358void SkRasterPipelineBlitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
359 SkIRect clip = {x,y, x+2,y+1};
360 uint8_t coverage[] = { (uint8_t)a0, (uint8_t)a1 };
361
362 SkMask mask;
363 mask.fImage = coverage;
364 mask.fBounds = clip;
365 mask.fRowBytes = 2;
366 mask.fFormat = SkMask::kA8_Format;
367
368 this->blitMask(mask, clip);
369}
370
mtklein9a5c47f2016-07-22 11:05:04 -0700371void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) {
372 if (mask.fFormat == SkMask::kBW_Format) {
373 // TODO: native BW masks?
374 return INHERITED::blitMask(mask, clip);
375 }
376
Mike Klein0a76b412017-05-22 12:01:59 -0400377 if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400378 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400379 p.extend(fColorPipeline);
Mike Klein66866172016-11-03 12:22:01 -0400380 if (fBlend == SkBlendMode::kSrcOver) {
381 p.append(SkRasterPipeline::scale_u8, &fMaskPtr);
382 this->append_load_d(&p);
383 this->append_blend(&p);
384 } else {
385 this->append_load_d(&p);
386 this->append_blend(&p);
387 p.append(SkRasterPipeline::lerp_u8, &fMaskPtr);
388 }
Mike Klein130863e2016-10-27 11:29:36 -0400389 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400390 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400391 fBlitMaskA8 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400392 }
393
Mike Klein0a76b412017-05-22 12:01:59 -0400394 if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) {
Mike Kleinb24704d2017-05-24 07:53:00 -0400395 SkRasterPipeline p(fAlloc);
Mike Kleinb35cb312017-05-19 12:01:01 -0400396 p.extend(fColorPipeline);
Mike Kleine902f8d2016-10-26 15:32:26 -0400397 this->append_load_d(&p);
398 this->append_blend(&p);
Mike Kleinbd3fe472016-10-25 15:43:46 -0400399 p.append(SkRasterPipeline::lerp_565, &fMaskPtr);
Mike Klein130863e2016-10-27 11:29:36 -0400400 this->maybe_clamp(&p);
Mike Kleine902f8d2016-10-26 15:32:26 -0400401 this->append_store(&p);
Mike Kleinb24704d2017-05-24 07:53:00 -0400402 fBlitMaskLCD16 = p.compile();
Mike Kleinbd3fe472016-10-25 15:43:46 -0400403 }
404
405 int x = clip.left();
406 for (int y = clip.top(); y < clip.bottom(); y++) {
407 fDstPtr = fDst.writable_addr(0,y);
408
Florin Malita47e55a52017-06-06 12:26:54 -0400409 this->maybe_shade(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700410 switch (mask.fFormat) {
411 case SkMask::kA8_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400412 fMaskPtr = mask.getAddr8(x,y)-x;
Mike Klein761d27c2017-06-01 12:37:08 -0400413 fBlitMaskA8(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700414 break;
415 case SkMask::kLCD16_Format:
Mike Kleinbd3fe472016-10-25 15:43:46 -0400416 fMaskPtr = mask.getAddrLCD16(x,y)-x;
Mike Klein761d27c2017-06-01 12:37:08 -0400417 fBlitMaskLCD16(x,y,clip.width());
mtklein9a5c47f2016-07-22 11:05:04 -0700418 break;
Mike Kleinbd3fe472016-10-25 15:43:46 -0400419 default:
420 // TODO
421 break;
mtklein9a5c47f2016-07-22 11:05:04 -0700422 }
mtklein9a5c47f2016-07-22 11:05:04 -0700423 }
424}