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 | |
| 33 | SkRasterPipelineBlitter(SkPixmap dst, SkBlendMode blend) |
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) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 36 | {} |
| 37 | |
| 38 | void blitH (int x, int y, int w) override; |
| 39 | void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override; |
| 40 | void blitMask (const SkMask&, const SkIRect& clip) override; |
| 41 | |
| 42 | // TODO: The default implementations of the other blits look fine, |
| 43 | // but some of them like blitV could probably benefit from custom |
| 44 | // blits using something like a SkRasterPipeline::runFew() method. |
| 45 | |
| 46 | private: |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 47 | void append_load_d(SkRasterPipeline*) const; |
| 48 | void append_blend (SkRasterPipeline*) const; |
| 49 | void maybe_clamp (SkRasterPipeline*) const; |
| 50 | void append_store (SkRasterPipeline*) const; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 51 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 52 | SkPixmap fDst; |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 53 | SkBlendMode fBlend; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 54 | SkRasterPipeline fColorPipeline; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 55 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 56 | // We may be able to specialize blitH() into a memset. |
| 57 | bool fCanMemsetInBlitH = false; |
| 58 | uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16. |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 59 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 60 | // Built lazily on first use. |
| 61 | SkRasterPipeline fBlitH, |
| 62 | fBlitAntiH, |
| 63 | fBlitMaskA8, |
| 64 | fBlitMaskLCD16; |
| 65 | |
| 66 | // These values are pointed to by the blit pipelines above, |
| 67 | // which allows us to adjust them from call to call. |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 68 | void* fDstPtr = nullptr; |
| 69 | const void* fMaskPtr = nullptr; |
| 70 | float fCurrentCoverage = 0.0f; |
| 71 | int fCurrentY = 0; |
| 72 | SkJumper_DitherCtx fDitherCtx = { &fCurrentY, 0.0f }; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 73 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 74 | typedef SkBlitter INHERITED; |
| 75 | }; |
| 76 | |
| 77 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 78 | const SkPaint& paint, |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame] | 79 | const SkMatrix& ctm, |
Matt Sarett | 25834ff | 2017-02-15 15:54:35 -0500 | [diff] [blame] | 80 | SkArenaAlloc* alloc) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 81 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, ctm); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 85 | const SkPaint& paint, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 86 | const SkRasterPipeline& shaderPipeline, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 87 | bool is_opaque, |
| 88 | bool wants_dither, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 89 | SkArenaAlloc* alloc) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 90 | bool is_constant = false; // If this were the case, it'd be better to just set a paint color. |
| 91 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, |
| 92 | shaderPipeline, is_opaque, is_constant, wants_dither); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, |
| 96 | const SkPaint& paint, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 97 | SkArenaAlloc* alloc, |
| 98 | const SkMatrix& ctm) { |
| 99 | auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), |
| 100 | dst.colorSpace())); |
| 101 | if (auto shader = paint.getShader()) { |
| 102 | SkRasterPipeline shaderPipeline; |
| 103 | if (!shader->appendStages(&shaderPipeline, dst.colorSpace(), alloc, ctm, paint)) { |
| 104 | // When a shader fails to append stages, it means it has vetoed drawing entirely. |
| 105 | return alloc->make<SkNullBlitter>(); |
| 106 | } |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 107 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 108 | bool is_opaque = shader->isOpaque(); |
| 109 | if (paintColor->a() != 1.0f) { |
| 110 | shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]); |
| 111 | is_opaque = false; |
| 112 | } |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 113 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 114 | bool is_constant = shader->isConstant(); |
| 115 | bool wants_dither = shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType; |
| 116 | return Create(dst, paint, alloc, shaderPipeline, is_opaque, is_constant, wants_dither); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 119 | SkRasterPipeline shaderPipeline; |
| 120 | shaderPipeline.append(SkRasterPipeline::constant_color, paintColor); |
| 121 | bool is_opaque = paintColor->a() == 1.0f, |
| 122 | is_constant = true, |
| 123 | wants_dither = false; |
| 124 | return Create(dst, paint, alloc, shaderPipeline, is_opaque, is_constant, wants_dither); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 127 | SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, |
| 128 | const SkPaint& paint, |
| 129 | SkArenaAlloc* alloc, |
| 130 | const SkRasterPipeline& shaderPipeline, |
| 131 | bool is_opaque, |
| 132 | bool is_constant, |
| 133 | bool wants_dither) { |
| 134 | auto blitter = alloc->make<SkRasterPipelineBlitter>(dst, paint.getBlendMode()); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 135 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 136 | // Our job in this factory is to fill out the blitter's color pipeline. |
| 137 | // This is the common front of the full blit pipelines, each constructed lazily on first use. |
| 138 | // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering. |
| 139 | auto colorPipeline = &blitter->fColorPipeline; |
| 140 | |
| 141 | // Let's get the shader in first. If the shader's not constant, it'll need seeding with x,y. |
| 142 | if (!is_constant) { |
| 143 | colorPipeline->append(SkRasterPipeline::seed_shader, &blitter->fCurrentY); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 144 | } |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 145 | colorPipeline->extend(shaderPipeline); |
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 | // If there's a color filter it comes next. |
| 148 | if (auto colorFilter = paint.getColorFilter()) { |
| 149 | colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 150 | is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 153 | // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to. |
| 154 | // Not all formats make sense to dither (think, F16). We set their dither rate to zero. |
| 155 | // We need to decide if we're going to dither now to keep is_constant accurate. |
| 156 | if (wants_dither || |
| 157 | (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) { |
| 158 | switch (dst.info().colorType()) { |
| 159 | default: blitter->fDitherCtx.rate = 0.0f; break; |
| 160 | case kRGB_565_SkColorType: blitter->fDitherCtx.rate = 1/63.0f; break; |
| 161 | case kRGBA_8888_SkColorType: |
| 162 | case kBGRA_8888_SkColorType: blitter->fDitherCtx.rate = 1/255.0f; break; |
| 163 | } |
| 164 | } |
| 165 | is_constant = is_constant && (blitter->fDitherCtx.rate == 0.0f); |
| 166 | |
| 167 | // We're logically done here. The code between here and return blitter is all optimization. |
| 168 | |
| 169 | // 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] | 170 | if (is_constant) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 171 | auto constantColor = alloc->make<SkPM4f>(); |
| 172 | colorPipeline->append(SkRasterPipeline::store_f32, &constantColor); |
| 173 | colorPipeline->run(0,1); |
| 174 | *colorPipeline = SkRasterPipeline(); |
| 175 | colorPipeline->append(SkRasterPipeline::constant_color, constantColor); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 176 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 177 | is_opaque = constantColor->a() == 1.0f; |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 178 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 179 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 180 | // We can strength-reduce SrcOver into Src when opaque. |
| 181 | if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) { |
| 182 | blitter->fBlend = SkBlendMode::kSrc; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 185 | // When we're drawing a constant color in Src mode, we can sometimes just memset. |
| 186 | // (The previous two optimizations help find more opportunities for this one.) |
| 187 | if (is_constant && blitter->fBlend == SkBlendMode::kSrc) { |
| 188 | // Run our color pipeline all the way through to produce what we'd memset when we can. |
| 189 | // Not all blits can memset, so we need to keep colorPipeline too. |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 190 | SkRasterPipeline p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 191 | p.extend(*colorPipeline); |
| 192 | blitter->fDstPtr = &blitter->fMemsetColor; |
| 193 | blitter->append_store(&p); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 194 | p.run(0,1); |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 195 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 196 | blitter->fCanMemsetInBlitH = true; |
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 | |
| 199 | return blitter; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 202 | void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 203 | p->append(SkRasterPipeline::move_src_dst); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 204 | switch (fDst.info().colorType()) { |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 205 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break; |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 206 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 207 | case kBGRA_8888_SkColorType: |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 208 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break; |
| 209 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 210 | default: break; |
| 211 | } |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 212 | if (fDst.info().colorType() == kBGRA_8888_SkColorType) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 213 | p->append(SkRasterPipeline::swap_rb); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 214 | } |
| 215 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 216 | p->append_from_srgb(fDst.info().alphaType()); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 217 | } |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 218 | p->append(SkRasterPipeline::swap); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 221 | void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { |
Matt Sarett | f388093 | 2017-03-24 10:06:03 -0400 | [diff] [blame] | 222 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 223 | p->append(SkRasterPipeline::to_srgb); |
| 224 | } |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 225 | if (fDitherCtx.rate > 0.0f) { |
| 226 | // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible |
| 227 | // over the whole range. If we did it before, 1/255.0f is too big a rate near zero. |
| 228 | p->append(SkRasterPipeline::dither, &fDitherCtx); |
| 229 | } |
| 230 | |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 231 | if (fDst.info().colorType() == kBGRA_8888_SkColorType) { |
| 232 | p->append(SkRasterPipeline::swap_rb); |
| 233 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 234 | switch (fDst.info().colorType()) { |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 235 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 236 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break; |
| 237 | case kBGRA_8888_SkColorType: |
| 238 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break; |
| 239 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 240 | default: break; |
| 241 | } |
| 242 | } |
| 243 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 244 | void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const { |
Mike Klein | bb33833 | 2017-05-04 12:42:52 -0400 | [diff] [blame] | 245 | SkBlendMode_AppendStages(fBlend, p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 246 | } |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 247 | |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 248 | void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const { |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 249 | if (SkBlendMode_CanOverflow(fBlend)) { |
| 250 | p->append(SkRasterPipeline::clamp_a); |
| 251 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 252 | } |
| 253 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 254 | void SkRasterPipelineBlitter::blitH(int x, int y, int w) { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 255 | fDstPtr = fDst.writable_addr(0,y); |
| 256 | fCurrentY = y; |
| 257 | |
| 258 | if (fCanMemsetInBlitH) { |
| 259 | switch (fDst.shiftPerPixel()) { |
Mike Klein | 8612548 | 2017-02-17 16:10:46 +0000 | [diff] [blame] | 260 | case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return; |
| 261 | case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return; |
| 262 | case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return; |
| 263 | case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 264 | default: break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | auto& p = fBlitH; |
| 269 | if (p.empty()) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 270 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 271 | if (fBlend != SkBlendMode::kSrc) { |
| 272 | this->append_load_d(&p); |
| 273 | this->append_blend(&p); |
| 274 | this->maybe_clamp(&p); |
| 275 | } |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 276 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 277 | } |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 278 | p.run(x,w); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 282 | auto& p = fBlitAntiH; |
| 283 | if (p.empty()) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 284 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 285 | if (fBlend == SkBlendMode::kSrcOver) { |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 286 | p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 287 | this->append_load_d(&p); |
| 288 | this->append_blend(&p); |
| 289 | } else { |
| 290 | this->append_load_d(&p); |
| 291 | this->append_blend(&p); |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 292 | p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 293 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 294 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 295 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 296 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 297 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 298 | fDstPtr = fDst.writable_addr(0,y); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 299 | fCurrentY = y; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 300 | for (int16_t run = *runs; run > 0; run = *runs) { |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 301 | switch (*aa) { |
| 302 | case 0x00: break; |
| 303 | case 0xff: this->blitH(x,y,run); break; |
| 304 | default: |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 305 | fCurrentCoverage = *aa * (1/255.0f); |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 306 | p.run(x,run); |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 307 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 308 | x += run; |
| 309 | runs += run; |
| 310 | aa += run; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 315 | if (mask.fFormat == SkMask::kBW_Format) { |
| 316 | // TODO: native BW masks? |
| 317 | return INHERITED::blitMask(mask, clip); |
| 318 | } |
| 319 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 320 | if (mask.fFormat == SkMask::kA8_Format && fBlitMaskA8.empty()) { |
| 321 | auto& p = fBlitMaskA8; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 322 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 323 | if (fBlend == SkBlendMode::kSrcOver) { |
| 324 | p.append(SkRasterPipeline::scale_u8, &fMaskPtr); |
| 325 | this->append_load_d(&p); |
| 326 | this->append_blend(&p); |
| 327 | } else { |
| 328 | this->append_load_d(&p); |
| 329 | this->append_blend(&p); |
| 330 | p.append(SkRasterPipeline::lerp_u8, &fMaskPtr); |
| 331 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 332 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 333 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 334 | } |
| 335 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 336 | if (mask.fFormat == SkMask::kLCD16_Format && fBlitMaskLCD16.empty()) { |
| 337 | auto& p = fBlitMaskLCD16; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame^] | 338 | p.extend(fColorPipeline); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 339 | this->append_load_d(&p); |
| 340 | this->append_blend(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 341 | p.append(SkRasterPipeline::lerp_565, &fMaskPtr); |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 342 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 343 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | int x = clip.left(); |
| 347 | for (int y = clip.top(); y < clip.bottom(); y++) { |
| 348 | fDstPtr = fDst.writable_addr(0,y); |
Mike Klein | 319ba3d | 2017-01-20 15:11:54 -0500 | [diff] [blame] | 349 | fCurrentY = y; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 350 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 351 | switch (mask.fFormat) { |
| 352 | case SkMask::kA8_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 353 | fMaskPtr = mask.getAddr8(x,y)-x; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 354 | fBlitMaskA8.run(x,clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 355 | break; |
| 356 | case SkMask::kLCD16_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 357 | fMaskPtr = mask.getAddrLCD16(x,y)-x; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 358 | fBlitMaskLCD16.run(x,clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 359 | break; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 360 | default: |
| 361 | // TODO |
| 362 | break; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 363 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 364 | } |
| 365 | } |