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 | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 13 | #include "SkColorSpaceXformer.h" |
Mike Klein | baaf8ad | 2016-09-29 09:04:15 -0400 | [diff] [blame] | 14 | #include "SkOpts.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 15 | #include "SkPM4f.h" |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 16 | #include "SkPM4fPriv.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 17 | #include "SkRasterPipeline.h" |
| 18 | #include "SkShader.h" |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 19 | #include "SkShaderBase.h" |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 20 | #include "SkUtils.h" |
Mike Klein | 581e698 | 2017-05-03 13:05:13 -0400 | [diff] [blame] | 21 | #include "../jumper/SkJumper.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 22 | |
Mike Klein | 4e3bc86 | 2017-05-22 20:15:17 +0000 | [diff] [blame] | 23 | class SkRasterPipelineBlitter final : public SkBlitter { |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 24 | public: |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 25 | // This is our common entrypoint for creating the blitter once we've sorted out shaders. |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 26 | static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*, |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 27 | const SkRasterPipeline& shaderPipeline, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 28 | bool is_opaque, bool is_constant, bool wants_dither); |
| 29 | |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 30 | SkRasterPipelineBlitter(SkPixmap dst, |
| 31 | SkBlendMode blend, |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 32 | SkArenaAlloc* alloc) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 33 | : fDst(dst) |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 34 | , fBlend(blend) |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 35 | , fAlloc(alloc) |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 36 | , fColorPipeline(alloc) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 37 | {} |
| 38 | |
Mike Klein | 34d10d7 | 2017-06-05 07:10:01 -0400 | [diff] [blame^] | 39 | void blitH (int x, int y, int w) override; |
| 40 | void blitAntiH (int x, int y, const SkAlpha[], const int16_t[]) override; |
| 41 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 42 | void blitMask (const SkMask&, const SkIRect& clip) override; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 43 | |
| 44 | // TODO: The default implementations of the other blits look fine, |
| 45 | // but some of them like blitV could probably benefit from custom |
| 46 | // blits using something like a SkRasterPipeline::runFew() method. |
| 47 | |
| 48 | private: |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 49 | void append_load_d(SkRasterPipeline*) const; |
| 50 | void append_blend (SkRasterPipeline*) const; |
| 51 | void maybe_clamp (SkRasterPipeline*) const; |
| 52 | void append_store (SkRasterPipeline*) const; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 53 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 54 | SkPixmap fDst; |
| 55 | SkBlendMode fBlend; |
| 56 | SkArenaAlloc* fAlloc; |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 57 | SkRasterPipeline fColorPipeline; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 58 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 59 | // We may be able to specialize blitH() into a memset. |
| 60 | bool fCanMemsetInBlitH = false; |
| 61 | uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16. |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 62 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 63 | // Built lazily on first use. |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 64 | std::function<void(size_t, size_t, size_t)> fBlitH, |
| 65 | fBlitAntiH, |
| 66 | fBlitMaskA8, |
| 67 | fBlitMaskLCD16; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 68 | |
| 69 | // These values are pointed to by the blit pipelines above, |
| 70 | // which allows us to adjust them from call to call. |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 71 | void* fDstPtr = nullptr; |
| 72 | const void* fMaskPtr = nullptr; |
| 73 | float fCurrentCoverage = 0.0f; |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 74 | float fDitherRate = 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) { |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 83 | SkColorSpace* dstCS = dst.colorSpace(); |
| 84 | auto paintColor = alloc->make<SkPM4f>(SkPM4f_from_SkColor(paint.getColor(), dstCS)); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 85 | auto shader = as_SB(paint.getShader()); |
Mike Reed | 98b7a6a | 2017-05-26 09:32:22 -0400 | [diff] [blame] | 86 | bool wants_dither = paint.isDither(); |
| 87 | |
| 88 | #ifdef SK_SUPPORT_LEGACY_RASTERPIPELINE |
| 89 | wants_dither = shader && shader->asAGradient(nullptr) >= SkShader::kLinear_GradientType; |
| 90 | #endif |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 91 | |
| 92 | SkRasterPipeline_<256> shaderPipeline; |
| 93 | if (!shader) { |
| 94 | // Having no shader makes things nice and easy... just use the paint color. |
| 95 | shaderPipeline.append(SkRasterPipeline::constant_color, paintColor); |
| 96 | bool is_opaque = paintColor->a() == 1.0f, |
Mike Reed | 98b7a6a | 2017-05-26 09:32:22 -0400 | [diff] [blame] | 97 | is_constant = true; |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 98 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 99 | shaderPipeline, |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 100 | is_opaque, is_constant, wants_dither); |
| 101 | } |
| 102 | |
| 103 | bool is_opaque = shader->isOpaque() && paintColor->a() == 1.0f; |
| 104 | bool is_constant = shader->isConstant(); |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 105 | if (shader->appendStages(&shaderPipeline, dstCS, alloc, ctm, paint)) { |
| 106 | if (paintColor->a() != 1.0f) { |
| 107 | shaderPipeline.append(SkRasterPipeline::scale_1_float, &paintColor->fVec[SkPM4f::A]); |
| 108 | } |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 109 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline, |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 110 | is_opaque, is_constant, wants_dither); |
| 111 | } |
| 112 | |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 113 | return alloc->make<SkNullBlitter>(); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 117 | const SkPaint& paint, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 118 | const SkRasterPipeline& shaderPipeline, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 119 | bool is_opaque, |
| 120 | bool wants_dither, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 121 | SkArenaAlloc* alloc) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 122 | bool is_constant = false; // If this were the case, it'd be better to just set a paint color. |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 123 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, shaderPipeline, |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 124 | is_opaque, is_constant, wants_dither); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 127 | SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, |
| 128 | const SkPaint& paint, |
| 129 | SkArenaAlloc* alloc, |
| 130 | const SkRasterPipeline& shaderPipeline, |
| 131 | bool is_opaque, |
| 132 | bool is_constant, |
| 133 | bool wants_dither) { |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 134 | auto blitter = alloc->make<SkRasterPipelineBlitter>(dst, |
| 135 | paint.getBlendMode(), |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 136 | alloc); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 137 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 138 | // Our job in this factory is to fill out the blitter's color pipeline. |
| 139 | // This is the common front of the full blit pipelines, each constructed lazily on first use. |
| 140 | // The full blit pipelines handle reading and writing the dst, blending, coverage, dithering. |
| 141 | auto colorPipeline = &blitter->fColorPipeline; |
| 142 | |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 143 | // Let's get the shader in first. |
Mike Reed | 6867eee | 2017-06-02 13:25:15 -0400 | [diff] [blame] | 144 | colorPipeline->extend(shaderPipeline); |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 145 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 146 | // If there's a color filter it comes next. |
| 147 | if (auto colorFilter = paint.getColorFilter()) { |
| 148 | colorFilter->appendStages(colorPipeline, dst.colorSpace(), alloc, is_opaque); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 149 | is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 152 | // We'll dither if the shader wants to, or if we're drawing 565 and the paint wants to. |
| 153 | // Not all formats make sense to dither (think, F16). We set their dither rate to zero. |
| 154 | // We need to decide if we're going to dither now to keep is_constant accurate. |
| 155 | if (wants_dither || |
| 156 | (paint.isDither() && dst.info().colorType() == kRGB_565_SkColorType)) { |
| 157 | switch (dst.info().colorType()) { |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 158 | default: blitter->fDitherRate = 0.0f; break; |
| 159 | case kRGB_565_SkColorType: blitter->fDitherRate = 1/63.0f; break; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 160 | case kRGBA_8888_SkColorType: |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 161 | case kBGRA_8888_SkColorType: blitter->fDitherRate = 1/255.0f; break; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 162 | } |
| 163 | } |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 164 | is_constant = is_constant && (blitter->fDitherRate == 0.0f); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 165 | |
| 166 | // We're logically done here. The code between here and return blitter is all optimization. |
| 167 | |
| 168 | // A pipeline that's still constant here can collapse back into a constant color. |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 169 | if (is_constant) { |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 170 | auto constantColor = alloc->make<SkPM4f>(); |
| 171 | colorPipeline->append(SkRasterPipeline::store_f32, &constantColor); |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 172 | colorPipeline->run(0,0,1); |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 173 | colorPipeline->reset(); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 174 | colorPipeline->append(SkRasterPipeline::constant_color, constantColor); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 175 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 176 | is_opaque = constantColor->a() == 1.0f; |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 177 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 178 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 179 | // We can strength-reduce SrcOver into Src when opaque. |
| 180 | if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) { |
| 181 | blitter->fBlend = SkBlendMode::kSrc; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 184 | // When we're drawing a constant color in Src mode, we can sometimes just memset. |
| 185 | // (The previous two optimizations help find more opportunities for this one.) |
| 186 | if (is_constant && blitter->fBlend == SkBlendMode::kSrc) { |
| 187 | // Run our color pipeline all the way through to produce what we'd memset when we can. |
| 188 | // Not all blits can memset, so we need to keep colorPipeline too. |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 189 | SkRasterPipeline_<256> p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 190 | p.extend(*colorPipeline); |
| 191 | blitter->fDstPtr = &blitter->fMemsetColor; |
| 192 | blitter->append_store(&p); |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 193 | p.run(0,0,1); |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 194 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 195 | blitter->fCanMemsetInBlitH = true; |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 196 | } |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 197 | |
| 198 | return blitter; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 201 | void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 202 | p->append(SkRasterPipeline::move_src_dst); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 203 | switch (fDst.info().colorType()) { |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 204 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8, &fDstPtr); break; |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 205 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565, &fDstPtr); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 206 | case kBGRA_8888_SkColorType: |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 207 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888, &fDstPtr); break; |
| 208 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16, &fDstPtr); break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 209 | default: break; |
| 210 | } |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 211 | if (fDst.info().colorType() == kBGRA_8888_SkColorType) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 212 | p->append(SkRasterPipeline::swap_rb); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 213 | } |
| 214 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 215 | p->append_from_srgb(fDst.info().alphaType()); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 216 | } |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 217 | p->append(SkRasterPipeline::swap); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 220 | void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { |
Matt Sarett | f388093 | 2017-03-24 10:06:03 -0400 | [diff] [blame] | 221 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 222 | p->append(SkRasterPipeline::to_srgb); |
| 223 | } |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 224 | if (fDitherRate > 0.0f) { |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 225 | // We dither after any sRGB transfer function to make sure our 1/255.0f is sensible |
| 226 | // over the whole range. If we did it before, 1/255.0f is too big a rate near zero. |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 227 | p->append(SkRasterPipeline::dither, &fDitherRate); |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 230 | if (fDst.info().colorType() == kBGRA_8888_SkColorType) { |
| 231 | p->append(SkRasterPipeline::swap_rb); |
| 232 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 233 | switch (fDst.info().colorType()) { |
Mike Klein | e71b167 | 2017-01-13 07:59:23 -0500 | [diff] [blame] | 234 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, &fDstPtr); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 235 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, &fDstPtr); break; |
| 236 | case kBGRA_8888_SkColorType: |
| 237 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, &fDstPtr); break; |
| 238 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, &fDstPtr); break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 239 | default: break; |
| 240 | } |
| 241 | } |
| 242 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 243 | void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const { |
Mike Klein | bb33833 | 2017-05-04 12:42:52 -0400 | [diff] [blame] | 244 | SkBlendMode_AppendStages(fBlend, p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 245 | } |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 246 | |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 247 | void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const { |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 248 | if (SkBlendMode_CanOverflow(fBlend)) { |
| 249 | p->append(SkRasterPipeline::clamp_a); |
| 250 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 251 | } |
| 252 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 253 | void SkRasterPipelineBlitter::blitH(int x, int y, int w) { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 254 | fDstPtr = fDst.writable_addr(0,y); |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 255 | |
| 256 | if (fCanMemsetInBlitH) { |
| 257 | switch (fDst.shiftPerPixel()) { |
Mike Klein | 8612548 | 2017-02-17 16:10:46 +0000 | [diff] [blame] | 258 | case 0: memset ((uint8_t *)fDstPtr + x, fMemsetColor, w); return; |
| 259 | case 1: sk_memset16((uint16_t*)fDstPtr + x, fMemsetColor, w); return; |
| 260 | case 2: sk_memset32((uint32_t*)fDstPtr + x, fMemsetColor, w); return; |
| 261 | case 3: sk_memset64((uint64_t*)fDstPtr + x, fMemsetColor, w); return; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 262 | default: break; |
| 263 | } |
| 264 | } |
| 265 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 266 | if (!fBlitH) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 267 | SkRasterPipeline p(fAlloc); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 268 | p.extend(fColorPipeline); |
Mike Klein | 5062626 | 2017-05-25 13:06:57 -0400 | [diff] [blame] | 269 | if (fBlend == SkBlendMode::kSrcOver |
| 270 | && fDst.info().colorType() == kRGBA_8888_SkColorType |
| 271 | && !fDst.colorSpace() |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 272 | && fDitherRate == 0.0f) { |
Mike Klein | 5062626 | 2017-05-25 13:06:57 -0400 | [diff] [blame] | 273 | p.append(SkRasterPipeline::srcover_rgba_8888, &fDstPtr); |
| 274 | } else { |
| 275 | if (fBlend != SkBlendMode::kSrc) { |
| 276 | this->append_load_d(&p); |
| 277 | this->append_blend(&p); |
| 278 | this->maybe_clamp(&p); |
| 279 | } |
| 280 | this->append_store(&p); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 281 | } |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 282 | fBlitH = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 283 | } |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 284 | fBlitH(x,y,w); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) { |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 288 | if (!fBlitAntiH) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 289 | SkRasterPipeline p(fAlloc); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 290 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 291 | if (fBlend == SkBlendMode::kSrcOver) { |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 292 | p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 293 | this->append_load_d(&p); |
| 294 | this->append_blend(&p); |
| 295 | } else { |
| 296 | this->append_load_d(&p); |
| 297 | this->append_blend(&p); |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 298 | p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 299 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 300 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 301 | this->append_store(&p); |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 302 | fBlitAntiH = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 303 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 304 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 305 | fDstPtr = fDst.writable_addr(0,y); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 306 | for (int16_t run = *runs; run > 0; run = *runs) { |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 307 | switch (*aa) { |
| 308 | case 0x00: break; |
| 309 | case 0xff: this->blitH(x,y,run); break; |
| 310 | default: |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 311 | fCurrentCoverage = *aa * (1/255.0f); |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 312 | fBlitAntiH(x,y,run); |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 313 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 314 | x += run; |
| 315 | runs += run; |
| 316 | aa += run; |
| 317 | } |
| 318 | } |
| 319 | |
Mike Klein | 34d10d7 | 2017-06-05 07:10:01 -0400 | [diff] [blame^] | 320 | void SkRasterPipelineBlitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { |
| 321 | SkIRect clip = {x,y, x+2,y+1}; |
| 322 | uint8_t coverage[] = { (uint8_t)a0, (uint8_t)a1 }; |
| 323 | |
| 324 | SkMask mask; |
| 325 | mask.fImage = coverage; |
| 326 | mask.fBounds = clip; |
| 327 | mask.fRowBytes = 2; |
| 328 | mask.fFormat = SkMask::kA8_Format; |
| 329 | |
| 330 | this->blitMask(mask, clip); |
| 331 | } |
| 332 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 333 | void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 334 | if (mask.fFormat == SkMask::kBW_Format) { |
| 335 | // TODO: native BW masks? |
| 336 | return INHERITED::blitMask(mask, clip); |
| 337 | } |
| 338 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 339 | if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 340 | SkRasterPipeline p(fAlloc); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 341 | p.extend(fColorPipeline); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 342 | if (fBlend == SkBlendMode::kSrcOver) { |
| 343 | p.append(SkRasterPipeline::scale_u8, &fMaskPtr); |
| 344 | this->append_load_d(&p); |
| 345 | this->append_blend(&p); |
| 346 | } else { |
| 347 | this->append_load_d(&p); |
| 348 | this->append_blend(&p); |
| 349 | p.append(SkRasterPipeline::lerp_u8, &fMaskPtr); |
| 350 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 351 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 352 | this->append_store(&p); |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 353 | fBlitMaskA8 = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 354 | } |
| 355 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 356 | if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 357 | SkRasterPipeline p(fAlloc); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 358 | p.extend(fColorPipeline); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 359 | this->append_load_d(&p); |
| 360 | this->append_blend(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 361 | p.append(SkRasterPipeline::lerp_565, &fMaskPtr); |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 362 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 363 | this->append_store(&p); |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 364 | fBlitMaskLCD16 = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | int x = clip.left(); |
| 368 | for (int y = clip.top(); y < clip.bottom(); y++) { |
| 369 | fDstPtr = fDst.writable_addr(0,y); |
| 370 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 371 | switch (mask.fFormat) { |
| 372 | case SkMask::kA8_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 373 | fMaskPtr = mask.getAddr8(x,y)-x; |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 374 | fBlitMaskA8(x,y,clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 375 | break; |
| 376 | case SkMask::kLCD16_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 377 | fMaskPtr = mask.getAddrLCD16(x,y)-x; |
Mike Klein | 761d27c | 2017-06-01 12:37:08 -0400 | [diff] [blame] | 378 | fBlitMaskLCD16(x,y,clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 379 | break; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 380 | default: |
| 381 | // TODO |
| 382 | break; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 383 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 384 | } |
| 385 | } |