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 | |
70 // Returns dst in its "natural" bias (either unit-float or 16bit int) | 49 // Returns dst in its "natural" bias (either unit-float or 16bit int) |
71 // | 50 // |
72 template <DstType D> Sk4f load_from_dst(uint64_t dst) { | 51 template <DstType D> Sk4f load_from_dst(uint64_t dst) { |
73 return (D == kU16_Dst) ? load_from_u16(dst) : load_from_f16(dst); | 52 return (D == kU16_Dst) ? load_from_u16(dst) : SkHalfToFloat_01(dst); |
74 } | 53 } |
75 | 54 |
76 // Assumes x4 is already in the "natural" bias (either unit-float or 16bit int) | 55 // Assumes x4 is already in the "natural" bias (either unit-float or 16bit int) |
77 template <DstType D> uint64_t store_to_dst(const Sk4f& x4) { | 56 template <DstType D> uint64_t store_to_dst(const Sk4f& x4) { |
78 return (D == kU16_Dst) ? store_to_u16(x4) : store_to_f16(x4); | 57 return (D == kU16_Dst) ? store_to_u16(x4) : SkFloatToHalf_01(x4); |
79 } | 58 } |
80 | 59 |
81 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 60 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
82 | 61 |
83 template <DstType D> void src_1(const SkXfermode::U64State& state, uint64_t dst[
], | 62 template <DstType D> void src_1(const SkXfermode::U64State& state, uint64_t dst[
], |
84 const SkPM4f& src, int count, const SkAlpha aa[]
) { | 63 const SkPM4f& src, int count, const SkAlpha aa[]
) { |
85 const Sk4f s4 = unit_to_dst_bias<D>(Sk4f::Load(src.fVec)); | 64 const Sk4f s4 = unit_to_dst_bias<D>(Sk4f::Load(src.fVec)); |
86 if (aa) { | 65 if (aa) { |
87 for (int i = 0; i < count; ++i) { | 66 for (int i = 0; i < count; ++i) { |
88 const Sk4f d4 = load_from_dst<D>(dst[i]); | 67 const Sk4f d4 = load_from_dst<D>(dst[i]); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return { nullptr, nullptr }; | 151 return { nullptr, nullptr }; |
173 } | 152 } |
174 | 153 |
175 SkXfermode::U64Proc1 SkXfermode::GetU64Proc1(Mode mode, uint32_t flags) { | 154 SkXfermode::U64Proc1 SkXfermode::GetU64Proc1(Mode mode, uint32_t flags) { |
176 return find_procs(mode, flags).fP1; | 155 return find_procs(mode, flags).fP1; |
177 } | 156 } |
178 | 157 |
179 SkXfermode::U64ProcN SkXfermode::GetU64ProcN(Mode mode, uint32_t flags) { | 158 SkXfermode::U64ProcN SkXfermode::GetU64ProcN(Mode mode, uint32_t flags) { |
180 return find_procs(mode, flags).fPN; | 159 return find_procs(mode, flags).fPN; |
181 } | 160 } |
OLD | NEW |