OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkMorphology_opts_SSE2.h" | 10 #include "SkMorphology_opts.h" |
| 11 #include "SkMorphology_opts_neon.h" |
11 | 12 |
12 #include <emmintrin.h> | 13 #include <arm_neon.h> |
13 | 14 |
14 /* SSE2 version of dilateX, dilateY, erodeX, erodeY. | 15 /* neon version of dilateX, dilateY, erodeX, erodeY. |
15 * portable versions are in src/effects/SkMorphologyImageFilter.cpp. | 16 * portable versions are in src/effects/SkMorphologyImageFilter.cpp. |
16 */ | 17 */ |
17 | 18 |
18 enum MorphType { | 19 enum MorphType { |
19 kDilate, kErode | 20 kDilate, kErode |
20 }; | 21 }; |
21 | 22 |
22 enum MorphDirection { | 23 enum MorphDirection { |
23 kX, kY | 24 kX, kY |
24 }; | 25 }; |
25 | 26 |
26 template<MorphType type, MorphDirection direction> | 27 template<MorphType type, MorphDirection direction> |
27 static void SkMorph_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | 28 static void SkMorph_neon(const SkPMColor* src, SkPMColor* dst, int radius, |
28 int width, int height, int srcStride, int dstStride) | 29 int width, int height, int srcStride, int dstStride) |
29 { | 30 { |
30 const int srcStrideX = direction == kX ? 1 : srcStride; | 31 const int srcStrideX = direction == kX ? 1 : srcStride; |
31 const int dstStrideX = direction == kX ? 1 : dstStride; | 32 const int dstStrideX = direction == kX ? 1 : dstStride; |
32 const int srcStrideY = direction == kX ? srcStride : 1; | 33 const int srcStrideY = direction == kX ? srcStride : 1; |
33 const int dstStrideY = direction == kX ? dstStride : 1; | 34 const int dstStrideY = direction == kX ? dstStride : 1; |
34 radius = SkMin32(radius, width - 1); | 35 radius = SkMin32(radius, width - 1); |
35 const SkPMColor* upperSrc = src + radius * srcStrideX; | 36 const SkPMColor* upperSrc = src + radius * srcStrideX; |
36 for (int x = 0; x < width; ++x) { | 37 for (int x = 0; x < width; ++x) { |
37 const SkPMColor* lp = src; | 38 const SkPMColor* lp = src; |
38 const SkPMColor* up = upperSrc; | 39 const SkPMColor* up = upperSrc; |
39 SkPMColor* dptr = dst; | 40 SkPMColor* dptr = dst; |
40 for (int y = 0; y < height; ++y) { | 41 for (int y = 0; y < height; ++y) { |
41 __m128i max = type == kDilate ? _mm_setzero_si128() : _mm_set1_epi32
(0xFFFFFFFF); | 42 uint8x8_t max = vdup_n_u8(type == kDilate ? 0 : 255); |
42 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { | 43 for (const SkPMColor* p = lp; p <= up; p += srcStrideX) { |
43 __m128i src_pixel = _mm_cvtsi32_si128(*p); | 44 uint8x8_t src_pixel = vreinterpret_u8_u32(vdup_n_u32(*p)); |
44 max = type == kDilate ? _mm_max_epu8(src_pixel, max) : _mm_min_e
pu8(src_pixel, max); | 45 max = type == kDilate ? vmax_u8(src_pixel, max) : vmin_u8(src_pi
xel, max); |
45 } | 46 } |
46 *dptr = _mm_cvtsi128_si32(max); | 47 *dptr = vget_lane_u32(vreinterpret_u32_u8(max), 0); |
47 dptr += dstStrideY; | 48 dptr += dstStrideY; |
48 lp += srcStrideY; | 49 lp += srcStrideY; |
49 up += srcStrideY; | 50 up += srcStrideY; |
50 } | 51 } |
51 if (x >= radius) src += srcStrideX; | 52 if (x >= radius) src += srcStrideX; |
52 if (x + radius < width - 1) upperSrc += srcStrideX; | 53 if (x + radius < width - 1) upperSrc += srcStrideX; |
53 dst += dstStrideX; | 54 dst += dstStrideX; |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 void SkDilateX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | 58 void SkDilateX_neon(const SkPMColor* src, SkPMColor* dst, int radius, |
58 int width, int height, int srcStride, int dstStride) | 59 int width, int height, int srcStride, int dstStride) |
59 { | 60 { |
60 SkMorph_SSE2<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStr
ide); | 61 SkMorph_neon<kDilate, kX>(src, dst, radius, width, height, srcStride, dstStr
ide); |
61 } | 62 } |
62 | 63 |
63 void SkErodeX_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | 64 void SkErodeX_neon(const SkPMColor* src, SkPMColor* dst, int radius, |
64 int width, int height, int srcStride, int dstStride) | 65 int width, int height, int srcStride, int dstStride) |
65 { | 66 { |
66 SkMorph_SSE2<kErode, kX>(src, dst, radius, width, height, srcStride, dstStri
de); | 67 SkMorph_neon<kErode, kX>(src, dst, radius, width, height, srcStride, dstStri
de); |
67 } | 68 } |
68 | 69 |
69 void SkDilateY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | 70 void SkDilateY_neon(const SkPMColor* src, SkPMColor* dst, int radius, |
70 int width, int height, int srcStride, int dstStride) | 71 int width, int height, int srcStride, int dstStride) |
71 { | 72 { |
72 SkMorph_SSE2<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStr
ide); | 73 SkMorph_neon<kDilate, kY>(src, dst, radius, width, height, srcStride, dstStr
ide); |
73 } | 74 } |
74 | 75 |
75 void SkErodeY_SSE2(const SkPMColor* src, SkPMColor* dst, int radius, | 76 void SkErodeY_neon(const SkPMColor* src, SkPMColor* dst, int radius, |
76 int width, int height, int srcStride, int dstStride) | 77 int width, int height, int srcStride, int dstStride) |
77 { | 78 { |
78 SkMorph_SSE2<kErode, kY>(src, dst, radius, width, height, srcStride, dstStri
de); | 79 SkMorph_neon<kErode, kY>(src, dst, radius, width, height, srcStride, dstStri
de); |
79 } | 80 } |
OLD | NEW |