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