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