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