epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2006 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #include "SkCoreBlitters.h" |
| 11 | #include "SkColorPriv.h" |
| 12 | #include "SkShader.h" |
| 13 | #include "SkXfermode.h" |
| 14 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 15 | SkA8_Blitter::SkA8_Blitter(const SkPixmap& device, const SkPaint& paint) : INHERITED(device) { |
mike@reedtribe.org | eadc807 | 2011-04-09 19:28:43 +0000 | [diff] [blame] | 16 | fSrcA = paint.getAlpha(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 17 | } |
| 18 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 19 | const SkPixmap* SkA8_Blitter::justAnOpaqueColor(uint32_t* value) { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 20 | if (255 == fSrcA) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | *value = 255; |
| 22 | return &fDevice; |
| 23 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 24 | return nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | } |
| 26 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 27 | void SkA8_Blitter::blitH(int x, int y, int width) { |
| 28 | SkASSERT(x >= 0 && y >= 0 && |
| 29 | (unsigned)(x + width) <= (unsigned)fDevice.width()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 31 | if (fSrcA == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 33 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 35 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 37 | if (fSrcA == 255) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | memset(device, 0xFF, width); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 39 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | unsigned scale = 256 - SkAlpha255To256(fSrcA); |
| 41 | unsigned srcA = fSrcA; |
| 42 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 43 | for (int i = 0; i < width; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 49 | void SkA8_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 50 | const int16_t runs[]) { |
| 51 | if (fSrcA == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 53 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 55 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | unsigned srcA = fSrcA; |
| 57 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 58 | for (;;) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | int count = runs[0]; |
| 60 | SkASSERT(count >= 0); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 61 | if (count == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 63 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | unsigned aa = antialias[0]; |
| 65 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 66 | if (aa == 255 && srcA == 255) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | memset(device, 0xFF, count); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 68 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | unsigned sa = SkAlphaMul(srcA, SkAlpha255To256(aa)); |
| 70 | unsigned scale = 256 - sa; |
| 71 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 72 | for (int i = 0; i < count; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | device[i] = SkToU8(sa + SkAlphaMul(device[i], scale)); |
| 74 | } |
| 75 | } |
| 76 | runs += count; |
| 77 | antialias += count; |
| 78 | device += count; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | ///////////////////////////////////////////////////////////////////////////////////// |
| 83 | |
| 84 | #define solid_8_pixels(mask, dst) \ |
| 85 | do { \ |
| 86 | if (mask & 0x80) dst[0] = 0xFF; \ |
| 87 | if (mask & 0x40) dst[1] = 0xFF; \ |
| 88 | if (mask & 0x20) dst[2] = 0xFF; \ |
| 89 | if (mask & 0x10) dst[3] = 0xFF; \ |
| 90 | if (mask & 0x08) dst[4] = 0xFF; \ |
| 91 | if (mask & 0x04) dst[5] = 0xFF; \ |
| 92 | if (mask & 0x02) dst[6] = 0xFF; \ |
| 93 | if (mask & 0x01) dst[7] = 0xFF; \ |
| 94 | } while (0) |
| 95 | |
| 96 | #define SK_BLITBWMASK_NAME SkA8_BlitBW |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 97 | #define SK_BLITBWMASK_ARGS |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | #define SK_BLITBWMASK_BLIT8(mask, dst) solid_8_pixels(mask, dst) |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 99 | #define SK_BLITBWMASK_GETADDR writable_addr8 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 100 | #define SK_BLITBWMASK_DEVTYPE uint8_t |
| 101 | #include "SkBlitBWMaskTemplate.h" |
| 102 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 103 | static inline void blend_8_pixels(U8CPU bw, uint8_t dst[], U8CPU sa, |
| 104 | unsigned dst_scale) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | if (bw & 0x80) dst[0] = SkToU8(sa + SkAlphaMul(dst[0], dst_scale)); |
| 106 | if (bw & 0x40) dst[1] = SkToU8(sa + SkAlphaMul(dst[1], dst_scale)); |
| 107 | if (bw & 0x20) dst[2] = SkToU8(sa + SkAlphaMul(dst[2], dst_scale)); |
| 108 | if (bw & 0x10) dst[3] = SkToU8(sa + SkAlphaMul(dst[3], dst_scale)); |
| 109 | if (bw & 0x08) dst[4] = SkToU8(sa + SkAlphaMul(dst[4], dst_scale)); |
| 110 | if (bw & 0x04) dst[5] = SkToU8(sa + SkAlphaMul(dst[5], dst_scale)); |
| 111 | if (bw & 0x02) dst[6] = SkToU8(sa + SkAlphaMul(dst[6], dst_scale)); |
| 112 | if (bw & 0x01) dst[7] = SkToU8(sa + SkAlphaMul(dst[7], dst_scale)); |
| 113 | } |
| 114 | |
| 115 | #define SK_BLITBWMASK_NAME SkA8_BlendBW |
| 116 | #define SK_BLITBWMASK_ARGS , U8CPU sa, unsigned dst_scale |
| 117 | #define SK_BLITBWMASK_BLIT8(mask, dst) blend_8_pixels(mask, dst, sa, dst_scale) |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 118 | #define SK_BLITBWMASK_GETADDR writable_addr8 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 119 | #define SK_BLITBWMASK_DEVTYPE uint8_t |
| 120 | #include "SkBlitBWMaskTemplate.h" |
| 121 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 122 | void SkA8_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 123 | if (fSrcA == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 124 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 125 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 126 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 127 | if (mask.fFormat == SkMask::kBW_Format) { |
| 128 | if (fSrcA == 0xFF) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 129 | SkA8_BlitBW(fDevice, mask, clip); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 130 | } else { |
| 131 | SkA8_BlendBW(fDevice, mask, clip, fSrcA, |
| 132 | SkAlpha255To256(255 - fSrcA)); |
| 133 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
| 137 | int x = clip.fLeft; |
| 138 | int y = clip.fTop; |
| 139 | int width = clip.width(); |
| 140 | int height = clip.height(); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 141 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@google.com | 7989186 | 2011-10-18 15:44:57 +0000 | [diff] [blame] | 142 | const uint8_t* alpha = mask.getAddr8(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | unsigned srcA = fSrcA; |
| 144 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 145 | while (--height >= 0) { |
| 146 | for (int i = width - 1; i >= 0; --i) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 147 | unsigned sa; |
| 148 | // scale our src by the alpha value |
| 149 | { |
| 150 | int aa = alpha[i]; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 151 | if (aa == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | continue; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 153 | } |
| 154 | if (aa == 255) { |
| 155 | if (srcA == 255) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 156 | device[i] = 0xFF; |
| 157 | continue; |
| 158 | } |
| 159 | sa = srcA; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 160 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 161 | sa = SkAlphaMul(srcA, SkAlpha255To256(aa)); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 162 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | int scale = 256 - SkAlpha255To256(sa); |
| 166 | device[i] = SkToU8(sa + SkAlphaMul(device[i], scale)); |
| 167 | } |
| 168 | device += fDevice.rowBytes(); |
| 169 | alpha += mask.fRowBytes; |
| 170 | } |
| 171 | } |
| 172 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 173 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 174 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 175 | void SkA8_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { |
| 176 | if (fSrcA == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 177 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 178 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 179 | |
| 180 | unsigned sa = SkAlphaMul(fSrcA, SkAlpha255To256(alpha)); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 181 | uint8_t* device = fDevice.writable_addr8(x, y); |
scroggo@google.com | e5f4824 | 2013-02-25 21:47:41 +0000 | [diff] [blame] | 182 | size_t rowBytes = fDevice.rowBytes(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 183 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 184 | if (sa == 0xFF) { |
| 185 | for (int i = 0; i < height; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | *device = SkToU8(sa); |
| 187 | device += rowBytes; |
| 188 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 189 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 190 | unsigned scale = 256 - SkAlpha255To256(sa); |
| 191 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 192 | for (int i = 0; i < height; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 193 | *device = SkToU8(sa + SkAlphaMul(*device, scale)); |
| 194 | device += rowBytes; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 199 | void SkA8_Blitter::blitRect(int x, int y, int width, int height) { |
| 200 | SkASSERT(x >= 0 && y >= 0 && |
| 201 | (unsigned)(x + width) <= (unsigned)fDevice.width() && |
| 202 | (unsigned)(y + height) <= (unsigned)fDevice.height()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 203 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 204 | if (fSrcA == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 205 | return; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 206 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 207 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 208 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 209 | unsigned srcA = fSrcA; |
| 210 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 211 | if (srcA == 255) { |
| 212 | while (--height >= 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 213 | memset(device, 0xFF, width); |
| 214 | device += fDevice.rowBytes(); |
| 215 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 216 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 217 | unsigned scale = 256 - SkAlpha255To256(srcA); |
| 218 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 219 | while (--height >= 0) { |
| 220 | for (int i = 0; i < width; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 221 | device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); |
| 222 | } |
| 223 | device += fDevice.rowBytes(); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /////////////////////////////////////////////////////////////////////// |
| 229 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 230 | SkA8_Shader_Blitter::SkA8_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 231 | SkShader::Context* shaderContext) |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 232 | : INHERITED(device, paint, shaderContext) |
| 233 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 234 | if ((fXfermode = paint.getXfermode()) != nullptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 235 | fXfermode->ref(); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 236 | SkASSERT(fShaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | int width = device.width(); |
| 240 | fBuffer = (SkPMColor*)sk_malloc_throw(sizeof(SkPMColor) * (width + (SkAlign4(width) >> 2))); |
| 241 | fAAExpand = (uint8_t*)(fBuffer + width); |
| 242 | } |
| 243 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 244 | SkA8_Shader_Blitter::~SkA8_Shader_Blitter() { |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 245 | if (fXfermode) SkSafeUnref(fXfermode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 246 | sk_free(fBuffer); |
| 247 | } |
| 248 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 249 | void SkA8_Shader_Blitter::blitH(int x, int y, int width) { |
| 250 | SkASSERT(x >= 0 && y >= 0 && |
| 251 | (unsigned)(x + width) <= (unsigned)fDevice.width()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 252 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 253 | uint8_t* device = fDevice.writable_addr8(x, y); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 254 | SkShader::Context* shaderContext = fShaderContext; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 255 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 256 | if ((shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag) && !fXfermode) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 257 | memset(device, 0xFF, width); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 258 | } else { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 259 | SkPMColor* span = fBuffer; |
| 260 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 261 | shaderContext->shadeSpan(x, y, span, width); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 262 | if (fXfermode) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 263 | fXfermode->xferA8(device, span, width, nullptr); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 264 | } else { |
| 265 | for (int i = width - 1; i >= 0; --i) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 266 | unsigned srcA = SkGetPackedA32(span[i]); |
| 267 | unsigned scale = 256 - SkAlpha255To256(srcA); |
| 268 | |
| 269 | device[i] = SkToU8(srcA + SkAlphaMul(device[i], scale)); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 275 | static inline uint8_t aa_blend8(SkPMColor src, U8CPU da, int aa) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 276 | SkASSERT((unsigned)aa <= 255); |
| 277 | |
| 278 | int src_scale = SkAlpha255To256(aa); |
| 279 | int sa = SkGetPackedA32(src); |
| 280 | int dst_scale = 256 - SkAlphaMul(sa, src_scale); |
| 281 | |
| 282 | return SkToU8((sa * src_scale + da * dst_scale) >> 8); |
| 283 | } |
| 284 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 285 | void SkA8_Shader_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 286 | const int16_t runs[]) { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 287 | SkShader::Context* shaderContext = fShaderContext; |
| 288 | SkXfermode* mode = fXfermode; |
| 289 | uint8_t* aaExpand = fAAExpand; |
| 290 | SkPMColor* span = fBuffer; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 291 | uint8_t* device = fDevice.writable_addr8(x, y); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 292 | int opaque = shaderContext->getFlags() & SkShader::kOpaqueAlpha_Flag; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 293 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 294 | for (;;) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 295 | int count = *runs; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 296 | if (count == 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 297 | break; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 298 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 299 | int aa = *antialias; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 300 | if (aa) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 301 | if (opaque && aa == 255 && mode == nullptr) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 302 | memset(device, 0xFF, count); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 303 | } else { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 304 | shaderContext->shadeSpan(x, y, span, count); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 305 | if (mode) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 306 | memset(aaExpand, aa, count); |
| 307 | mode->xferA8(device, span, count, aaExpand); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 308 | } else { |
| 309 | for (int i = count - 1; i >= 0; --i) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 310 | device[i] = aa_blend8(span[i], device[i], aa); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 311 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | } |
| 315 | device += count; |
| 316 | runs += count; |
| 317 | antialias += count; |
| 318 | x += count; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 319 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 320 | } |
| 321 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 322 | void SkA8_Shader_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 323 | if (mask.fFormat == SkMask::kBW_Format) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 324 | this->INHERITED::blitMask(mask, clip); |
| 325 | return; |
| 326 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 327 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 328 | int x = clip.fLeft; |
| 329 | int y = clip.fTop; |
| 330 | int width = clip.width(); |
| 331 | int height = clip.height(); |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 332 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@google.com | 7989186 | 2011-10-18 15:44:57 +0000 | [diff] [blame] | 333 | const uint8_t* alpha = mask.getAddr8(x, y); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 334 | SkShader::Context* shaderContext = fShaderContext; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 335 | |
| 336 | SkPMColor* span = fBuffer; |
| 337 | |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 338 | while (--height >= 0) { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 339 | shaderContext->shadeSpan(x, y, span, width); |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 340 | if (fXfermode) { |
| 341 | fXfermode->xferA8(device, span, width, alpha); |
commit-bot@chromium.org | 96583db | 2013-08-15 18:16:07 +0000 | [diff] [blame] | 342 | } else { |
| 343 | for (int i = width - 1; i >= 0; --i) { |
| 344 | device[i] = aa_blend8(span[i], device[i], alpha[i]); |
| 345 | } |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 346 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 347 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 348 | y += 1; |
| 349 | device += fDevice.rowBytes(); |
| 350 | alpha += mask.fRowBytes; |
| 351 | } |
| 352 | } |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 353 | |
| 354 | /////////////////////////////////////////////////////////////////////////////// |
| 355 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 356 | SkA8_Coverage_Blitter::SkA8_Coverage_Blitter(const SkPixmap& device, |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 357 | const SkPaint& paint) : SkRasterBlitter(device) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 358 | SkASSERT(nullptr == paint.getShader()); |
| 359 | SkASSERT(nullptr == paint.getXfermode()); |
| 360 | SkASSERT(nullptr == paint.getColorFilter()); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | void SkA8_Coverage_Blitter::blitAntiH(int x, int y, const SkAlpha antialias[], |
| 364 | const int16_t runs[]) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 365 | uint8_t* device = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 366 | SkDEBUGCODE(int totalCount = 0;) |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 367 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 368 | for (;;) { |
| 369 | int count = runs[0]; |
| 370 | SkASSERT(count >= 0); |
| 371 | if (count == 0) { |
| 372 | return; |
| 373 | } |
reed@google.com | b95d9f5 | 2013-11-08 17:50:14 +0000 | [diff] [blame] | 374 | if (antialias[0]) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 375 | memset(device, antialias[0], count); |
| 376 | } |
| 377 | runs += count; |
| 378 | antialias += count; |
| 379 | device += count; |
| 380 | |
| 381 | SkDEBUGCODE(totalCount += count;) |
| 382 | } |
| 383 | SkASSERT(fDevice.width() == totalCount); |
| 384 | } |
| 385 | |
| 386 | void SkA8_Coverage_Blitter::blitH(int x, int y, int width) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 387 | memset(fDevice.writable_addr8(x, y), 0xFF, width); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | void SkA8_Coverage_Blitter::blitV(int x, int y, int height, SkAlpha alpha) { |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 391 | if (0 == alpha) { |
| 392 | return; |
| 393 | } |
reed@google.com | b95d9f5 | 2013-11-08 17:50:14 +0000 | [diff] [blame] | 394 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 395 | uint8_t* dst = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 396 | const size_t dstRB = fDevice.rowBytes(); |
| 397 | while (--height >= 0) { |
| 398 | *dst = alpha; |
| 399 | dst += dstRB; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | void SkA8_Coverage_Blitter::blitRect(int x, int y, int width, int height) { |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 404 | uint8_t* dst = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 405 | const size_t dstRB = fDevice.rowBytes(); |
| 406 | while (--height >= 0) { |
| 407 | memset(dst, 0xFF, width); |
| 408 | dst += dstRB; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | void SkA8_Coverage_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) { |
| 413 | SkASSERT(SkMask::kA8_Format == mask.fFormat); |
| 414 | |
| 415 | int x = clip.fLeft; |
| 416 | int y = clip.fTop; |
| 417 | int width = clip.width(); |
| 418 | int height = clip.height(); |
| 419 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 420 | uint8_t* dst = fDevice.writable_addr8(x, y); |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 421 | const uint8_t* src = mask.getAddr8(x, y); |
| 422 | const size_t srcRB = mask.fRowBytes; |
| 423 | const size_t dstRB = fDevice.rowBytes(); |
skia.committer@gmail.com | ab7442c | 2013-11-08 07:01:56 +0000 | [diff] [blame] | 424 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 425 | while (--height >= 0) { |
| 426 | memcpy(dst, src, width); |
| 427 | dst += dstRB; |
| 428 | src += srcRB; |
| 429 | } |
| 430 | } |
| 431 | |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 432 | const SkPixmap* SkA8_Coverage_Blitter::justAnOpaqueColor(uint32_t*) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame^] | 433 | return nullptr; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 434 | } |