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