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 | |
| 8 | #include "SkBlitter.h" |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 9 | #include "SkBlendModePriv.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 10 | #include "SkColor.h" |
| 11 | #include "SkColorFilter.h" |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 12 | #include "SkFixedAlloc.h" |
Mike Klein | baaf8ad | 2016-09-29 09:04:15 -0400 | [diff] [blame] | 13 | #include "SkOpts.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 14 | #include "SkPM4f.h" |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 15 | #include "SkPM4fPriv.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 16 | #include "SkRasterPipeline.h" |
| 17 | #include "SkShader.h" |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 18 | #include "SkXfermode.h" |
| 19 | |
| 20 | |
| 21 | class SkRasterPipelineBlitter : public SkBlitter { |
| 22 | public: |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame^] | 23 | static SkBlitter* Create(const SkPixmap&, const SkPaint&, const SkMatrix& ctm, |
| 24 | SkTBlitterAllocator*); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 25 | |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 26 | SkRasterPipelineBlitter(SkPixmap dst, SkBlendMode blend, SkPM4f paintColor) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 27 | : fDst(dst) |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 28 | , fBlend(blend) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 29 | , fPaintColor(paintColor) |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 30 | , fScratchAlloc(fScratch, sizeof(fScratch)) |
| 31 | , fScratchFallback(&fScratchAlloc) |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 32 | {} |
| 33 | |
| 34 | void blitH (int x, int y, int w) override; |
| 35 | void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override; |
| 36 | void blitMask (const SkMask&, const SkIRect& clip) override; |
| 37 | |
| 38 | // TODO: The default implementations of the other blits look fine, |
| 39 | // but some of them like blitV could probably benefit from custom |
| 40 | // blits using something like a SkRasterPipeline::runFew() method. |
| 41 | |
| 42 | private: |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 43 | void append_load_d(SkRasterPipeline*) const; |
| 44 | void append_store (SkRasterPipeline*) const; |
| 45 | void append_blend (SkRasterPipeline*) const; |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 46 | void maybe_clamp (SkRasterPipeline*) const; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 47 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 48 | SkPixmap fDst; |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 49 | SkBlendMode fBlend; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 50 | SkPM4f fPaintColor; |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 51 | SkRasterPipeline fShader; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 52 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 53 | // These functions are compiled lazily when first used. |
Mike Klein | af49b19 | 2016-11-15 08:52:04 -0500 | [diff] [blame] | 54 | std::function<void(size_t, size_t, size_t)> fBlitH = nullptr, |
| 55 | fBlitAntiH = nullptr, |
| 56 | fBlitMaskA8 = nullptr, |
| 57 | fBlitMaskLCD16 = nullptr; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 58 | |
| 59 | // These values are pointed to by the compiled blit functions |
| 60 | // above, which allows us to adjust them from call to call. |
| 61 | void* fDstPtr = nullptr; |
| 62 | const void* fMaskPtr = nullptr; |
| 63 | float fConstantCoverage = 0.0f; |
| 64 | |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 65 | // Scratch space for shaders and color filters to use. |
| 66 | char fScratch[64]; |
| 67 | SkFixedAlloc fScratchAlloc; |
| 68 | SkFallbackAlloc fScratchFallback; |
| 69 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 70 | typedef SkBlitter INHERITED; |
| 71 | }; |
| 72 | |
| 73 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap& dst, |
| 74 | const SkPaint& paint, |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame^] | 75 | const SkMatrix& ctm, |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 76 | SkTBlitterAllocator* alloc) { |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame^] | 77 | return SkRasterPipelineBlitter::Create(dst, paint, ctm, alloc); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 78 | } |
| 79 | |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 80 | static bool supported(const SkImageInfo& info) { |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 81 | switch (info.colorType()) { |
mtklein | 4e90e3e | 2016-07-25 14:35:31 -0700 | [diff] [blame] | 82 | case kN32_SkColorType: return info.gammaCloseToSRGB(); |
| 83 | case kRGBA_F16_SkColorType: return true; |
| 84 | case kRGB_565_SkColorType: return true; |
| 85 | default: return false; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 88 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 89 | SkBlitter* SkRasterPipelineBlitter::Create(const SkPixmap& dst, |
| 90 | const SkPaint& paint, |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame^] | 91 | const SkMatrix& ctm, |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 92 | SkTBlitterAllocator* alloc) { |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 93 | auto blitter = alloc->createT<SkRasterPipelineBlitter>( |
| 94 | dst, |
| 95 | paint.getBlendMode(), |
| 96 | SkPM4f_from_SkColor(paint.getColor(), dst.colorSpace())); |
| 97 | |
Mike Klein | f98b730 | 2016-11-06 10:18:06 -0500 | [diff] [blame] | 98 | auto earlyOut = [&] { |
herb | bf6d80a | 2016-11-15 06:26:56 -0800 | [diff] [blame] | 99 | alloc->deleteLast(); |
Mike Klein | f98b730 | 2016-11-06 10:18:06 -0500 | [diff] [blame] | 100 | return nullptr; |
| 101 | }; |
| 102 | |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 103 | SkBlendMode* blend = &blitter->fBlend; |
| 104 | SkPM4f* paintColor = &blitter->fPaintColor; |
| 105 | SkRasterPipeline* pipeline = &blitter->fShader; |
| 106 | |
| 107 | SkShader* shader = paint.getShader(); |
| 108 | SkColorFilter* colorFilter = paint.getColorFilter(); |
| 109 | |
| 110 | // TODO: all temporary |
Mike Klein | b0d10e0 | 2016-11-12 10:29:26 -0500 | [diff] [blame] | 111 | if (!supported(dst.info()) || !SkBlendMode_AppendStages(*blend)) { |
Mike Klein | f98b730 | 2016-11-06 10:18:06 -0500 | [diff] [blame] | 112 | return earlyOut(); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 113 | } |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 114 | |
Mike Klein | b0d10e0 | 2016-11-12 10:29:26 -0500 | [diff] [blame] | 115 | bool is_opaque = paintColor->a() == 1.0f, |
| 116 | is_constant = true; |
| 117 | pipeline->append(SkRasterPipeline::constant_color, paintColor); |
| 118 | |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 119 | if (shader) { |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame^] | 120 | // Shaders start with the paint color in (r,g,b,a) and dst-space (x,y) in (dr,dg). |
| 121 | // Before the shader runs, move the paint color to (dr,dg,db,da), and put (x,y) in (r,g). |
| 122 | pipeline->append(SkRasterPipeline::swap_src_dst); |
| 123 | if (!shader->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback, ctm)) { |
Mike Klein | b0d10e0 | 2016-11-12 10:29:26 -0500 | [diff] [blame] | 124 | return earlyOut(); |
| 125 | } |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame^] | 126 | // srcin, s' = s * da, i.e. modulate the output of the shader by the paint alpha. |
| 127 | pipeline->append(SkRasterPipeline::srcin); |
| 128 | |
| 129 | is_opaque = is_opaque && shader->isOpaque(); |
| 130 | is_constant = shader->isConstant(); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 131 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 132 | |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 133 | if (colorFilter) { |
Mike Klein | 744908e | 2016-11-11 12:51:36 -0500 | [diff] [blame] | 134 | if (!colorFilter->appendStages(pipeline, dst.colorSpace(), &blitter->fScratchFallback, |
| 135 | is_opaque)) { |
Mike Klein | f98b730 | 2016-11-06 10:18:06 -0500 | [diff] [blame] | 136 | return earlyOut(); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 137 | } |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 138 | is_opaque = is_opaque && (colorFilter->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 139 | } |
| 140 | |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 141 | if (is_constant) { |
| 142 | pipeline->append(SkRasterPipeline::store_f32, &paintColor); |
Mike Klein | af49b19 | 2016-11-15 08:52:04 -0500 | [diff] [blame] | 143 | pipeline->compile()(0,0, 1); |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 144 | |
| 145 | *pipeline = SkRasterPipeline(); |
| 146 | pipeline->append(SkRasterPipeline::constant_color, paintColor); |
| 147 | |
| 148 | is_opaque = paintColor->a() == 1.0f; |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 149 | } |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 150 | |
mtklein | a4a4488 | 2016-11-04 13:20:07 -0700 | [diff] [blame] | 151 | if (is_opaque && *blend == SkBlendMode::kSrcOver) { |
| 152 | *blend = SkBlendMode::kSrc; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 153 | } |
| 154 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 155 | return blitter; |
| 156 | } |
| 157 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 158 | void SkRasterPipelineBlitter::append_load_d(SkRasterPipeline* p) const { |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 159 | SkASSERT(supported(fDst.info())); |
| 160 | |
| 161 | switch (fDst.info().colorType()) { |
| 162 | case kN32_SkColorType: |
| 163 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 164 | p->append(SkRasterPipeline::load_d_srgb, &fDstPtr); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 165 | } |
| 166 | break; |
mtklein | 4e90e3e | 2016-07-25 14:35:31 -0700 | [diff] [blame] | 167 | case kRGBA_F16_SkColorType: |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 168 | p->append(SkRasterPipeline::load_d_f16, &fDstPtr); |
mtklein | 4e90e3e | 2016-07-25 14:35:31 -0700 | [diff] [blame] | 169 | break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 170 | case kRGB_565_SkColorType: |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 171 | p->append(SkRasterPipeline::load_d_565, &fDstPtr); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 172 | break; |
| 173 | default: break; |
| 174 | } |
| 175 | } |
| 176 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 177 | void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p) const { |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 178 | SkASSERT(supported(fDst.info())); |
| 179 | |
| 180 | switch (fDst.info().colorType()) { |
| 181 | case kN32_SkColorType: |
| 182 | if (fDst.info().gammaCloseToSRGB()) { |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 183 | p->append(SkRasterPipeline::store_srgb, &fDstPtr); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 184 | } |
| 185 | break; |
mtklein | 4e90e3e | 2016-07-25 14:35:31 -0700 | [diff] [blame] | 186 | case kRGBA_F16_SkColorType: |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 187 | p->append(SkRasterPipeline::store_f16, &fDstPtr); |
mtklein | 4e90e3e | 2016-07-25 14:35:31 -0700 | [diff] [blame] | 188 | break; |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 189 | case kRGB_565_SkColorType: |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 190 | p->append(SkRasterPipeline::store_565, &fDstPtr); |
mtklein | 8e4373f | 2016-07-22 14:20:27 -0700 | [diff] [blame] | 191 | break; |
| 192 | default: break; |
| 193 | } |
| 194 | } |
| 195 | |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 196 | void SkRasterPipelineBlitter::append_blend(SkRasterPipeline* p) const { |
| 197 | SkAssertResult(SkBlendMode_AppendStages(fBlend, p)); |
| 198 | } |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 199 | |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 200 | void SkRasterPipelineBlitter::maybe_clamp(SkRasterPipeline* p) const { |
Mike Klein | eea7c16 | 2016-11-03 10:20:35 -0400 | [diff] [blame] | 201 | if (SkBlendMode_CanOverflow(fBlend)) { p->append(SkRasterPipeline::clamp_a); } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 202 | } |
| 203 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 204 | void SkRasterPipelineBlitter::blitH(int x, int y, int w) { |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 205 | if (!fBlitH) { |
| 206 | SkRasterPipeline p; |
| 207 | p.extend(fShader); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 208 | if (fBlend != SkBlendMode::kSrc) { |
| 209 | this->append_load_d(&p); |
| 210 | this->append_blend(&p); |
| 211 | this->maybe_clamp(&p); |
| 212 | } |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 213 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 214 | fBlitH = p.compile(); |
| 215 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 216 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 217 | fDstPtr = fDst.writable_addr(0,y); |
Mike Klein | af49b19 | 2016-11-15 08:52:04 -0500 | [diff] [blame] | 218 | fBlitH(x,y, w); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void SkRasterPipelineBlitter::blitAntiH(int x, int y, const SkAlpha aa[], const int16_t runs[]) { |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 222 | if (!fBlitAntiH) { |
| 223 | SkRasterPipeline p; |
| 224 | p.extend(fShader); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 225 | if (fBlend == SkBlendMode::kSrcOver) { |
| 226 | p.append(SkRasterPipeline::scale_constant_float, &fConstantCoverage); |
| 227 | this->append_load_d(&p); |
| 228 | this->append_blend(&p); |
| 229 | } else { |
| 230 | this->append_load_d(&p); |
| 231 | this->append_blend(&p); |
| 232 | p.append(SkRasterPipeline::lerp_constant_float, &fConstantCoverage); |
| 233 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 234 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 235 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 236 | fBlitAntiH = p.compile(); |
| 237 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 238 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 239 | fDstPtr = fDst.writable_addr(0,y); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 240 | for (int16_t run = *runs; run > 0; run = *runs) { |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 241 | switch (*aa) { |
| 242 | case 0x00: break; |
| 243 | case 0xff: this->blitH(x,y,run); break; |
| 244 | default: |
| 245 | fConstantCoverage = *aa * (1/255.0f); |
Mike Klein | af49b19 | 2016-11-15 08:52:04 -0500 | [diff] [blame] | 246 | fBlitAntiH(x,y, run); |
Mike Klein | aeb7959 | 2016-11-07 09:29:07 -0500 | [diff] [blame] | 247 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 248 | x += run; |
| 249 | runs += run; |
| 250 | aa += run; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void SkRasterPipelineBlitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 255 | if (mask.fFormat == SkMask::kBW_Format) { |
| 256 | // TODO: native BW masks? |
| 257 | return INHERITED::blitMask(mask, clip); |
| 258 | } |
| 259 | |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 260 | if (mask.fFormat == SkMask::kA8_Format && !fBlitMaskA8) { |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 261 | SkRasterPipeline p; |
| 262 | p.extend(fShader); |
Mike Klein | 6686617 | 2016-11-03 12:22:01 -0400 | [diff] [blame] | 263 | if (fBlend == SkBlendMode::kSrcOver) { |
| 264 | p.append(SkRasterPipeline::scale_u8, &fMaskPtr); |
| 265 | this->append_load_d(&p); |
| 266 | this->append_blend(&p); |
| 267 | } else { |
| 268 | this->append_load_d(&p); |
| 269 | this->append_blend(&p); |
| 270 | p.append(SkRasterPipeline::lerp_u8, &fMaskPtr); |
| 271 | } |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 272 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 273 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 274 | fBlitMaskA8 = p.compile(); |
| 275 | } |
| 276 | |
| 277 | if (mask.fFormat == SkMask::kLCD16_Format && !fBlitMaskLCD16) { |
| 278 | SkRasterPipeline p; |
| 279 | p.extend(fShader); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 280 | this->append_load_d(&p); |
| 281 | this->append_blend(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 282 | p.append(SkRasterPipeline::lerp_565, &fMaskPtr); |
Mike Klein | 130863e | 2016-10-27 11:29:36 -0400 | [diff] [blame] | 283 | this->maybe_clamp(&p); |
Mike Klein | e902f8d | 2016-10-26 15:32:26 -0400 | [diff] [blame] | 284 | this->append_store(&p); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 285 | fBlitMaskLCD16 = p.compile(); |
| 286 | } |
| 287 | |
| 288 | int x = clip.left(); |
| 289 | for (int y = clip.top(); y < clip.bottom(); y++) { |
| 290 | fDstPtr = fDst.writable_addr(0,y); |
| 291 | |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 292 | switch (mask.fFormat) { |
| 293 | case SkMask::kA8_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 294 | fMaskPtr = mask.getAddr8(x,y)-x; |
Mike Klein | af49b19 | 2016-11-15 08:52:04 -0500 | [diff] [blame] | 295 | fBlitMaskA8(x,y, clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 296 | break; |
| 297 | case SkMask::kLCD16_Format: |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 298 | fMaskPtr = mask.getAddrLCD16(x,y)-x; |
Mike Klein | af49b19 | 2016-11-15 08:52:04 -0500 | [diff] [blame] | 299 | fBlitMaskLCD16(x,y, clip.width()); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 300 | break; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 301 | default: |
| 302 | // TODO |
| 303 | break; |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 304 | } |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 305 | } |
| 306 | } |