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