| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 #include "SkHalf.h" | 8 #include "SkHalf.h" |
| 9 #include "SkPM4fPriv.h" | 9 #include "SkPM4fPriv.h" |
| 10 #include "SkUtils.h" | 10 #include "SkUtils.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 return SkNx_cast<float>(Sk4h::Load(&value)); | 39 return SkNx_cast<float>(Sk4h::Load(&value)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // takes floats already biased by 65535 | 42 // takes floats already biased by 65535 |
| 43 static uint64_t store_to_u16(const Sk4f& x4) { | 43 static uint64_t store_to_u16(const Sk4f& x4) { |
| 44 uint64_t value; | 44 uint64_t value; |
| 45 SkNx_cast<uint16_t>(x4 + Sk4f(0.5f)).store(&value); | 45 SkNx_cast<uint16_t>(x4 + Sk4f(0.5f)).store(&value); |
| 46 return value; | 46 return value; |
| 47 } | 47 } |
| 48 | 48 |
| 49 static Sk4f load_from_f16(uint64_t value) { |
| 50 const uint16_t* u16 = reinterpret_cast<const uint16_t*>(&value); |
| 51 float f4[4]; |
| 52 for (int i = 0; i < 4; ++i) { |
| 53 f4[i] = SkHalfToFloat(u16[i]); |
| 54 } |
| 55 return Sk4f::Load(f4); |
| 56 } |
| 57 |
| 58 static uint64_t store_to_f16(const Sk4f& x4) { |
| 59 uint64_t value; |
| 60 uint16_t* u16 = reinterpret_cast<uint16_t*>(&value); |
| 61 |
| 62 float f4[4]; |
| 63 x4.store(f4); |
| 64 for (int i = 0; i < 4; ++i) { |
| 65 u16[i] = SkFloatToHalf(f4[i]); |
| 66 } |
| 67 return value; |
| 68 } |
| 69 |
| 49 // Returns dst in its "natural" bias (either unit-float or 16bit int) | 70 // Returns dst in its "natural" bias (either unit-float or 16bit int) |
| 50 // | 71 // |
| 51 template <DstType D> Sk4f load_from_dst(uint64_t dst) { | 72 template <DstType D> Sk4f load_from_dst(uint64_t dst) { |
| 52 return (D == kU16_Dst) ? load_from_u16(dst) : SkHalfToFloat_01(dst); | 73 return (D == kU16_Dst) ? load_from_u16(dst) : load_from_f16(dst); |
| 53 } | 74 } |
| 54 | 75 |
| 55 // Assumes x4 is already in the "natural" bias (either unit-float or 16bit int) | 76 // Assumes x4 is already in the "natural" bias (either unit-float or 16bit int) |
| 56 template <DstType D> uint64_t store_to_dst(const Sk4f& x4) { | 77 template <DstType D> uint64_t store_to_dst(const Sk4f& x4) { |
| 57 return (D == kU16_Dst) ? store_to_u16(x4) : SkFloatToHalf_01(x4); | 78 return (D == kU16_Dst) ? store_to_u16(x4) : store_to_f16(x4); |
| 58 } | 79 } |
| 59 | 80 |
| 60 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 81 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 61 | 82 |
| 62 template <DstType D> void src_1(const SkXfermode::U64State& state, uint64_t dst[
], | 83 template <DstType D> void src_1(const SkXfermode::U64State& state, uint64_t dst[
], |
| 63 const SkPM4f& src, int count, const SkAlpha aa[]
) { | 84 const SkPM4f& src, int count, const SkAlpha aa[]
) { |
| 64 const Sk4f s4 = unit_to_dst_bias<D>(Sk4f::Load(src.fVec)); | 85 const Sk4f s4 = unit_to_dst_bias<D>(Sk4f::Load(src.fVec)); |
| 65 if (aa) { | 86 if (aa) { |
| 66 for (int i = 0; i < count; ++i) { | 87 for (int i = 0; i < count; ++i) { |
| 67 const Sk4f d4 = load_from_dst<D>(dst[i]); | 88 const Sk4f d4 = load_from_dst<D>(dst[i]); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 return { nullptr, nullptr }; | 172 return { nullptr, nullptr }; |
| 152 } | 173 } |
| 153 | 174 |
| 154 SkXfermode::U64Proc1 SkXfermode::GetU64Proc1(Mode mode, uint32_t flags) { | 175 SkXfermode::U64Proc1 SkXfermode::GetU64Proc1(Mode mode, uint32_t flags) { |
| 155 return find_procs(mode, flags).fP1; | 176 return find_procs(mode, flags).fP1; |
| 156 } | 177 } |
| 157 | 178 |
| 158 SkXfermode::U64ProcN SkXfermode::GetU64ProcN(Mode mode, uint32_t flags) { | 179 SkXfermode::U64ProcN SkXfermode::GetU64ProcN(Mode mode, uint32_t flags) { |
| 159 return find_procs(mode, flags).fPN; | 180 return find_procs(mode, flags).fPN; |
| 160 } | 181 } |
| OLD | NEW |