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 | |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame^] | 8 | #include "../jumper/SkJumper.h" |
Herb Derby | ac04fef | 2017-01-13 17:34:33 -0500 | [diff] [blame] | 9 | #include "SkArenaAlloc.h" |
Hal Canary | fdcfb8b | 2018-06-13 09:42:32 -0400 | [diff] [blame] | 10 | #include "SkBlendModePriv.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame^] | 11 | #include "SkBlitter.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 12 | #include "SkColor.h" |
| 13 | #include "SkColorFilter.h" |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 14 | #include "SkColorSpaceXformer.h" |
Mike Klein | baaf8ad | 2016-09-29 09:04:15 -0400 | [diff] [blame] | 15 | #include "SkOpts.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 16 | #include "SkPM4f.h" |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 17 | #include "SkPM4fPriv.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 18 | #include "SkRasterPipeline.h" |
| 19 | #include "SkShader.h" |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 20 | #include "SkShaderBase.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame^] | 21 | #include "SkTo.h" |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 22 | #include "SkUtils.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 23 | |
Mike Klein | 4e3bc86 | 2017-05-22 20:15:17 +0000 | [diff] [blame] | 24 | class SkRasterPipelineBlitter final : public SkBlitter { |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 25 | public: |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 26 | // 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] | 27 | static SkBlitter* Create(const SkPixmap&, const SkPaint&, SkArenaAlloc*, |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 28 | const SkRasterPipeline& shaderPipeline, |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 29 | SkShaderBase::Context*, |
Mike Reed | eb7dc79 | 2017-06-12 12:48:45 -0400 | [diff] [blame] | 30 | bool is_opaque, bool is_constant); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 31 | |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 32 | SkRasterPipelineBlitter(SkPixmap dst, |
| 33 | SkBlendMode blend, |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 34 | SkArenaAlloc* alloc, |
| 35 | SkShaderBase::Context* burstCtx) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 36 | : fDst(dst) |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 37 | , fBlend(blend) |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 38 | , fAlloc(alloc) |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 39 | , fBurstCtx(burstCtx) |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 40 | , fColorPipeline(alloc) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 41 | {} |
| 42 | |
Mike Klein | 34d10d7 | 2017-06-05 07:10:01 -0400 | [diff] [blame] | 43 | void blitH (int x, int y, int w) override; |
| 44 | void blitAntiH (int x, int y, const SkAlpha[], const int16_t[]) override; |
| 45 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
Mike Reed | cc7f660 | 2017-09-06 14:00:24 -0400 | [diff] [blame] | 46 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
Mike Klein | 34d10d7 | 2017-06-05 07:10:01 -0400 | [diff] [blame] | 47 | void blitMask (const SkMask&, const SkIRect& clip) override; |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 48 | void blitRect (int x, int y, int width, int height) override; |
Mike Reed | e6befa5 | 2017-08-28 11:30:48 -0400 | [diff] [blame] | 49 | void blitV (int x, int y, int height, SkAlpha alpha) override; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 50 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 51 | private: |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 52 | void append_load_dst(SkRasterPipeline*) const; |
| 53 | void append_store (SkRasterPipeline*) const; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 54 | |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 55 | // If we have an burst context, use it to fill our shader buffer. |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 56 | void burst_shade(int x, int y, int w); |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 57 | |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 58 | SkPixmap fDst; |
| 59 | SkBlendMode fBlend; |
| 60 | SkArenaAlloc* fAlloc; |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 61 | SkShaderBase::Context* fBurstCtx; |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 62 | SkRasterPipeline fColorPipeline; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 63 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 64 | SkJumper_MemoryCtx fShaderOutput = {nullptr,0}, // Possibly updated each call to burst_shade(). |
| 65 | fDstPtr = {nullptr,0}, // Always points to the top-left of fDst. |
| 66 | fMaskPtr = {nullptr,0}; // Updated each call to blitMask(). |
| 67 | |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 68 | // We may be able to specialize blitH() or blitRect() into a memset. |
| 69 | bool fCanMemsetInBlitRect = false; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 70 | uint64_t fMemsetColor = 0; // Big enough for largest dst format, F16. |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 71 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 72 | // Built lazily on first use. |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 73 | std::function<void(size_t, size_t, size_t, size_t)> fBlitRect, |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 74 | fBlitAntiH, |
| 75 | fBlitMaskA8, |
| 76 | fBlitMaskLCD16; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 77 | |
| 78 | // These values are pointed to by the blit pipelines above, |
| 79 | // which allows us to adjust them from call to call. |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 80 | float fCurrentCoverage = 0.0f; |
| 81 | float fDitherRate = 0.0f; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 82 | |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 83 | std::vector<SkPM4f> fShaderBuffer; |
| 84 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 85 | typedef SkBlitter INHERITED; |
| 86 | }; |
| 87 | |
| 88 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 89 | const SkPaint& paint, |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame] | 90 | const SkMatrix& ctm, |
Matt Sarett | 25834ff | 2017-02-15 15:54:35 -0500 | [diff] [blame] | 91 | SkArenaAlloc* alloc) { |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 92 | SkColorSpace* dstCS = dst.colorSpace(); |
Mike Reed | c91e387 | 2017-07-05 14:12:37 -0400 | [diff] [blame] | 93 | SkPM4f paintColor = SkPM4f_from_SkColor(paint.getColor(), dstCS); |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 94 | auto shader = as_SB(paint.getShader()); |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 95 | |
| 96 | SkRasterPipeline_<256> shaderPipeline; |
| 97 | if (!shader) { |
| 98 | // Having no shader makes things nice and easy... just use the paint color. |
Mike Klein | 073073e | 2017-08-03 09:42:53 -0400 | [diff] [blame] | 99 | shaderPipeline.append_constant_color(alloc, paintColor); |
Mike Reed | c91e387 | 2017-07-05 14:12:37 -0400 | [diff] [blame] | 100 | bool is_opaque = paintColor.a() == 1.0f, |
Mike Reed | 98b7a6a | 2017-05-26 09:32:22 -0400 | [diff] [blame] | 101 | is_constant = true; |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 102 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 103 | shaderPipeline, nullptr, |
Mike Reed | eb7dc79 | 2017-06-12 12:48:45 -0400 | [diff] [blame] | 104 | is_opaque, is_constant); |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Mike Reed | c91e387 | 2017-07-05 14:12:37 -0400 | [diff] [blame] | 107 | bool is_opaque = shader->isOpaque() && paintColor.a() == 1.0f; |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 108 | bool is_constant = shader->isConstant(); |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 109 | |
| 110 | // Check whether the shader prefers to run in burst mode. |
| 111 | if (auto* burstCtx = shader->makeBurstPipelineContext( |
| 112 | SkShaderBase::ContextRec(paint, ctm, nullptr, SkShaderBase::ContextRec::kPM4f_DstType, |
| 113 | dstCS), alloc)) { |
| 114 | return SkRasterPipelineBlitter::Create(dst, paint, alloc, |
| 115 | shaderPipeline, burstCtx, |
Mike Reed | eb7dc79 | 2017-06-12 12:48:45 -0400 | [diff] [blame] | 116 | is_opaque, is_constant); |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Mike Reed | 1d8c42e | 2017-08-29 14:58:19 -0400 | [diff] [blame] | 119 | if (shader->appendStages({&shaderPipeline, alloc, dstCS, paint, nullptr, ctm})) { |
Mike Reed | c91e387 | 2017-07-05 14:12:37 -0400 | [diff] [blame] | 120 | if (paintColor.a() != 1.0f) { |
| 121 | shaderPipeline.append(SkRasterPipeline::scale_1_float, |
| 122 | alloc->make<float>(paintColor.a())); |
Mike Klein | 3b840e9 | 2017-05-23 15:06:17 -0400 | [diff] [blame] | 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 | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 172 | // Not all formats make sense to dither (think, F16). We set their dither rate |
| 173 | // to zero. 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 | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 176 | default: blitter->fDitherRate = 0.0f; break; |
| 177 | case kARGB_4444_SkColorType: blitter->fDitherRate = 1/15.0f; break; |
| 178 | case kRGB_565_SkColorType: blitter->fDitherRate = 1/63.0f; break; |
Mike Klein | 95d19f3 | 2017-06-15 07:40:24 -0700 | [diff] [blame] | 179 | case kGray_8_SkColorType: |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 180 | case kRGB_888x_SkColorType: |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 181 | case kRGBA_8888_SkColorType: |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 182 | case kBGRA_8888_SkColorType: blitter->fDitherRate = 1/255.0f; break; |
| 183 | case kRGB_101010x_SkColorType: |
| 184 | case kRGBA_1010102_SkColorType: blitter->fDitherRate = 1/1023.0f; break; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 185 | } |
Mike Reed | eb7dc79 | 2017-06-12 12:48:45 -0400 | [diff] [blame] | 186 | // TODO: for constant colors, we could try to measure the effect of dithering, and if |
| 187 | // it has no value (i.e. all variations result in the same 32bit color, then we |
| 188 | // could disable it (for speed, by not adding the stage). |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 189 | } |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 190 | is_constant = is_constant && (blitter->fDitherRate == 0.0f); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 191 | |
| 192 | // We're logically done here. The code between here and return blitter is all optimization. |
| 193 | |
| 194 | // 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] | 195 | if (is_constant) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 196 | SkPM4f constantColor; |
| 197 | SkJumper_MemoryCtx constantColorPtr = { &constantColor, 0 }; |
| 198 | colorPipeline->append(SkRasterPipeline::store_f32, &constantColorPtr); |
| 199 | colorPipeline->run(0,0,1,1); |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 200 | colorPipeline->reset(); |
Mike Klein | 073073e | 2017-08-03 09:42:53 -0400 | [diff] [blame] | 201 | colorPipeline->append_constant_color(alloc, constantColor); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 202 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 203 | is_opaque = constantColor.a() == 1.0f; |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 204 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 205 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 206 | // We can strength-reduce SrcOver into Src when opaque. |
| 207 | if (is_opaque && blitter->fBlend == SkBlendMode::kSrcOver) { |
| 208 | blitter->fBlend = SkBlendMode::kSrc; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 211 | // When we're drawing a constant color in Src mode, we can sometimes just memset. |
| 212 | // (The previous two optimizations help find more opportunities for this one.) |
| 213 | if (is_constant && blitter->fBlend == SkBlendMode::kSrc) { |
| 214 | // Run our color pipeline all the way through to produce what we'd memset when we can. |
| 215 | // Not all blits can memset, so we need to keep colorPipeline too. |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 216 | SkRasterPipeline_<256> p; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 217 | p.extend(*colorPipeline); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 218 | blitter->fDstPtr = SkJumper_MemoryCtx{&blitter->fMemsetColor, 0}; |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 219 | blitter->append_store(&p); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 220 | p.run(0,0,1,1); |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 221 | |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 222 | blitter->fCanMemsetInBlitRect = true; |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 223 | } |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 224 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 225 | blitter->fDstPtr = SkJumper_MemoryCtx{ |
| 226 | blitter->fDst.writable_addr(), |
| 227 | blitter->fDst.rowBytesAsPixels(), |
| 228 | }; |
| 229 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 230 | return blitter; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 233 | void SkRasterPipelineBlitter::append_load_dst(SkRasterPipeline* p) const { |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 234 | const void* ctx = &fDstPtr; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 235 | switch (fDst.info().colorType()) { |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 236 | default: break; |
| 237 | |
| 238 | case kGray_8_SkColorType: p->append(SkRasterPipeline::load_g8_dst, ctx); break; |
| 239 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::load_a8_dst, ctx); break; |
| 240 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::load_565_dst, ctx); break; |
| 241 | case kARGB_4444_SkColorType: p->append(SkRasterPipeline::load_4444_dst, ctx); break; |
| 242 | case kBGRA_8888_SkColorType: p->append(SkRasterPipeline::load_bgra_dst, ctx); break; |
| 243 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::load_8888_dst, ctx); break; |
| 244 | case kRGBA_1010102_SkColorType: p->append(SkRasterPipeline::load_1010102_dst, ctx); break; |
| 245 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::load_f16_dst, ctx); break; |
| 246 | |
| 247 | case kRGB_888x_SkColorType: p->append(SkRasterPipeline::load_8888_dst, ctx); |
| 248 | p->append(SkRasterPipeline::force_opaque_dst ); break; |
| 249 | case kRGB_101010x_SkColorType: p->append(SkRasterPipeline::load_1010102_dst, ctx); |
| 250 | p->append(SkRasterPipeline::force_opaque_dst ); break; |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 251 | } |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 252 | if (fDst.info().alphaType() == kUnpremul_SkAlphaType) { |
| 253 | p->append(SkRasterPipeline::premul_dst); |
| 254 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Mike Klein | 14c8f82 | 2016-11-30 19:39:43 -0500 | [diff] [blame] | 257 | void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 258 | if (fDst.info().alphaType() == kUnpremul_SkAlphaType) { |
| 259 | p->append(SkRasterPipeline::unpremul); |
| 260 | } |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 261 | if (fDitherRate > 0.0f) { |
Mike Klein | 9b10f8f | 2017-06-01 13:11:16 -0400 | [diff] [blame] | 262 | p->append(SkRasterPipeline::dither, &fDitherRate); |
Mike Klein | db711c9 | 2017-05-03 17:57:48 -0400 | [diff] [blame] | 263 | } |
| 264 | |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 265 | const void* ctx = &fDstPtr; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 266 | switch (fDst.info().colorType()) { |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 267 | default: break; |
Mike Klein | ac568a9 | 2018-01-25 09:09:32 -0500 | [diff] [blame] | 268 | |
| 269 | case kGray_8_SkColorType: p->append(SkRasterPipeline::luminance_to_alpha); |
| 270 | p->append(SkRasterPipeline::store_a8, ctx); break; |
| 271 | case kAlpha_8_SkColorType: p->append(SkRasterPipeline::store_a8, ctx); break; |
| 272 | case kRGB_565_SkColorType: p->append(SkRasterPipeline::store_565, ctx); break; |
| 273 | case kARGB_4444_SkColorType: p->append(SkRasterPipeline::store_4444, ctx); break; |
| 274 | case kBGRA_8888_SkColorType: p->append(SkRasterPipeline::store_bgra, ctx); break; |
| 275 | case kRGBA_8888_SkColorType: p->append(SkRasterPipeline::store_8888, ctx); break; |
| 276 | case kRGBA_1010102_SkColorType: p->append(SkRasterPipeline::store_1010102, ctx); break; |
| 277 | case kRGBA_F16_SkColorType: p->append(SkRasterPipeline::store_f16, ctx); break; |
| 278 | |
| 279 | case kRGB_888x_SkColorType: p->append(SkRasterPipeline::force_opaque ); |
| 280 | p->append(SkRasterPipeline::store_8888, ctx); break; |
| 281 | case kRGB_101010x_SkColorType: p->append(SkRasterPipeline::force_opaque ); |
| 282 | p->append(SkRasterPipeline::store_1010102, ctx); break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 286 | void SkRasterPipelineBlitter::burst_shade(int x, int y, int w) { |
| 287 | SkASSERT(fBurstCtx); |
| 288 | if (w > SkToInt(fShaderBuffer.size())) { |
| 289 | fShaderBuffer.resize(w); |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 290 | } |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 291 | fBurstCtx->shadeSpan4f(x,y, fShaderBuffer.data(), w); |
| 292 | // We'll be reading from fShaderOutput.pixels + x, so back up by x. |
| 293 | fShaderOutput = SkJumper_MemoryCtx{ fShaderBuffer.data() - x, 0 }; |
Florin Malita | 47e55a5 | 2017-06-06 12:26:54 -0400 | [diff] [blame] | 294 | } |
| 295 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 296 | void SkRasterPipelineBlitter::blitH(int x, int y, int w) { |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 297 | this->blitRect(x,y,w,1); |
| 298 | } |
| 299 | |
| 300 | void SkRasterPipelineBlitter::blitRect(int x, int y, int w, int h) { |
| 301 | if (fCanMemsetInBlitRect) { |
| 302 | for (int ylimit = y+h; y < ylimit; y++) { |
| 303 | switch (fDst.shiftPerPixel()) { |
| 304 | case 0: memset (fDst.writable_addr8 (x,y), fMemsetColor, w); break; |
| 305 | case 1: sk_memset16(fDst.writable_addr16(x,y), fMemsetColor, w); break; |
| 306 | case 2: sk_memset32(fDst.writable_addr32(x,y), fMemsetColor, w); break; |
| 307 | case 3: sk_memset64(fDst.writable_addr64(x,y), fMemsetColor, w); break; |
| 308 | default: break; |
| 309 | } |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 310 | } |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 311 | return; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 312 | } |
| 313 | |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 314 | if (!fBlitRect) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 315 | SkRasterPipeline p(fAlloc); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 316 | p.extend(fColorPipeline); |
Mike Klein | 0cb1589 | 2017-10-24 11:07:09 -0400 | [diff] [blame] | 317 | if (fBlend == SkBlendMode::kSrcOver |
| 318 | && (fDst.info().colorType() == kRGBA_8888_SkColorType || |
| 319 | fDst.info().colorType() == kBGRA_8888_SkColorType) |
| 320 | && !fDst.colorSpace() |
| 321 | && fDst.info().alphaType() != kUnpremul_SkAlphaType |
| 322 | && fDitherRate == 0.0f) { |
Mike Klein | 0cb1589 | 2017-10-24 11:07:09 -0400 | [diff] [blame] | 323 | auto stage = fDst.info().colorType() == kRGBA_8888_SkColorType |
| 324 | ? SkRasterPipeline::srcover_rgba_8888 |
| 325 | : SkRasterPipeline::srcover_bgra_8888; |
| 326 | p.append(stage, &fDstPtr); |
Mike Klein | 5062626 | 2017-05-25 13:06:57 -0400 | [diff] [blame] | 327 | } else { |
| 328 | if (fBlend != SkBlendMode::kSrc) { |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 329 | this->append_load_dst(&p); |
| 330 | SkBlendMode_AppendStages(fBlend, &p); |
Mike Klein | 5062626 | 2017-05-25 13:06:57 -0400 | [diff] [blame] | 331 | } |
| 332 | this->append_store(&p); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 333 | } |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 334 | fBlitRect = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 335 | } |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 336 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 337 | if (fBurstCtx) { |
Mike Klein | 3b59af5 | 2017-07-20 16:02:12 -0400 | [diff] [blame] | 338 | // We can only burst shade one row at a time. |
| 339 | for (int ylimit = y+h; y < ylimit; y++) { |
| 340 | this->burst_shade(x,y,w); |
| 341 | fBlitRect(x,y, w,1); |
| 342 | } |
| 343 | } else { |
| 344 | // If not bursting we can blit the entire rect at once. |
| 345 | fBlitRect(x,y,w,h); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 346 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | 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] | 350 | if (!fBlitAntiH) { |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 351 | SkRasterPipeline p(fAlloc); |
| 352 | p.extend(fColorPipeline); |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 353 | if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/false)) { |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 354 | p.append(SkRasterPipeline::scale_1_float, &fCurrentCoverage); |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 355 | this->append_load_dst(&p); |
| 356 | SkBlendMode_AppendStages(fBlend, &p); |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 357 | } else { |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 358 | this->append_load_dst(&p); |
| 359 | SkBlendMode_AppendStages(fBlend, &p); |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 360 | p.append(SkRasterPipeline::lerp_1_float, &fCurrentCoverage); |
| 361 | } |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 362 | |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 363 | this->append_store(&p); |
| 364 | fBlitAntiH = p.compile(); |
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 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 367 | for (int16_t run = *runs; run > 0; run = *runs) { |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 368 | switch (*aa) { |
| 369 | case 0x00: break; |
| 370 | case 0xff: this->blitH(x,y,run); break; |
| 371 | default: |
Mike Klein | babd93e | 2016-11-30 16:05:10 -0500 | [diff] [blame] | 372 | fCurrentCoverage = *aa * (1/255.0f); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 373 | if (fBurstCtx) { |
| 374 | this->burst_shade(x,y,run); |
| 375 | } |
| 376 | fBlitAntiH(x,y,run,1); |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 377 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 378 | x += run; |
| 379 | runs += run; |
| 380 | aa += run; |
| 381 | } |
| 382 | } |
| 383 | |
Mike Klein | 34d10d7 | 2017-06-05 07:10:01 -0400 | [diff] [blame] | 384 | void SkRasterPipelineBlitter::blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) { |
| 385 | SkIRect clip = {x,y, x+2,y+1}; |
| 386 | uint8_t coverage[] = { (uint8_t)a0, (uint8_t)a1 }; |
| 387 | |
| 388 | SkMask mask; |
| 389 | mask.fImage = coverage; |
| 390 | mask.fBounds = clip; |
| 391 | mask.fRowBytes = 2; |
| 392 | mask.fFormat = SkMask::kA8_Format; |
| 393 | |
| 394 | this->blitMask(mask, clip); |
| 395 | } |
| 396 | |
Mike Reed | cc7f660 | 2017-09-06 14:00:24 -0400 | [diff] [blame] | 397 | void SkRasterPipelineBlitter::blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) { |
| 398 | SkIRect clip = {x,y, x+1,y+2}; |
| 399 | uint8_t coverage[] = { (uint8_t)a0, (uint8_t)a1 }; |
| 400 | |
| 401 | SkMask mask; |
| 402 | mask.fImage = coverage; |
| 403 | mask.fBounds = clip; |
| 404 | mask.fRowBytes = 1; |
| 405 | mask.fFormat = SkMask::kA8_Format; |
| 406 | |
| 407 | this->blitMask(mask, clip); |
| 408 | } |
| 409 | |
Mike Reed | e6befa5 | 2017-08-28 11:30:48 -0400 | [diff] [blame] | 410 | void SkRasterPipelineBlitter::blitV(int x, int y, int height, SkAlpha alpha) { |
| 411 | SkIRect clip = {x,y, x+1,y+height}; |
| 412 | |
| 413 | SkMask mask; |
| 414 | mask.fImage = α |
| 415 | mask.fBounds = clip; |
| 416 | mask.fRowBytes = 0; // so we reuse the 1 "row" for all of height |
| 417 | mask.fFormat = SkMask::kA8_Format; |
| 418 | |
| 419 | this->blitMask(mask, clip); |
| 420 | } |
| 421 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 422 | void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 423 | if (mask.fFormat == SkMask::kBW_Format) { |
| 424 | // TODO: native BW masks? |
| 425 | return INHERITED::blitMask(mask, clip); |
| 426 | } |
| 427 | |
Mike Klein | e822803 | 2017-11-14 13:41:30 -0500 | [diff] [blame] | 428 | // We'll use the first (A8) plane of any mask and ignore the other two, just like Ganesh. |
| 429 | SkMask::Format effectiveMaskFormat = mask.fFormat == SkMask::k3D_Format ? SkMask::kA8_Format |
| 430 | : mask.fFormat; |
| 431 | |
| 432 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 433 | // Lazily build whichever pipeline we need, specialized for each mask format. |
Mike Klein | e822803 | 2017-11-14 13:41:30 -0500 | [diff] [blame] | 434 | if (effectiveMaskFormat == SkMask::kA8_Format && !fBlitMaskA8) { |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 435 | SkRasterPipeline p(fAlloc); |
| 436 | p.extend(fColorPipeline); |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 437 | if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/false)) { |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 438 | p.append(SkRasterPipeline::scale_u8, &fMaskPtr); |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 439 | this->append_load_dst(&p); |
| 440 | SkBlendMode_AppendStages(fBlend, &p); |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 441 | } else { |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 442 | this->append_load_dst(&p); |
| 443 | SkBlendMode_AppendStages(fBlend, &p); |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 444 | p.append(SkRasterPipeline::lerp_u8, &fMaskPtr); |
| 445 | } |
Florin Malita | c3a863f | 2017-08-23 20:36:02 +0000 | [diff] [blame] | 446 | this->append_store(&p); |
| 447 | fBlitMaskA8 = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 448 | } |
Mike Klein | e822803 | 2017-11-14 13:41:30 -0500 | [diff] [blame] | 449 | if (effectiveMaskFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 450 | SkRasterPipeline p(fAlloc); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 451 | p.extend(fColorPipeline); |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 452 | if (SkBlendMode_ShouldPreScaleCoverage(fBlend, /*rgb_coverage=*/true)) { |
| 453 | // Somewhat unusually, scale_565 needs dst loaded first. |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 454 | this->append_load_dst(&p); |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 455 | p.append(SkRasterPipeline::scale_565, &fMaskPtr); |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 456 | SkBlendMode_AppendStages(fBlend, &p); |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 457 | } else { |
Mike Klein | b34b626 | 2017-09-04 12:17:54 -0400 | [diff] [blame] | 458 | this->append_load_dst(&p); |
| 459 | SkBlendMode_AppendStages(fBlend, &p); |
Mike Klein | fb126fa | 2017-08-24 13:06:23 -0400 | [diff] [blame] | 460 | p.append(SkRasterPipeline::lerp_565, &fMaskPtr); |
| 461 | } |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 462 | this->append_store(&p); |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 463 | fBlitMaskLCD16 = p.compile(); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 464 | } |
| 465 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 466 | std::function<void(size_t,size_t,size_t,size_t)>* blitter = nullptr; |
| 467 | // Update fMaskPtr to point "into" this current mask, but lined up with fDstPtr at (0,0). |
Mike Klein | 804d0f2 | 2018-05-31 13:16:59 -0400 | [diff] [blame] | 468 | // This sort of trickery upsets UBSAN (pointer-overflow) so we do our math in uintptr_t. |
| 469 | |
Mike Klein | ec84612 | 2018-02-26 11:56:30 -0500 | [diff] [blame] | 470 | // mask.fRowBytes is a uint32_t, which would break our addressing math on 64-bit builds. |
| 471 | size_t rowBytes = mask.fRowBytes; |
Mike Klein | e822803 | 2017-11-14 13:41:30 -0500 | [diff] [blame] | 472 | switch (effectiveMaskFormat) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 473 | case SkMask::kA8_Format: |
Mike Klein | ec84612 | 2018-02-26 11:56:30 -0500 | [diff] [blame] | 474 | fMaskPtr.stride = rowBytes; |
Mike Klein | 804d0f2 | 2018-05-31 13:16:59 -0400 | [diff] [blame] | 475 | fMaskPtr.pixels = (void*)((uintptr_t)mask.fImage - mask.fBounds.left() * (size_t)1 |
| 476 | - mask.fBounds.top() * rowBytes); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 477 | blitter = &fBlitMaskA8; |
| 478 | break; |
| 479 | case SkMask::kLCD16_Format: |
Mike Klein | ec84612 | 2018-02-26 11:56:30 -0500 | [diff] [blame] | 480 | fMaskPtr.stride = rowBytes / 2; |
Mike Klein | 804d0f2 | 2018-05-31 13:16:59 -0400 | [diff] [blame] | 481 | fMaskPtr.pixels = (void*)((uintptr_t)mask.fImage - mask.fBounds.left() * (size_t)2 |
| 482 | - mask.fBounds.top() * rowBytes); |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 483 | blitter = &fBlitMaskLCD16; |
| 484 | break; |
| 485 | default: |
| 486 | return; |
| 487 | } |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 488 | |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 489 | SkASSERT(blitter); |
| 490 | if (fBurstCtx) { |
| 491 | // We can only burst shade one row at a time. |
| 492 | int x = clip.left(); |
| 493 | for (int y = clip.top(); y < clip.bottom(); y++) { |
| 494 | this->burst_shade(x,y,clip.width()); |
| 495 | (*blitter)(x,y, clip.width(),1); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 496 | } |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 497 | } else { |
| 498 | // If not bursting we can blit the entire mask at once. |
| 499 | (*blitter)(clip.left(),clip.top(), clip.width(),clip.height()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 500 | } |
| 501 | } |