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