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