20 return (
rv >> 18) & ((1 << 14) - 1);
24 return (
rv >> 14) & ((1 << 4) - 1);
28 return rv & ((1 << 14) - 1);
36 uint32_t expectedOutput;
43 {
"-2.100 => {0x00, 0xe, 0x00}",
SkFloatToFixed(-2.100f), 63, 0x38000},
44 {
"-1.900 => {0x00, 0x1, 0x00}",
SkFloatToFixed(-1.900f), 63, 0x04000},
45 {
"-0.500 => {0x00, 0x8, 0x00}",
SkFloatToFixed(-0.500f), 63, 0x20000},
46 {
"0.0000 => {0x00, 0x0, 0x01}",
SkFloatToFixed(0.0000f), 63, 0x000001},
47 {
"0.0416 => {0x00, 0x0, 0x01}",
SkFloatToFixed(0.0416f), 63, 0x000001},
48 {
"1.8583 => {0x01, 0xd, 0x02}",
SkFloatToFixed(1.8583f), 63, 0x074002},
49 {
"3.6749 => {0x03, 0xa, 0x04}",
SkFloatToFixed(3.6749f), 63, 0x0e8004},
50 {
"5.4916 => {0x05, 0x7, 0x06}",
SkFloatToFixed(5.4916f), 63, 0x15c006},
51 {
"7.3083 => {0x07, 0x4, 0x08}",
SkFloatToFixed(7.3083f), 63, 0x1d0008},
52 {
"9.0000 => {0x09, 0x0, 0x0a}",
SkFloatToFixed(9.0000f), 63, 0x24000a},
53 {
"50.000 => {0x32, 0x0, 0x33}",
SkFloatToFixed(50.000f), 63, 0xc80033},
54 {
"50.875 => {0x32, 0xe, 0x33}",
SkFloatToFixed(50.875f), 63, 0xcb8033},
55 {
"62.123 => {0x3e, 0x1, 0x3f}",
SkFloatToFixed(62.123f), 63, 0xf8403f},
56 {
"62.999 => {0x3e, 0xf, 0x3f}",
SkFloatToFixed(62.999f), 63, 0xfbc03f},
57 {
"63.000 => {0x3f, 0x0, 0x3f}",
SkFloatToFixed(63.000f), 63, 0xfc003f},
59 {
"64.500 => {0x3f, 0x8, 0x3f}",
SkFloatToFixed(64.500f), 63, 0xfe003f},
60 {
"127.20 => {0x3f, 0x3, 0x3f}",
SkFloatToFixed(127.20f), 63, 0xfcc03f},
62 {
"64.510 => {0x40, 0x8, 0x41}",
SkFloatToFixed(64.510f), 256, 0x1020041},
63 {
"127.21 => {0x7f, 0x3, 0x80}",
SkFloatToFixed(127.21f), 256, 0x1fcc080},
64 {
"256.77 => {0x100, 0xc, 0x100}",
SkFloatToFixed(256.77f), 256, 0x4030100},
65 {
"10000. => {0x100, 0x0, 0x100}",
SkFloatToFixed(10000.f), 256, 0x4000100},
68 constexpr size_t NUM_TESTS =
sizeof(
tests) /
sizeof(
TestCase);
70 for (
size_t i = 0;
i < NUM_TESTS;
i++) {
73 uint32_t exp = tc.expectedOutput;
76 "%s | %x != %x | {%x, %x, %x} != {%x, %x, %x}\n",
77 tc.name.c_str(),
rv, exp,
83DEF_TEST(MatrixProcs_pack_clamp_out_of_range, r) {
89 uint32_t expectedOutput;
94 static constexpr unsigned MAX_PACKED_VALUE = (1 << 14) - 1;
96 {
"16000.42=>{0xff, 6, 0xff}",
SkFloatToFixed(16000.42f), 255, 0x3fd80ff},
97 {
"17000.42=>{0xff, 6, 0xff}",
SkFloatToFixed(17000.42f), 255, 0x3fd80ff},
98 {
"18000.42=>{0xff, 6, 0xff}",
SkFloatToFixed(18000.42f), 255, 0x3fd80ff},
100 {
"16000.42=>{0x3e80, 6, 0x3e81}",
SkFloatToFixed(16000.42f), MAX_PACKED_VALUE, 0xfa01be81},
101 {
"16382.00=>{0x3ffe, 0, 0x3fff}",
SkFloatToFixed(16382.00f), MAX_PACKED_VALUE, 0xfff83fff},
102 {
"16382.51=>{0x3ffe, 8, 0x3fff}}",
SkFloatToFixed(16382.51f), MAX_PACKED_VALUE, 0xfffa3fff},
103 {
"17000.42=>{0x3fff, 6, 0x3fff}",
SkFloatToFixed(17000.42f), MAX_PACKED_VALUE, 0xfffdbfff},
104 {
"18000.42=>{0x3fff, 6, 0x3fff}",
SkFloatToFixed(18000.42f), MAX_PACKED_VALUE, 0xfffdbfff},
107 {
"32767.90=>{0x3fff, e, 0x0}",
SkFloatToFixed(32767.90f), MAX_PACKED_VALUE, 0xffff8000},
110 constexpr size_t NUM_TESTS =
sizeof(
tests) /
sizeof(
TestCase);
112 for (
size_t i = 0;
i < NUM_TESTS;
i++) {
115 uint32_t exp = tc.expectedOutput;
118 "%s | %x != %x | {%x, %x, %x} != {%x, %x, %x}\n",
119 tc.name.c_str(),
rv, exp,
130 uint32_t expectedOutput;
135 {
"-0.300 => {0x2c, 0xc, 0x2d}",
SkFloatToFixed(-0.300f), 63, 0xb3002d, 63},
136 {
"-0.200 => {0x33, 0x3, 0x34}",
SkFloatToFixed(-0.200f), 63, 0xccc034, 63},
137 {
"-0.100 => {0x39, 0x9, 0x3a}",
SkFloatToFixed(-0.100f), 63, 0xe6403a, 63},
139 {
"0.0000 => {0x00, 0x0, 0x01}",
SkFloatToFixed(0.0000f), 63, 0x000001, 63},
140 {
"0.1000 => {0x06, 0x6, 0x07}",
SkFloatToFixed(0.1000f), 63, 0x198007, 63},
141 {
"0.1234 => {0x07, 0xe, 0x08}",
SkFloatToFixed(0.1234f), 63, 0x1f8008, 63},
142 {
"0.2000 => {0x0c, 0xc, 0x0d}",
SkFloatToFixed(0.2000f), 63, 0x33000d, 63},
143 {
"0.3000 => {0x13, 0x3, 0x14}",
SkFloatToFixed(0.3000f), 63, 0x4cc014, 63},
144 {
"0.4000 => {0x19, 0x9, 0x1a}",
SkFloatToFixed(0.4000f), 63, 0x66401a, 63},
145 {
"0.5000 => {0x20, 0x0, 0x21}",
SkFloatToFixed(0.5000f), 63, 0x800021, 63},
146 {
"0.5678 => {0x24, 0x5, 0x25}",
SkFloatToFixed(0.5678f), 63, 0x914025, 63},
147 {
"0.6000 => {0x26, 0x6, 0x27}",
SkFloatToFixed(0.6000f), 63, 0x998027, 63},
148 {
"0.7000 => {0x2c, 0xc, 0x2d}",
SkFloatToFixed(0.7000f), 63, 0xb3002d, 63},
149 {
"0.8000 => {0x33, 0x3, 0x34}",
SkFloatToFixed(0.8000f), 63, 0xccc034, 63},
150 {
"0.9000 => {0x39, 0x9, 0x3a}",
SkFloatToFixed(0.9000f), 63, 0xe6403a, 63},
151 {
"0.9500 => {0x3c, 0xc, 0x3d}",
SkFloatToFixed(0.9500f), 63, 0xf3003d, 63},
152 {
"0.9990 => {0x3f, 0xe, 0x00}",
SkFloatToFixed(0.9990f), 63, 0xff8000, 63},
154 {
"1.0000 => {0x00, 0x0, 0x01}",
SkFloatToFixed(1.0000f), 63, 0x000001, 63},
155 {
"1.1000 => {0x06, 0x6, 0x07}",
SkFloatToFixed(1.1000f), 63, 0x198007, 63},
156 {
"1.1234 => {0x07, 0xe, 0x08}",
SkFloatToFixed(1.1234f), 63, 0x1f8008, 63},
157 {
"1.9500 => {0x3c, 0xc, 0x3d}",
SkFloatToFixed(1.9500f), 63, 0xf3003d, 63},
159 {
"0.4567 => {0x75, 0x5, 0x76}",
SkFloatToFixed(0.4567f), 256, 0x1d54076, 256},
160 {
"1.0000 => {0x00, 0x0, 0x01}",
SkFloatToFixed(1.0000f), 256, 0x0000001, 256},
161 {
"1.2345 => {0x3c, 0x4, 0x3d}",
SkFloatToFixed(1.2345f), 256, 0x0f1003d, 256},
163 {
"0.1111 [64,128] => {0x07, 0x3, 0x07}",
SkFloatToFixed(0.1111f), 64, 0x1cc007, 128},
164 {
"0.1111 [64,256] => {0x07, 0x3, 0x07}",
SkFloatToFixed(0.1111f), 64, 0x1cc007, 256},
165 {
"0.1111 [64,512] => {0x07, 0x3, 0x07}",
SkFloatToFixed(0.1111f), 64, 0x1cc007, 512},
166 {
"0.1111 [64, 32] => {0x07, 0x3, 0x09}",
SkFloatToFixed(0.1111f), 64, 0x1cc009, 32},
167 {
"0.1111 [64, 8] => {0x07, 0x3, 0x0f}",
SkFloatToFixed(0.1111f), 64, 0x1cc00f, 8},
170 constexpr size_t NUM_TESTS =
sizeof(
tests) /
sizeof(
TestCase);
172 for (
size_t i = 0;
i < NUM_TESTS;
i++) {
175 uint32_t exp = tc.expectedOutput;
178 "%s | %x != %x | {%x, %x, %x} != {%x, %x, %x}\n",
179 tc.name.c_str(),
rv, exp,
190 uint32_t expectedOutput;
196 {
"-0.300 => {0x13, 0xc, 0x12}",
SkFloatToFixed(-0.300f), 63, 0x4f0012, 63},
197 {
"-0.200 => {0x0c, 0x3, 0x0b}",
SkFloatToFixed(-0.200f), 63, 0x30c00b, 63},
198 {
"-0.100 => {0x06, 0x9, 0x05}",
SkFloatToFixed(-0.100f), 63, 0x1a4005, 63},
200 {
"0.0000 => {0x00, 0x0, 0x01}",
SkFloatToFixed(0.0000f), 63, 0x000001, 63},
201 {
"0.1000 => {0x06, 0x6, 0x07}",
SkFloatToFixed(0.1000f), 63, 0x198007, 63},
202 {
"0.1234 => {0x07, 0xe, 0x08}",
SkFloatToFixed(0.1234f), 63, 0x1f8008, 63},
203 {
"0.2000 => {0x0c, 0xc, 0x0d}",
SkFloatToFixed(0.2000f), 63, 0x33000d, 63},
204 {
"0.3000 => {0x13, 0x3, 0x14}",
SkFloatToFixed(0.3000f), 63, 0x4cc014, 63},
205 {
"0.4000 => {0x19, 0x9, 0x1a}",
SkFloatToFixed(0.4000f), 63, 0x66401a, 63},
206 {
"0.5000 => {0x20, 0x0, 0x21}",
SkFloatToFixed(0.5000f), 63, 0x800021, 63},
207 {
"0.5678 => {0x24, 0x5, 0x25}",
SkFloatToFixed(0.5678f), 63, 0x914025, 63},
208 {
"0.6000 => {0x26, 0x6, 0x27}",
SkFloatToFixed(0.6000f), 63, 0x998027, 63},
209 {
"0.7000 => {0x2c, 0xc, 0x2d}",
SkFloatToFixed(0.7000f), 63, 0xb3002d, 63},
210 {
"0.8000 => {0x33, 0x3, 0x34}",
SkFloatToFixed(0.8000f), 63, 0xccc034, 63},
211 {
"0.9000 => {0x39, 0x9, 0x3a}",
SkFloatToFixed(0.9000f), 63, 0xe6403a, 63},
212 {
"0.9500 => {0x3c, 0xc, 0x3d}",
SkFloatToFixed(0.9500f), 63, 0xf3003d, 63},
213 {
"0.9990 => {0x3f, 0xe, 0x3f}",
SkFloatToFixed(0.9990f), 63, 0xff803f, 63},
215 {
"1.0000 => {0x3f, 0x0, 0x3e}",
SkFloatToFixed(1.0000f), 63, 0xfc003e, 63},
216 {
"1.1000 => {0x39, 0x6, 0x38}",
SkFloatToFixed(1.1000f), 63, 0xe58038, 63},
217 {
"1.1234 => {0x38, 0xe, 0x37}",
SkFloatToFixed(1.1234f), 63, 0xe38037, 63},
218 {
"1.9500 => {0x03, 0xc, 0x02}",
SkFloatToFixed(1.9500f), 63, 0xf0002, 63},
220 {
"0.4567 => {0x75, 0x5, 0x76}",
SkFloatToFixed(0.4567f), 256, 0x1d54076, 256},
221 {
"1.0000 => {0x100,0x0, 0xff}",
SkFloatToFixed(1.0000f), 256, 0x40000ff, 256},
222 {
"1.2345 => {0xc4, 0x4, 0xc3}",
SkFloatToFixed(1.2345f), 256, 0x31100c3, 256},
224 {
"0.1111 [64,128] => {0x07, 0x3, 0x07}",
SkFloatToFixed(0.1111f), 64, 0x1cc007, 128},
225 {
"0.1111 [64,256] => {0x07, 0x3, 0x07}",
SkFloatToFixed(0.1111f), 64, 0x1cc007, 256},
226 {
"0.1111 [64,512] => {0x07, 0x3, 0x07}",
SkFloatToFixed(0.1111f), 64, 0x1cc007, 512},
227 {
"0.1111 [64, 32] => {0x07, 0x3, 0x09}",
SkFloatToFixed(0.1111f), 64, 0x1cc009, 32},
228 {
"0.1111 [64, 8] => {0x07, 0x3, 0x0f}",
SkFloatToFixed(0.1111f), 64, 0x1cc00f, 8},
231 constexpr size_t NUM_TESTS =
sizeof(
tests) /
sizeof(
TestCase);
233 for (
size_t i = 0;
i < NUM_TESTS;
i++) {
236 uint32_t exp = tc.expectedOutput;
239 "%s | %x != %x | {%x, %x, %x} != {%x, %x, %x}\n",
240 tc.name.c_str(),
rv, exp,
250 uint32_t expectedLowerBound;
251 uint32_t expectedLerp;
252 uint32_t expectedUpperBound;
256 {
"0x000000 => {0x00, 0x0, 0x00}", 0x000000, 0x00, 0x0, 0x00},
257 {
"0x074002 => {0x01, 0xd, 0x02}", 0x074002, 0x01, 0xd, 0x02},
258 {
"0x15c006 => {0x05, 0x7, 0x06}", 0x15c006, 0x05, 0x7, 0x06},
259 {
"0x1d0008 => {0x07, 0x4, 0x08}", 0x1d0008, 0x07, 0x4, 0x08},
260 {
"0x24000a => {0x09, 0x0, 0x0a}", 0x24000a, 0x09, 0x0, 0x0a},
261 {
"0xfc003f => {0x3f, 0x0, 0x3f}", 0xfc003f, 0x3f, 0x0, 0x3f},
262 {
"0x4000100 => {0x100, 0x0, 0x100}", 0x4000100, 0x100, 0x0, 0x100},
265 constexpr size_t NUM_TESTS =
sizeof(
tests) /
sizeof(
TestCase);
267 for (
size_t i = 0;
i < NUM_TESTS;
i++) {
273 "%s lower %x != %x", tc.name.c_str(),
lower, tc.expectedLowerBound);
275 "%s lerp %x != %x", tc.name.c_str(),
lerp, tc.expectedLerp);
277 "%s upper %x != %x", tc.name.c_str(), upper, tc.expectedUpperBound);
SkPoint lerp(const SkPoint &a, const SkPoint &b, float t)
DEF_TEST(MatrixProcs_pack_clamp, r)
uint32_t highBits(uint32_t rv)
uint32_t lowBits(uint32_t rv)
uint32_t middleBits(uint32_t rv)
#define SkFloatToFixed(x)
#define REPORTER_ASSERT(r, cond,...)
static float max(float r, float g, float b)
DEF_SWITCHES_START aot vmservice shared library name
uint32_t pack_repeat(SkFixed f, unsigned max, size_t width)
uint32_t pack_mirror(SkFixed f, unsigned max, size_t width)
void decode_packed_coordinates_and_weight(U32 packed, Out *v0, Out *v1, Out *w)
uint32_t pack_clamp(SkFixed f, unsigned max)