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