OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
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 SK_ALWAYS_INLINE SkPMFloat::SkPMFloat(SkPMColor c) { | 8 namespace { // See SkPMFloat.h |
| 9 |
| 10 inline SkPMFloat::SkPMFloat(SkPMColor c) { |
9 SkPMColorAssert(c); | 11 SkPMColorAssert(c); |
10 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); | 12 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); |
11 uint16x8_t fix8_16 = vmovl_u8(fix8); | 13 uint16x8_t fix8_16 = vmovl_u8(fix8); |
12 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); | 14 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); |
13 fVec = vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)); | 15 fVec = vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)); |
14 SkASSERT(this->isValid()); | 16 SkASSERT(this->isValid()); |
15 } | 17 } |
16 | 18 |
17 SK_ALWAYS_INLINE SkPMColor SkPMFloat::round() const { | 19 inline SkPMColor SkPMFloat::round() const { |
18 // vcvt_u32_f32 truncates, so we round manually by adding a half before conv
erting. | 20 // vcvt_u32_f32 truncates, so we round manually by adding a half before conv
erting. |
19 float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255)); | 21 float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255)); |
20 uint32x4_t fix8_32 = vcvtq_u32_f32(rounded); | 22 uint32x4_t fix8_32 = vcvtq_u32_f32(rounded); |
21 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); | 23 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); |
22 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); | 24 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); |
23 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); | 25 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); |
24 SkPMColorAssert(c); | 26 SkPMColorAssert(c); |
25 return c; | 27 return c; |
26 } | 28 } |
27 | 29 |
28 SK_ALWAYS_INLINE Sk4f SkPMFloat::alphas() const { | 30 inline Sk4f SkPMFloat::alphas() const { |
29 static_assert(SK_A32_SHIFT == 24, "Assuming little-endian."); | 31 static_assert(SK_A32_SHIFT == 24, "Assuming little-endian."); |
30 return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of hi
gh half i.e. lane 3. | 32 return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of hi
gh half i.e. lane 3. |
31 } | 33 } |
| 34 |
| 35 } // namespace |
OLD | NEW |