| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifdef THORVG_NEON_VECTOR_SUPPORT |
| 24 |
|
| 25 |
#include <arm_neon.h> |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#if defined(__ARM_64BIT_STATE) || defined(_M_ARM64) |
| 30 |
#define TVG_AARCH64 1 |
| 31 |
#else |
| 32 |
#define TVG_AARCH64 0 |
| 33 |
#endif |
| 34 |
|
| 35 |
|
| 36 |
static inline uint8x8_t ALPHA_BLEND(uint8x8_t c, uint8x8_t a) |
| 37 |
{ |
| 38 |
uint16x8_t t = vmull_u8(c, a); |
| 39 |
return vshrn_n_u16(t, 8); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
static void neonRasterGrayscale8(uint8_t* dst, uint8_t val, uint32_t offset, int32_t len) |
| 44 |
{ |
| 45 |
dst += offset; |
| 46 |
|
| 47 |
int32_t i = 0; |
| 48 |
const uint8x16_t valVec = vdupq_n_u8(val); |
| 49 |
#if TVG_AARCH64 |
| 50 |
uint8x16x4_t valQuad = {valVec, valVec, valVec, valVec}; |
| 51 |
for (; i <= len - 16 * 4; i += 16 * 4) { |
| 52 |
vst1q_u8_x4(dst + i, valQuad); |
| 53 |
} |
| 54 |
#else |
| 55 |
for (; i <= len - 16; i += 16) { |
| 56 |
vst1q_u8(dst + i, valVec); |
| 57 |
} |
| 58 |
#endif |
| 59 |
for (; i < len; i++) { |
| 60 |
dst[i] = val; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
static void neonRasterPixel32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len) |
| 66 |
{ |
| 67 |
dst += offset; |
| 68 |
|
| 69 |
uint32x4_t vectorVal = vdupq_n_u32(val); |
| 70 |
|
| 71 |
#if TVG_AARCH64 |
| 72 |
uint32_t iterations = len / 16; |
| 73 |
uint32_t neonFilled = iterations * 16; |
| 74 |
uint32x4x4_t valQuad = {vectorVal, vectorVal, vectorVal, vectorVal}; |
| 75 |
for (uint32_t i = 0; i < iterations; ++i) { |
| 76 |
vst4q_u32(dst, valQuad); |
| 77 |
dst += 16; |
| 78 |
} |
| 79 |
#else |
| 80 |
uint32_t iterations = len / 4; |
| 81 |
uint32_t neonFilled = iterations * 4; |
| 82 |
for (uint32_t i = 0; i < iterations; ++i) { |
| 83 |
vst1q_u32(dst, vectorVal); |
| 84 |
dst += 4; |
| 85 |
} |
| 86 |
#endif |
| 87 |
int32_t leftovers = len - neonFilled; |
| 88 |
while (leftovers--) *dst++ = val; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
static bool neonRasterTranslucentRle(SwSurface* surface, const SwRle* rle, uint8_t r, uint8_t g, uint8_t b, uint8_t a) |
| 93 |
{ |
| 94 |
auto span = rle->spans; |
| 95 |
|
| 96 |
|
| 97 |
if (surface->channelSize == sizeof(uint32_t)) { |
| 98 |
auto color = surface->join(r, g, b, a); |
| 99 |
uint32_t src; |
| 100 |
uint8x8_t *vDst = nullptr; |
| 101 |
uint16_t align; |
| 102 |
|
| 103 |
for (uint32_t i = 0; i < rle->size; ++i) { |
| 104 |
if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage); |
| 105 |
else src = color; |
| 106 |
|
| 107 |
auto dst = &surface->buf32[span->y * surface->stride + span->x]; |
| 108 |
auto ialpha = IA(src); |
| 109 |
|
| 110 |
if ((((uintptr_t) dst) & 0x7) != 0) { |
| 111 |
|
| 112 |
*dst = src + ALPHA_BLEND(*dst, ialpha); |
| 113 |
vDst = (uint8x8_t*)(dst + 1); |
| 114 |
align = 1; |
| 115 |
} else { |
| 116 |
vDst = (uint8x8_t*) dst; |
| 117 |
align = 0; |
| 118 |
} |
| 119 |
|
| 120 |
uint8x8_t vSrc = (uint8x8_t) vdup_n_u32(src); |
| 121 |
uint8x8_t vIalpha = vdup_n_u8((uint8_t) ialpha); |
| 122 |
|
| 123 |
for (uint32_t x = 0; x < (span->len - align) / 2; ++x) |
| 124 |
vDst[x] = vadd_u8(vSrc, ALPHA_BLEND(vDst[x], vIalpha)); |
| 125 |
|
| 126 |
auto leftovers = (span->len - align) % 2; |
| 127 |
if (leftovers > 0) dst[span->len - 1] = src + ALPHA_BLEND(dst[span->len - 1], ialpha); |
| 128 |
|
| 129 |
++span; |
| 130 |
} |
| 131 |
|
| 132 |
} else if (surface->channelSize == sizeof(uint8_t)) { |
| 133 |
TVGLOG("SW_ENGINE", "Require Neon Optimization, Channel Size = %d", surface->channelSize); |
| 134 |
uint8_t src; |
| 135 |
for (uint32_t i = 0; i < rle->size; ++i, ++span) { |
| 136 |
auto dst = &surface->buf8[span->y * surface->stride + span->x]; |
| 137 |
if (span->coverage < 255) src = MULTIPLY(span->coverage, a); |
| 138 |
else src = a; |
| 139 |
auto ialpha = ~a; |
| 140 |
for (uint32_t x = 0; x < span->len; ++x, ++dst) { |
| 141 |
*dst = src + MULTIPLY(*dst, ialpha); |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
return true; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
static bool neonRasterTranslucentRect(SwSurface* surface, const SwBBox& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) |
| 150 |
{ |
| 151 |
auto h = static_cast<uint32_t>(region.max.y - region.min.y); |
| 152 |
auto w = static_cast<uint32_t>(region.max.x - region.min.x); |
| 153 |
|
| 154 |
|
| 155 |
if (surface->channelSize == sizeof(uint32_t)) { |
| 156 |
auto color = surface->join(r, g, b, a); |
| 157 |
auto buffer = surface->buf32 + (region.min.y * surface->stride) + region.min.x; |
| 158 |
auto ialpha = 255 - a; |
| 159 |
|
| 160 |
auto vColor = vdup_n_u32(color); |
| 161 |
auto vIalpha = vdup_n_u8((uint8_t) ialpha); |
| 162 |
|
| 163 |
uint8x8_t* vDst = nullptr; |
| 164 |
uint32_t align; |
| 165 |
|
| 166 |
for (uint32_t y = 0; y < h; ++y) { |
| 167 |
auto dst = &buffer[y * surface->stride]; |
| 168 |
|
| 169 |
if ((((uintptr_t) dst) & 0x7) != 0) { |
| 170 |
|
| 171 |
*dst = color + ALPHA_BLEND(*dst, ialpha); |
| 172 |
vDst = (uint8x8_t*) (dst + 1); |
| 173 |
align = 1; |
| 174 |
} else { |
| 175 |
vDst = (uint8x8_t*) dst; |
| 176 |
align = 0; |
| 177 |
} |
| 178 |
|
| 179 |
for (uint32_t x = 0; x < (w - align) / 2; ++x) |
| 180 |
vDst[x] = vadd_u8((uint8x8_t)vColor, ALPHA_BLEND(vDst[x], vIalpha)); |
| 181 |
|
| 182 |
auto leftovers = (w - align) % 2; |
| 183 |
if (leftovers > 0) dst[w - 1] = color + ALPHA_BLEND(dst[w - 1], ialpha); |
| 184 |
} |
| 185 |
|
| 186 |
} else if (surface->channelSize == sizeof(uint8_t)) { |
| 187 |
TVGLOG("SW_ENGINE", "Require Neon Optimization, Channel Size = %d", surface->channelSize); |
| 188 |
auto buffer = surface->buf8 + (region.min.y * surface->stride) + region.min.x; |
| 189 |
auto ialpha = ~a; |
| 190 |
for (uint32_t y = 0; y < h; ++y) { |
| 191 |
auto dst = &buffer[y * surface->stride]; |
| 192 |
for (uint32_t x = 0; x < w; ++x, ++dst) { |
| 193 |
*dst = a + MULTIPLY(*dst, ialpha); |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
return true; |
| 198 |
} |
| 199 |
|
| 200 |
#endif |