Chromium Code Reviews| 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkBlurImage_opts.h" | 11 #include "SkBlurImage_opts.h" |
| 12 #include "SkRect.h" | 12 #include "SkRect.h" |
| 13 | 13 |
| 14 #include <arm_neon.h> | 14 #include <arm_neon.h> |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 enum BlurDirection { | 18 enum BlurDirection { |
| 19 kX, kY | 19 kX, kY |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Helper function to load 2 pixels from diffent rows to a 8x8 NEON register | |
| 24 * and also pre-load pixels for future read | |
| 25 */ | |
| 26 template<BlurDirection srcDirection> | |
| 27 inline uint8x8_t load_2_pixels(const SkPMColor* src, int srcStride) { | |
| 28 if (srcDirection == kX) { | |
| 29 uint32x2_t temp = vdup_n_u32(0); | |
| 30 // 10% faster by add these 2 prefetches | |
| 31 SK_PREFETCH(src + 16); | |
| 32 SK_PREFETCH(src + srcStride + 16); | |
| 33 return vreinterpret_u8_u32(vld1_lane_u32(src + srcStride, vld1_lane_u32( src, temp, 0), 1)); | |
| 34 } else { | |
| 35 // this prefetch doesn't impact the performance | |
| 36 SK_PREFETCH(src + srcStride); | |
| 37 return vld1_u8((uint8_t*)src); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * Helper function to store the low 8-bits from a 16x8 NEON register to 2 rows | |
| 43 */ | |
| 44 template<BlurDirection dstDirection> | |
| 45 inline void store_2_pixels(uint16x8_t result16x8, SkPMColor* dst, int dstStride) { | |
| 46 if (dstDirection == kX) { | |
| 47 uint32x2_t temp = vreinterpret_u32_u8(vmovn_u16(result16x8)); | |
| 48 vst1_lane_u32(dst, temp, 0); | |
| 49 vst1_lane_u32(dst + dstStride, temp, 1); | |
| 50 } else { | |
| 51 uint8x8_t temp = vmovn_u16(result16x8); | |
| 52 vst1_u8((uint8_t*)dst, temp); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 /** | |
| 57 * fast path for kernel size less than 128 | |
| 58 */ | |
| 59 template<BlurDirection srcDirection, BlurDirection dstDirection> | |
| 60 void SkDoubleRowBoxBlur_NEON(const SkPMColor** src, int srcStride, SkPMColor** d st, int kernelSize, | |
| 61 int leftOffset, int rightOffset, int width, int* height) | |
| 62 { | |
| 63 const int rightBorder = SkMin32(rightOffset + 1, width); | |
| 64 const int srcStrideX = srcDirection == kX ? 1 : srcStride; | |
| 65 const int dstStrideX = dstDirection == kX ? 1 : *height; | |
| 66 const int srcStrideY = srcDirection == kX ? srcStride : 1; | |
| 67 const int dstStrideY = dstDirection == kX ? width : 1; | |
| 68 const uint16x8_t scale = vdupq_n_u16((1 << 15) / kernelSize); | |
| 69 | |
| 70 for (; *height >= 2; *height -= 2) { | |
| 71 uint16x8_t sum = vdupq_n_u16(0); | |
| 72 const SkPMColor* p = *src; | |
| 73 for (int i = 0; i < rightBorder; i++) { | |
| 74 sum = vaddw_u8(sum, | |
| 75 load_2_pixels<srcDirection>(p, srcStride)); | |
| 76 p += srcStrideX; | |
| 77 } | |
| 78 | |
| 79 const SkPMColor* sptr = *src; | |
| 80 SkPMColor* dptr = *dst; | |
| 81 for (int x = 0; x < width; x++) { | |
| 82 // val = (sum * scale * 2 + 0x8000) >> 16 | |
| 83 uint16x8_t resultPixles = vreinterpretq_u16_s16(vqrdmulhq_s16( | |
|
kevin.petit.not.used.account
2013/12/12 15:29:32
typo: "Pixles" => "Pixels". Otherwise, nice use of
zheng.xu
2013/12/13 04:31:59
Done.
| |
| 84 vreinterpretq_s16_u16(sum), vreinterpretq_s16_u16(scale))); | |
| 85 store_2_pixels<dstDirection>(resultPixles, dptr, width); | |
| 86 | |
| 87 if (x >= leftOffset) { | |
| 88 sum = vsubw_u8(sum, | |
|
kevin.petit.not.used.account
2013/12/12 15:29:32
stray space character at the end of the line
zheng.xu
2013/12/13 04:31:59
Done.
| |
| 89 load_2_pixels<srcDirection>(sptr - leftOffset * srcStrideX, srcStride)); | |
| 90 } | |
| 91 if (x + rightOffset + 1 < width) { | |
| 92 sum = vaddw_u8(sum, | |
|
kevin.petit.not.used.account
2013/12/12 15:29:32
stray space character at the end of the line
zheng.xu
2013/12/13 04:31:59
Done.
| |
| 93 load_2_pixels<srcDirection>(sptr + (rightOffset + 1) * srcSt rideX, srcStride)); | |
| 94 } | |
| 95 sptr += srcStrideX; | |
| 96 dptr += dstStrideX; | |
| 97 } | |
| 98 *src += srcStrideY * 2; | |
| 99 *dst += dstStrideY * 2; | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 | |
| 104 /** | |
| 23 * Helper function to spread the components of a 32-bit integer into the | 105 * Helper function to spread the components of a 32-bit integer into the |
| 24 * lower 8 bits of each 16-bit element of a NEON register. | 106 * lower 8 bits of each 16-bit element of a NEON register. |
| 25 */ | 107 */ |
| 26 | 108 |
| 27 static inline uint16x4_t expand(uint32_t a) { | 109 static inline uint16x4_t expand(uint32_t a) { |
| 28 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B ) | 110 // ( ARGB ) -> ( ARGB ARGB ) -> ( A R G B A R G B ) |
| 29 uint8x8_t v8 = vreinterpret_u8_u32(vdup_n_u32(a)); | 111 uint8x8_t v8 = vreinterpret_u8_u32(vdup_n_u32(a)); |
| 30 // ( A R G B A R G B ) -> ( 0A 0R 0G 0B 0A 0R 0G 0B ) -> ( 0A 0R 0G 0B ) | 112 // ( A R G B A R G B ) -> ( 0A 0R 0G 0B 0A 0R 0G 0B ) -> ( 0A 0R 0G 0B ) |
| 31 return vget_low_u16(vmovl_u8(v8)); | 113 return vget_low_u16(vmovl_u8(v8)); |
| 32 } | 114 } |
| 33 | 115 |
| 34 template<BlurDirection srcDirection, BlurDirection dstDirection> | 116 template<BlurDirection srcDirection, BlurDirection dstDirection> |
| 35 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, | 117 void SkBoxBlur_NEON(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker nelSize, |
| 36 int leftOffset, int rightOffset, int width, int height) | 118 int leftOffset, int rightOffset, int width, int height) |
| 37 { | 119 { |
| 38 const int rightBorder = SkMin32(rightOffset + 1, width); | 120 const int rightBorder = SkMin32(rightOffset + 1, width); |
| 39 const int srcStrideX = srcDirection == kX ? 1 : srcStride; | 121 const int srcStrideX = srcDirection == kX ? 1 : srcStride; |
| 40 const int dstStrideX = dstDirection == kX ? 1 : height; | 122 const int dstStrideX = dstDirection == kX ? 1 : height; |
| 41 const int srcStrideY = srcDirection == kX ? srcStride : 1; | 123 const int srcStrideY = srcDirection == kX ? srcStride : 1; |
| 42 const int dstStrideY = dstDirection == kX ? width : 1; | 124 const int dstStrideY = dstDirection == kX ? width : 1; |
| 43 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize); | 125 const uint32x4_t scale = vdupq_n_u32((1 << 24) / kernelSize); |
| 44 const uint32x4_t half = vdupq_n_u32(1 << 23); | 126 const uint32x4_t half = vdupq_n_u32(1 << 23); |
| 45 for (int y = 0; y < height; ++y) { | 127 |
| 128 if (kernelSize < 128) | |
| 129 { | |
| 130 SkDoubleRowBoxBlur_NEON<srcDirection, dstDirection>(&src, srcStride, &ds t, kernelSize, | |
| 131 leftOffset, rightOffset, width, &height); | |
| 132 } | |
| 133 | |
| 134 for (; height > 0; height--) { | |
|
kevin.petit.not.used.account
2013/12/12 15:29:32
That means the last row in the case of an odd coun
zheng.xu
2013/12/13 04:31:59
I think it is not. Because this algorithm is alrea
| |
| 46 uint32x4_t sum = vdupq_n_u32(0); | 135 uint32x4_t sum = vdupq_n_u32(0); |
| 47 const SkPMColor* p = src; | 136 const SkPMColor* p = src; |
| 48 for (int i = 0; i < rightBorder; ++i) { | 137 for (int i = 0; i < rightBorder; ++i) { |
| 49 sum = vaddw_u16(sum, expand(*p)); | 138 sum = vaddw_u16(sum, expand(*p)); |
| 50 p += srcStrideX; | 139 p += srcStrideX; |
| 51 } | 140 } |
| 52 | 141 |
| 53 const SkPMColor* sptr = src; | 142 const SkPMColor* sptr = src; |
| 54 SkPMColor* dptr = dst; | 143 SkPMColor* dptr = dst; |
| 55 for (int x = 0; x < width; ++x) { | 144 for (int x = 0; x < width; ++x) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 70 | 159 |
| 71 if (x >= leftOffset) { | 160 if (x >= leftOffset) { |
| 72 const SkPMColor* l = sptr - leftOffset * srcStrideX; | 161 const SkPMColor* l = sptr - leftOffset * srcStrideX; |
| 73 sum = vsubw_u16(sum, expand(*l)); | 162 sum = vsubw_u16(sum, expand(*l)); |
| 74 } | 163 } |
| 75 if (x + rightOffset + 1 < width) { | 164 if (x + rightOffset + 1 < width) { |
| 76 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX; | 165 const SkPMColor* r = sptr + (rightOffset + 1) * srcStrideX; |
| 77 sum = vaddw_u16(sum, expand(*r)); | 166 sum = vaddw_u16(sum, expand(*r)); |
| 78 } | 167 } |
| 79 sptr += srcStrideX; | 168 sptr += srcStrideX; |
| 80 if (srcDirection == kY) { | 169 if (srcDirection == kX) { |
| 170 SK_PREFETCH(sptr + (rightOffset + 16) * srcStrideX); | |
| 171 } else { | |
| 81 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); | 172 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); |
| 82 } | 173 } |
| 83 dptr += dstStrideX; | 174 dptr += dstStrideX; |
| 84 } | 175 } |
| 85 src += srcStrideY; | 176 src += srcStrideY; |
| 86 dst += dstStrideY; | 177 dst += dstStrideY; |
| 87 } | 178 } |
| 88 } | 179 } |
| 89 | 180 |
| 90 } // namespace | 181 } // namespace |
| 91 | 182 |
| 92 bool SkBoxBlurGetPlatformProcs_NEON(SkBoxBlurProc* boxBlurX, | 183 bool SkBoxBlurGetPlatformProcs_NEON(SkBoxBlurProc* boxBlurX, |
| 93 SkBoxBlurProc* boxBlurY, | 184 SkBoxBlurProc* boxBlurY, |
| 94 SkBoxBlurProc* boxBlurXY, | 185 SkBoxBlurProc* boxBlurXY, |
| 95 SkBoxBlurProc* boxBlurYX) { | 186 SkBoxBlurProc* boxBlurYX) { |
| 96 *boxBlurX = SkBoxBlur_NEON<kX, kX>; | 187 *boxBlurX = SkBoxBlur_NEON<kX, kX>; |
| 97 *boxBlurY = SkBoxBlur_NEON<kY, kY>; | 188 *boxBlurY = SkBoxBlur_NEON<kY, kY>; |
| 98 *boxBlurXY = SkBoxBlur_NEON<kX, kY>; | 189 *boxBlurXY = SkBoxBlur_NEON<kX, kY>; |
| 99 *boxBlurYX = SkBoxBlur_NEON<kY, kX>; | 190 *boxBlurYX = SkBoxBlur_NEON<kY, kX>; |
| 100 return true; | 191 return true; |
| 101 } | 192 } |
| OLD | NEW |