mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 1 | /* |
| 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 Derby | ac04fef | 2017-01-13 17:34:33 -0500 | [diff] [blame] | 8 | #include "SkArenaAlloc.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 9 | #include "SkBlitter.h" |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 10 | #include "SkBlendModePriv.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 11 | #include "SkColor.h" |
| 12 | #include "SkColorFilter.h" |
Mike Klein | baaf8ad | 2016-09-29 09:04:15 -0400 | [diff] [blame] | 13 | #include "SkOpts.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 14 | #include "SkPM4f.h" |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 15 | #include "SkPM4fPriv.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 16 | #include "SkRasterPipeline.h" |
| 17 | #include "SkShader.h" |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 18 | #include "SkUtils.h" |
Mike Klein | 581e698 | 2017-05-03 13:05:13 -0400 | [diff] [blame] | 19 | #include "../jumper/SkJumper.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 20 | |
| 21 | class SkRasterPipelineBlitter : public SkBlitter { |
| 22 | public: |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 23 | // 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); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 26 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 27 | // 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 Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 33 | SkRasterPipelineBlitter(SkPixmap dst, SkBlendMode blend, SkArenaAlloc* alloc) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 34 | : fDst(dst) |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 35 | , fBlend(blend) |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 36 | , fAlloc(alloc) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 37 | {} |
| 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 | |
| 47 | private: |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 48 | void append_load_d(SkRasterPipeline*) const; |
| 49 | void append_blend (SkRasterPipeline*) const; |
| 50 | void maybe_clamp (SkRasterPipeline*) const; |
| 51 | void append_store (SkRasterPipeline*) const; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 52 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 53 | SkPixmap fDst; |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 54 | SkBlendMode fBlend; |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 55 | SkArenaAlloc* fAlloc; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 56 | SkRasterPipeline fColorPipeline; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 57 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 58 | // 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 Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 61 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 62 | // Built lazily on first use. |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 63 | std::function<void(size_t, size_t)> fBlitH, |
| 64 | fBlitAntiH, |
| 65 | fBlitMaskA8, |
| 66 | fBlitMaskLCD16; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 67 | |
| 68 | // These values are pointed to by the blit pipelines above, |
| 69 | // which allows us to adjust them from call to call. |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 70 | void* fDstPtr = nullptr; |
| 71 | const void* fMaskPtr = nullptr; |
| 72 | float fCurrentCoverage = 0.0f; |
| 73 | int fCurrentY = 0; |
| 74 | SkJumper_DitherCtx fDitherCtx = { &fCurrentY, 0.0f }; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 75 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 76 | typedef SkBlitter INHERITED; |
| 77 | }; |
| 78 | |
| 79 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 80 | const SkPaint& paint, |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame] | 81 | const SkMatrix& ctm, |
Matt Sarett | 25834ff | 2017-02-15 15:54:35 -0500 | [diff] [blame] | 82 | SkArenaAlloc* alloc) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 83 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, ctm); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 87 | const SkPaint& paint, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 88 | const SkRasterPipeline& shaderPipeline, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 89 | bool is_opaque, |
| 90 | bool wants_dither, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 91 | SkArenaAlloc* alloc) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 92 | bool is_constant = false; // If this were the case, it'd be better to just set a paint color. |
| 93 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, |
| 94 | shaderPipeline, is_opaque, is_constant, wants_dither); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, |
| 98 | const SkPaint& paint, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 99 | SkArenaAlloc* alloc, |
| 100 | const SkMatrix& ctm) { |
| 101 | auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), |
| 102 | dst.colorSpace())); |
| 103 | if (auto shader = paint.getShader()) { |
| 104 | SkRasterPipeline shaderPipeline; |
| 105 | if (!shader->appendStages(&shaderPipeline, dst.colorSpace(), alloc, ctm, paint)) { |
| 106 | // When a shader fails to append stages, it means it has vetoed drawing entirely. |
| 107 | return alloc->make<SkNullBlitter>(); |
| 108 | } |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 109 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 110 | bool is_opaque = shader->isOpaque(); |
| 111 | if (paintColor->a() != 1.0f) { |
| 112 | shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]); |
| 113 | is_opaque = false; |
| 114 | } |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 115 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 116 | bool is_constant = shader->isConstant(); |
| 117 | bool wants_dither = shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType; |
| 118 | return Create(dst, paint, alloc, shaderPipeline, is_opaque, is_constant, wants_dither); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 119 | } |
| 120 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 121 | SkRasterPipeline shaderPipeline; |
| 122 | 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 Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 129 | SkBlitter* 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 Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 136 | auto blitter = alloc->make<SkRasterPipelineBlitter>(dst, paint.getBlendMode(), alloc); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 137 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 138 | // 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 Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 146 | } |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 147 | colorPipeline->extend(shaderPipeline); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 148 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 149 | // If there's a color filter it comes next. |
| 150 | if (auto colorFilter = paint.getColorFilter()) { |
| 151 | colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 152 | is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 155 | // 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 Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 172 | if (is_constant) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 173 | auto constantColor = alloc->make<SkPM4f>(); |
| 174 | colorPipeline->append(SkRasterPipeline::store_f32, &constantColor); |
| 175 | colorPipeline->run(0,1); |
| 176 | *colorPipeline = SkRasterPipeline(); |
| 177 | colorPipeline->append(SkRasterPipeline::constant_color, constantColor); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 178 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 179 | is_opaque = constantColor->a() == 1.0f; |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 180 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 181 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 182 | // We can strength-reduce SrcOver into Src when opaque. |
| 183 | if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) { |
| 184 | blitter->fBlend = SkBlendMode::kSrc; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 187 | // 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 Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 192 | SkRasterPipeline p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 193 | p.extend(*colorPipeline); |
| 194 | blitter->fDstPtr = &blitter->fMemsetColor; |
| 195 | blitter->append_store(&p); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 196 | p.run(0,1); |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 197 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 198 | blitter->fCanMemsetInBlitH = true; |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 199 | } |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 200 | |
| 201 | return blitter; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 204 | void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 205 | p->append(SkRasterPipeline::move_src_dst); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 206 | switch (fDst.info().colorType()) { |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 207 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break; |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 208 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 209 | case kBGRA_8888_SkColorType: |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 210 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break; |
| 211 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 212 | default: break; |
| 213 | } |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 214 | if (fDst.info().colorType() == kBGRA_8888_SkColorType) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 215 | p->append(SkRasterPipeline::swap_rb); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 216 | } |
| 217 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 218 | p->append_from_srgb(fDst.info().alphaType()); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 219 | } |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 220 | p->append(SkRasterPipeline::swap); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 223 | void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { |
Matt Sarett | f388093 | 2017-03-24 10:06:03 -0400 | [diff] [blame] | 224 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 225 | p->append(SkRasterPipeline::to_srgb); |
| 226 | } |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 227 | 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 Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 233 | if (fDst.info().colorType() == kBGRA_8888_SkColorType) { |
| 234 | p->append(SkRasterPipeline::swap_rb); |
| 235 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 236 | switch (fDst.info().colorType()) { |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 237 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 238 | 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; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 242 | default: break; |
| 243 | } |
| 244 | } |
| 245 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 246 | void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const { |
Mike Klein | bb33833 | 2017-05-04 12:42:52 -0400 | [diff] [blame] | 247 | SkBlendMode_AppendStages(fBlend, p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 248 | } |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 249 | |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 250 | void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const { |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 251 | if (SkBlendMode_CanOverflow(fBlend)) { |
| 252 | p->append(SkRasterPipeline::clamp_a); |
| 253 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 254 | } |
| 255 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 256 | void SkRasterPipelineBlitter::blitH(int x, int y, int w) { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 257 | fDstPtr = fDst.writable_addr(0,y); |
| 258 | fCurrentY = y; |
| 259 | |
| 260 | if (fCanMemsetInBlitH) { |
| 261 | switch (fDst.shiftPerPixel()) { |
Mike Klein | 8612548 | 2017-02-17 16:10:46 +0000 | [diff] [blame] | 262 | 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 Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 266 | default: break; |
| 267 | } |
| 268 | } |
| 269 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 270 | if (!fBlitH) { |
| 271 | SkRasterPipeline p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 272 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 273 | if (fBlend != SkBlendMode::kSrc) { |
| 274 | this->append_load_d(&p); |
| 275 | this->append_blend(&p); |
| 276 | this->maybe_clamp(&p); |
| 277 | } |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 278 | this->append_store(&p); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 279 | fBlitH = p.compile(fAlloc); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 280 | } |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 281 | fBlitH(x,w); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) { |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 285 | if (!fBlitAntiH) { |
| 286 | SkRasterPipeline p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 287 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 288 | if (fBlend == SkBlendMode::kSrcOver) { |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 289 | p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 290 | this->append_load_d(&p); |
| 291 | this->append_blend(&p); |
| 292 | } else { |
| 293 | this->append_load_d(&p); |
| 294 | this->append_blend(&p); |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 295 | p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 296 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 297 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 298 | this->append_store(&p); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 299 | fBlitAntiH = p.compile(fAlloc); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 300 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 301 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 302 | fDstPtr = fDst.writable_addr(0,y); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 303 | fCurrentY = y; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 304 | for (int16_t run = *runs; run > 0; run = *runs) { |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 305 | switch (*aa) { |
| 306 | case 0x00: break; |
| 307 | case 0xff: this->blitH(x,y,run); break; |
| 308 | default: |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 309 | fCurrentCoverage = *aa * (1/255.0f); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 310 | fBlitAntiH(x,run); |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 311 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 312 | x += run; |
| 313 | runs += run; |
| 314 | aa += run; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void 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 Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 324 | if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) { |
| 325 | SkRasterPipeline p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 326 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 327 | 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 Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 336 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 337 | this->append_store(&p); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 338 | fBlitMaskA8 = p.compile(fAlloc); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 341 | if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) { |
| 342 | SkRasterPipeline p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 343 | p.extend(fColorPipeline); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 344 | this->append_load_d(&p); |
| 345 | this->append_blend(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 346 | p.append(SkRasterPipeline::lerp_565, &fMaskPtr); |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 347 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 348 | this->append_store(&p); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 349 | fBlitMaskLCD16 = p.compile(fAlloc); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | int x = clip.left(); |
| 353 | for (int y = clip.top(); y < clip.bottom(); y++) { |
| 354 | fDstPtr = fDst.writable_addr(0,y); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 355 | fCurrentY = y; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 356 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 357 | switch (mask.fFormat) { |
| 358 | case SkMask::kA8_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 359 | fMaskPtr = mask.getAddr8(x,y)-x; |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 360 | fBlitMaskA8(x,clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 361 | break; |
| 362 | case SkMask::kLCD16_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 363 | fMaskPtr = mask.getAddrLCD16(x,y)-x; |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame^] | 364 | fBlitMaskLCD16(x,clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 365 | break; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 366 | default: |
| 367 | // TODO |
| 368 | break; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 369 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 370 | } |
| 371 | } |