Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/core/SkXfermodeU64.cpp

Issue 1685203002: lots of sRGB and F16 blits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use SkAutoTMalloc Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkXfermode4f.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 23
24 enum DstType { 24 enum DstType {
25 kU16_Dst, 25 kU16_Dst,
26 kF16_Dst, 26 kF16_Dst,
27 }; 27 };
28 28
29 static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCovera ge) { 29 static Sk4f lerp_by_coverage(const Sk4f& src, const Sk4f& dst, uint8_t srcCovera ge) {
30 return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f)); 30 return dst + (src - dst) * Sk4f(srcCoverage * (1/255.0f));
31 } 31 }
32 32
33 template <DstType D> Sk4f unit_to_dst_bias(const Sk4f& x4) { 33 template <DstType D> Sk4f unit_to_bias(const Sk4f& x4) {
34 return (D == kU16_Dst) ? x4 * Sk4f(65535) : x4; 34 return (D == kU16_Dst) ? x4 * Sk4f(65535) : x4;
35 } 35 }
36 36
37 template <DstType D> Sk4f bias_to_unit(const Sk4f& x4) {
38 return (D == kU16_Dst) ? x4 * Sk4f(1.0f/65535) : x4;
39 }
40
37 // returns value already biased by 65535 41 // returns value already biased by 65535
38 static Sk4f load_from_u16(uint64_t value) { 42 static Sk4f load_from_u16(uint64_t value) {
39 return SkNx_cast<float>(Sk4h::Load(&value)); 43 return SkNx_cast<float>(Sk4h::Load(&value));
40 } 44 }
41 45
42 // takes floats already biased by 65535 46 // takes floats already biased by 65535
43 static uint64_t store_to_u16(const Sk4f& x4) { 47 static uint64_t store_to_u16(const Sk4f& x4) {
44 uint64_t value; 48 uint64_t value;
45 SkNx_cast<uint16_t>(x4 + Sk4f(0.5f)).store(&value); 49 SkNx_cast<uint16_t>(x4 + Sk4f(0.5f)).store(&value);
46 return value; 50 return value;
(...skipping 14 matching lines...) Expand all
61 if (SkPM4f::R == 0) { 65 if (SkPM4f::R == 0) {
62 return x; // we're already RGBA 66 return x; // we're already RGBA
63 } else { 67 } else {
64 // we're BGRA, so swap R and B 68 // we're BGRA, so swap R and B
65 return SkNx_shuffle<2, 1, 0, 3>(x); 69 return SkNx_shuffle<2, 1, 0, 3>(x);
66 } 70 }
67 } 71 }
68 72
69 //////////////////////////////////////////////////////////////////////////////// /////////////////// 73 //////////////////////////////////////////////////////////////////////////////// ///////////////////
70 74
75 template <DstType D> void xfer_u64_1(const SkXfermode::U64State& state, uint64_t dst[],
76 const SkPM4f& src, int count, const SkAlpha aa[]) {
77 SkXfermodeProc4f proc = state.fXfer->getProc4f();
78 SkPM4f d;
79 if (aa) {
80 for (int i = 0; i < count; ++i) {
81 Sk4f d4 = bias_to_unit<D>(load_from_dst<D>(dst[i]));
82 d4.store(d.fVec);
83 Sk4f r4 = unit_to_bias<D>(Sk4f::Load(proc(src, d).fVec));
84 dst[i] = store_to_dst<D>(lerp_by_coverage(r4, d4, aa[i]));
85 }
86 } else {
87 for (int i = 0; i < count; ++i) {
88 bias_to_unit<D>(load_from_dst<D>(dst[i])).store(d.fVec);
89 Sk4f r4 = unit_to_bias<D>(Sk4f::Load(proc(src, d).fVec));
90 dst[i] = store_to_dst<D>(r4);
91 }
92 }
93 }
94
95 template <DstType D> void xfer_u64_n(const SkXfermode::U64State& state, uint64_t dst[],
96 const SkPM4f src[], int count, const SkAlph a aa[]) {
97 SkXfermodeProc4f proc = state.fXfer->getProc4f();
98 SkPM4f d;
99 if (aa) {
100 for (int i = 0; i < count; ++i) {
101 Sk4f d4 = bias_to_unit<D>(load_from_dst<D>(dst[i]));
102 d4.store(d.fVec);
103 Sk4f r4 = unit_to_bias<D>(Sk4f::Load(proc(src[i], d).fVec));
104 dst[i] = store_to_dst<D>(lerp_by_coverage(r4, d4, aa[i]));
105 }
106 } else {
107 for (int i = 0; i < count; ++i) {
108 bias_to_unit<D>(load_from_dst<D>(dst[i])).store(d.fVec);
109 Sk4f r4 = unit_to_bias<D>(Sk4f::Load(proc(src[i], d).fVec));
110 dst[i] = store_to_dst<D>(r4);
111 }
112 }
113 }
114
115 const U64ProcPair gU64Procs_General[] = {
116 { xfer_u64_1<kU16_Dst>, xfer_u64_n<kU16_Dst> }, // U16 alpha
117 { xfer_u64_1<kU16_Dst>, xfer_u64_n<kU16_Dst> }, // U16 opaque
118 { xfer_u64_1<kF16_Dst>, xfer_u64_n<kF16_Dst> }, // F16 alpha
119 { xfer_u64_1<kF16_Dst>, xfer_u64_n<kF16_Dst> }, // F16 opaque
120 };
121
122 //////////////////////////////////////////////////////////////////////////////// ///////////////////
123
71 template <DstType D> void src_1(const SkXfermode::U64State& state, uint64_t dst[ ], 124 template <DstType D> void src_1(const SkXfermode::U64State& state, uint64_t dst[ ],
72 const SkPM4f& src, int count, const SkAlpha aa[] ) { 125 const SkPM4f& src, int count, const SkAlpha aa[] ) {
73 const Sk4f s4 = pm_to_rgba_order(unit_to_dst_bias<D>(Sk4f::Load(src.fVec))); 126 const Sk4f s4 = pm_to_rgba_order(unit_to_bias<D>(Sk4f::Load(src.fVec)));
74 if (aa) { 127 if (aa) {
75 for (int i = 0; i < count; ++i) { 128 for (int i = 0; i < count; ++i) {
76 const Sk4f d4 = load_from_dst<D>(dst[i]); 129 const Sk4f d4 = load_from_dst<D>(dst[i]);
77 dst[i] = store_to_dst<D>(lerp_by_coverage(s4, d4, aa[i])); 130 dst[i] = store_to_dst<D>(lerp_by_coverage(s4, d4, aa[i]));
78 } 131 }
79 } else { 132 } else {
80 sk_memset64(dst, store_to_dst<D>(s4), count); 133 sk_memset64(dst, store_to_dst<D>(s4), count);
81 } 134 }
82 } 135 }
83 136
84 template <DstType D> void src_n(const SkXfermode::U64State& state, uint64_t dst[ ], 137 template <DstType D> void src_n(const SkXfermode::U64State& state, uint64_t dst[ ],
85 const SkPM4f src[], int count, const SkAlpha aa[ ]) { 138 const SkPM4f src[], int count, const SkAlpha aa[ ]) {
86 if (aa) { 139 if (aa) {
87 for (int i = 0; i < count; ++i) { 140 for (int i = 0; i < count; ++i) {
88 const Sk4f s4 = pm_to_rgba_order(unit_to_dst_bias<D>(Sk4f::Load(src[ i].fVec))); 141 const Sk4f s4 = pm_to_rgba_order(unit_to_bias<D>(Sk4f::Load(src[i].f Vec)));
89 const Sk4f d4 = load_from_dst<D>(dst[i]); 142 const Sk4f d4 = load_from_dst<D>(dst[i]);
90 dst[i] = store_to_dst<D>(lerp_by_coverage(s4, d4, aa[i])); 143 dst[i] = store_to_dst<D>(lerp_by_coverage(s4, d4, aa[i]));
91 } 144 }
92 } else { 145 } else {
93 for (int i = 0; i < count; ++i) { 146 for (int i = 0; i < count; ++i) {
94 const Sk4f s4 = pm_to_rgba_order(unit_to_dst_bias<D>(Sk4f::Load(src[ i].fVec))); 147 const Sk4f s4 = pm_to_rgba_order(unit_to_bias<D>(Sk4f::Load(src[i].f Vec)));
95 dst[i] = store_to_dst<D>(s4); 148 dst[i] = store_to_dst<D>(s4);
96 } 149 }
97 } 150 }
98 } 151 }
99 152
100 const U64ProcPair gU64Procs_Src[] = { 153 const U64ProcPair gU64Procs_Src[] = {
101 { src_1<kU16_Dst>, src_n<kU16_Dst> }, // U16 alpha 154 { src_1<kU16_Dst>, src_n<kU16_Dst> }, // U16 alpha
102 { src_1<kU16_Dst>, src_n<kU16_Dst> }, // U16 opaque 155 { src_1<kU16_Dst>, src_n<kU16_Dst> }, // U16 opaque
103 { src_1<kF16_Dst>, src_n<kF16_Dst> }, // F16 alpha 156 { src_1<kF16_Dst>, src_n<kF16_Dst> }, // F16 alpha
104 { src_1<kF16_Dst>, src_n<kF16_Dst> }, // F16 opaque 157 { src_1<kF16_Dst>, src_n<kF16_Dst> }, // F16 opaque
105 }; 158 };
106 159
107 //////////////////////////////////////////////////////////////////////////////// /////////////////// 160 //////////////////////////////////////////////////////////////////////////////// ///////////////////
108 161
109 template <DstType D> void srcover_1(const SkXfermode::U64State& state, uint64_t dst[], 162 template <DstType D> void srcover_1(const SkXfermode::U64State& state, uint64_t dst[],
110 const SkPM4f& src, int count, const SkAlpha aa[]) { 163 const SkPM4f& src, int count, const SkAlpha aa[]) {
111 const Sk4f s4 = pm_to_rgba_order(Sk4f::Load(src.fVec)); 164 const Sk4f s4 = pm_to_rgba_order(Sk4f::Load(src.fVec));
112 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); 165 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
113 const Sk4f s4bias = unit_to_dst_bias<D>(s4); 166 const Sk4f s4bias = unit_to_bias<D>(s4);
114 for (int i = 0; i < count; ++i) { 167 for (int i = 0; i < count; ++i) {
115 const Sk4f d4bias = load_from_dst<D>(dst[i]); 168 const Sk4f d4bias = load_from_dst<D>(dst[i]);
116 const Sk4f r4bias = s4bias + d4bias * dst_scale; 169 const Sk4f r4bias = s4bias + d4bias * dst_scale;
117 if (aa) { 170 if (aa) {
118 dst[i] = store_to_dst<D>(lerp_by_coverage(r4bias, d4bias, aa[i])); 171 dst[i] = store_to_dst<D>(lerp_by_coverage(r4bias, d4bias, aa[i]));
119 } else { 172 } else {
120 dst[i] = store_to_dst<D>(r4bias); 173 dst[i] = store_to_dst<D>(r4bias);
121 } 174 }
122 } 175 }
123 } 176 }
124 177
125 template <DstType D> void srcover_n(const SkXfermode::U64State& state, uint64_t dst[], 178 template <DstType D> void srcover_n(const SkXfermode::U64State& state, uint64_t dst[],
126 const SkPM4f src[], int count, const SkAlpha aa[]) { 179 const SkPM4f src[], int count, const SkAlpha aa[]) {
127 for (int i = 0; i < count; ++i) { 180 for (int i = 0; i < count; ++i) {
128 const Sk4f s4 = pm_to_rgba_order(Sk4f::Load(src[i].fVec)); 181 const Sk4f s4 = pm_to_rgba_order(Sk4f::Load(src[i].fVec));
129 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); 182 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4));
130 const Sk4f s4bias = unit_to_dst_bias<D>(s4); 183 const Sk4f s4bias = unit_to_bias<D>(s4);
131 const Sk4f d4bias = load_from_dst<D>(dst[i]); 184 const Sk4f d4bias = load_from_dst<D>(dst[i]);
132 const Sk4f r4bias = s4bias + d4bias * dst_scale; 185 const Sk4f r4bias = s4bias + d4bias * dst_scale;
133 if (aa) { 186 if (aa) {
134 dst[i] = store_to_dst<D>(lerp_by_coverage(r4bias, d4bias, aa[i])); 187 dst[i] = store_to_dst<D>(lerp_by_coverage(r4bias, d4bias, aa[i]));
135 } else { 188 } else {
136 dst[i] = store_to_dst<D>(r4bias); 189 dst[i] = store_to_dst<D>(r4bias);
137 } 190 }
138 } 191 }
139 } 192 }
140 193
141 const U64ProcPair gU64Procs_SrcOver[] = { 194 const U64ProcPair gU64Procs_SrcOver[] = {
142 { srcover_1<kU16_Dst>, srcover_n<kU16_Dst> }, // U16 alpha 195 { srcover_1<kU16_Dst>, srcover_n<kU16_Dst> }, // U16 alpha
143 { src_1<kU16_Dst>, src_n<kU16_Dst> }, // U16 opaque 196 { src_1<kU16_Dst>, src_n<kU16_Dst> }, // U16 opaque
144 { srcover_1<kF16_Dst>, srcover_n<kF16_Dst> }, // F16 alpha 197 { srcover_1<kF16_Dst>, srcover_n<kF16_Dst> }, // F16 alpha
145 { src_1<kF16_Dst>, src_n<kF16_Dst> }, // F16 opaque 198 { src_1<kF16_Dst>, src_n<kF16_Dst> }, // F16 opaque
146 }; 199 };
147 200
148 //////////////////////////////////////////////////////////////////////////////// /////////////////// 201 //////////////////////////////////////////////////////////////////////////////// ///////////////////
149 202
150 static U64ProcPair find_procs(SkXfermode::Mode mode, uint32_t flags) { 203 static U64ProcPair find_procs(SkXfermode::Mode mode, uint32_t flags) {
151 SkASSERT(0 == (flags & ~3)); 204 SkASSERT(0 == (flags & ~3));
152 flags &= 3; 205 flags &= 3;
153 206
154 switch (mode) { 207 switch (mode) {
155 case SkXfermode::kSrc_Mode: return gU64Procs_Src[flags]; 208 case SkXfermode::kSrc_Mode: return gU64Procs_Src[flags];
156 case SkXfermode::kSrcOver_Mode: return gU64Procs_SrcOver[flags]; 209 case SkXfermode::kSrcOver_Mode: return gU64Procs_SrcOver[flags];
157 default: 210 default:
158 break; 211 break;
159 } 212 }
160 return { nullptr, nullptr }; 213 return gU64Procs_General[flags];
161 } 214 }
162 215
163 SkXfermode::U64Proc1 SkXfermode::GetU64Proc1(Mode mode, uint32_t flags) { 216 SkXfermode::U64Proc1 SkXfermode::GetU64Proc1(Mode mode, uint32_t flags) {
164 return find_procs(mode, flags).fP1; 217 return find_procs(mode, flags).fP1;
165 } 218 }
166 219
167 SkXfermode::U64ProcN SkXfermode::GetU64ProcN(Mode mode, uint32_t flags) { 220 SkXfermode::U64ProcN SkXfermode::GetU64ProcN(Mode mode, uint32_t flags) {
168 return find_procs(mode, flags).fPN; 221 return find_procs(mode, flags).fPN;
169 } 222 }
OLDNEW
« no previous file with comments | « src/core/SkXfermode4f.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698