1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkHalf.h"
#include "SkPM4fPriv.h"
#include "SkUtils.h"
#include "SkXfermodePriv.h"
static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCoverage) {
return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
static void xfer_1(SkBlendMode mode, uint64_t dst[], const SkPM4f* src, int count,
const SkAlpha aa[]) {
SkXfermodeProc4f proc = SkXfermode::GetProc4f(mode);
SkPM4f d;
if (aa) {
for (int i = 0; i < count; ++i) {
Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
d4.store(d.fVec);
Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
SkFloatToHalf_finite_ftz(lerp_by_coverage(r4, d4, aa[i])).store(&dst[i]);
}
} else {
for (int i = 0; i < count; ++i) {
SkHalfToFloat_finite_ftz(dst[i]).store(d.fVec);
Sk4f r4 = Sk4f::Load(proc(*src, d).fVec);
SkFloatToHalf_finite_ftz(r4).store(&dst[i]);
}
}
}
static void xfer_n(SkBlendMode mode, uint64_t dst[], const SkPM4f src[], int count,
const SkAlpha aa[]) {
SkXfermodeProc4f proc = SkXfermode::GetProc4f(mode);
SkPM4f d;
if (aa) {
for (int i = 0; i < count; ++i) {
Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
d4.store(d.fVec);
Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
SkFloatToHalf_finite_ftz(lerp_by_coverage(r4, d4, aa[i])).store(&dst[i]);
}
} else {
for (int i = 0; i < count; ++i) {
SkHalfToFloat_finite_ftz(dst[i]).store(d.fVec);
Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec);
SkFloatToHalf_finite_ftz(r4).store(&dst[i]);
}
}
}
const SkXfermode::F16Proc gProcs_General[] = { xfer_n, xfer_n, xfer_1, xfer_1 };
///////////////////////////////////////////////////////////////////////////////////////////////////
static void clear(SkBlendMode, uint64_t dst[], const SkPM4f*, int count, const SkAlpha aa[]) {
if (aa) {
for (int i = 0; i < count; ++i) {
if (aa[i]) {
const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
SkFloatToHalf_finite_ftz(d4 * Sk4f((255 - aa[i]) * 1.0f/255)).store(&dst[i]);
}
}
} else {
sk_memset64(dst, 0, count);
}
}
const SkXfermode::F16Proc gProcs_Clear[] = { clear, clear, clear, clear };
///////////////////////////////////////////////////////////////////////////////////////////////////
static void src_1(SkBlendMode, uint64_t dst[], const SkPM4f* src, int count, const SkAlpha aa[]) {
const Sk4f s4 = Sk4f::Load(src->fVec);
if (aa) {
for (int i = 0; i < count; ++i) {
const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
SkFloatToHalf_finite_ftz(lerp_by_coverage(s4, d4, aa[i])).store(&dst[i]);
}
} else {
uint64_t s4h;
SkFloatToHalf_finite_ftz(s4).store(&s4h);
sk_memset64(dst, s4h, count);
}
}
static void src_n(SkBlendMode, uint64_t dst[], const SkPM4f src[], int count, const SkAlpha aa[]) {
if (aa) {
for (int i = 0; i < count; ++i) {
const Sk4f s4 = Sk4f::Load(src[i].fVec);
const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
SkFloatToHalf_finite_ftz(lerp_by_coverage(s4, d4, aa[i])).store(&dst[i]);
}
} else {
for (int i = 0; i < count; ++i) {
const Sk4f s4 = Sk4f::Load(src[i].fVec);
SkFloatToHalf_finite_ftz(s4).store(&dst[i]);
}
}
}
const SkXfermode::F16Proc gProcs_Src[] = { src_n, src_n, src_1, src_1 };
///////////////////////////////////////////////////////////////////////////////////////////////////
static void dst(SkBlendMode, uint64_t*, const SkPM4f*, int count, const SkAlpha[]) {}
const SkXfermode::F16Proc gProcs_Dst[] = { dst, dst, dst, dst };
///////////////////////////////////////////////////////////////////////////////////////////////////
static void srcover_1(SkBlendMode, uint64_t dst[], const SkPM4f* src, int count,
const SkAlpha aa[]) {
const Sk4f s4 = Sk4f::Load(src->fVec);
const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
for (int i = 0; i < count; ++i) {
const Sk4f d4 = SkHalfToFloat_finite_ftz(dst[i]);
const Sk4f r4 = s4 + d4 * dst_scale;
if (aa) {
SkFloatToHalf_finite_ftz(lerp_by_coverage(r4, d4, aa[i])).store(&dst[i]);
} else {
SkFloatToHalf_finite_ftz(r4).store(&dst[i]);
}
}
}
static void srcover_n(SkBlendMode, uint64_t dst[], const SkPM4f src[], int count,
const SkAlpha aa[]) {
for (int i = 0; i < count; ++i) {
Sk4f s = Sk4f::Load(src+i),
d = SkHalfToFloat_finite_ftz(dst[i]),
r = s + d*(1.0f - SkNx_shuffle<3,3,3,3>(s));
if (aa) {
r = lerp_by_coverage(r, d, aa[i]);
}
SkFloatToHalf_finite_ftz(r).store(&dst[i]);
}
}
const SkXfermode::F16Proc gProcs_SrcOver[] = { srcover_n, src_n, srcover_1, src_1 };
///////////////////////////////////////////////////////////////////////////////////////////////////
SkXfermode::F16Proc SkXfermode::GetF16Proc(SkBlendMode mode, uint32_t flags) {
SkASSERT(0 == (flags & ~3));
flags &= 3;
switch (mode) {
case SkBlendMode::kClear: return gProcs_Clear[flags];
case SkBlendMode::kSrc: return gProcs_Src[flags];
case SkBlendMode::kDst: return gProcs_Dst[flags];
case SkBlendMode::kSrcOver: return gProcs_SrcOver[flags];
default:
break;
}
return gProcs_General[flags];
}
|