| 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 "SkPM4fPriv.h" | 8 #include "SkPM4fPriv.h" |
| 9 #include "SkUtils.h" | 9 #include "SkUtils.h" |
| 10 #include "SkXfermode.h" | 10 #include "SkXfermode.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 | 36 |
| 37 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) { | 37 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) { |
| 38 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f); | 38 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f); |
| 39 } | 39 } |
| 40 | 40 |
| 41 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 41 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 42 | 42 |
| 43 template <DstType D> void general_1(const SkXfermode* xfer, uint32_t dst[], | 43 template <DstType D> void general_1(const SkXfermode* xfer, uint32_t dst[], |
| 44 const SkPM4f* src, int count, const SkAlpha
aa[]) { | 44 const SkPM4f* src, int count, const SkAlpha
aa[]) { |
| 45 const SkPM4f s = src->pmorder(); |
| 45 SkXfermodeProc4f proc = xfer->getProc4f(); | 46 SkXfermodeProc4f proc = xfer->getProc4f(); |
| 46 SkPM4f d; | 47 SkPM4f d; |
| 47 if (aa) { | 48 if (aa) { |
| 48 for (int i = 0; i < count; ++i) { | 49 for (int i = 0; i < count; ++i) { |
| 49 Sk4f d4 = load_dst<D>(dst[i]); | 50 Sk4f d4 = load_dst<D>(dst[i]); |
| 50 d4.store(d.fVec); | 51 d4.store(d.fVec); |
| 51 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); | 52 Sk4f r4 = Sk4f::Load(proc(s, d).fVec); |
| 52 dst[i] = store_dst<D>(lerp(r4, d4, aa[i])); | 53 dst[i] = store_dst<D>(lerp(r4, d4, aa[i])); |
| 53 } | 54 } |
| 54 } else { | 55 } else { |
| 55 for (int i = 0; i < count; ++i) { | 56 for (int i = 0; i < count; ++i) { |
| 56 load_dst<D>(dst[i]).store(d.fVec); | 57 load_dst<D>(dst[i]).store(d.fVec); |
| 57 Sk4f r4 = Sk4f::Load(proc(*src, d).fVec); | 58 Sk4f r4 = Sk4f::Load(proc(s, d).fVec); |
| 58 dst[i] = store_dst<D>(r4); | 59 dst[i] = store_dst<D>(r4); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 template <DstType D> void general_n(const SkXfermode* xfer, uint32_t dst[], | 64 template <DstType D> void general_n(const SkXfermode* xfer, uint32_t dst[], |
| 64 const SkPM4f src[], int count, const SkAlpha
aa[]) { | 65 const SkPM4f src[], int count, const SkAlpha
aa[]) { |
| 65 SkXfermodeProc4f proc = xfer->getProc4f(); | 66 SkXfermodeProc4f proc = xfer->getProc4f(); |
| 66 SkPM4f d; | 67 SkPM4f d; |
| 67 if (aa) { | 68 if (aa) { |
| 68 for (int i = 0; i < count; ++i) { | 69 for (int i = 0; i < count; ++i) { |
| 69 Sk4f d4 = load_dst<D>(dst[i]); | 70 Sk4f d4 = load_dst<D>(dst[i]); |
| 70 d4.store(d.fVec); | 71 d4.store(d.fVec); |
| 71 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); | 72 Sk4f r4 = Sk4f::Load(proc(src[i].pmorder(), d).fVec); |
| 72 dst[i] = store_dst<D>(lerp(r4, d4, aa[i])); | 73 dst[i] = store_dst<D>(lerp(r4, d4, aa[i])); |
| 73 } | 74 } |
| 74 } else { | 75 } else { |
| 75 for (int i = 0; i < count; ++i) { | 76 for (int i = 0; i < count; ++i) { |
| 76 load_dst<D>(dst[i]).store(d.fVec); | 77 load_dst<D>(dst[i]).store(d.fVec); |
| 77 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); | 78 Sk4f r4 = Sk4f::Load(proc(src[i], d).fVec); |
| 78 dst[i] = store_dst<D>(r4); | 79 dst[i] = store_dst<D>(r4); |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 } | 82 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 template <DstType D> void src_n(const SkXfermode*, uint32_t dst[], | 135 template <DstType D> void src_n(const SkXfermode*, uint32_t dst[], |
| 135 const SkPM4f src[], int count, const SkAlpha aa[
]) { | 136 const SkPM4f src[], int count, const SkAlpha aa[
]) { |
| 136 for (int i = 0; i < count; ++i) { | 137 for (int i = 0; i < count; ++i) { |
| 137 unsigned a = 0xFF; | 138 unsigned a = 0xFF; |
| 138 if (aa) { | 139 if (aa) { |
| 139 a = aa[i]; | 140 a = aa[i]; |
| 140 if (0 == a) { | 141 if (0 == a) { |
| 141 continue; | 142 continue; |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 Sk4f r4 = Sk4f::Load(src[i].fVec); // src always overrides dst | 145 Sk4f r4 = src[i].to4f_pmorder(); |
| 145 if (a != 0xFF) { | 146 if (a != 0xFF) { |
| 146 Sk4f d4 = load_dst<D>(dst[i]); | 147 Sk4f d4 = load_dst<D>(dst[i]); |
| 147 r4 = lerp(r4, d4, a); | 148 r4 = lerp(r4, d4, a); |
| 148 } | 149 } |
| 149 dst[i] = store_dst<D>(r4); | 150 dst[i] = store_dst<D>(r4); |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 | 153 |
| 153 static Sk4f lerp(const Sk4f& src, const Sk4f& dst, const Sk4f& src_scale) { | 154 static Sk4f lerp(const Sk4f& src, const Sk4f& dst, const Sk4f& src_scale) { |
| 154 return dst + (src - dst) * src_scale; | 155 return dst + (src - dst) * src_scale; |
| 155 } | 156 } |
| 156 | 157 |
| 157 template <DstType D> void src_1(const SkXfermode*, uint32_t dst[], | 158 template <DstType D> void src_1(const SkXfermode*, uint32_t dst[], |
| 158 const SkPM4f* src, int count, const SkAlpha aa[]
) { | 159 const SkPM4f* src, int count, const SkAlpha aa[]
) { |
| 159 const Sk4f s4 = Sk4f::Load(src->fVec); | 160 const Sk4f s4 = src->to4f_pmorder(); |
| 160 | 161 |
| 161 if (aa) { | 162 if (aa) { |
| 162 if (D == kLinear_Dst) { | 163 if (D == kLinear_Dst) { |
| 163 // operate in bias-255 space for src and dst | 164 // operate in bias-255 space for src and dst |
| 164 const Sk4f& s4_255 = s4 * Sk4f(255); | 165 const Sk4f& s4_255 = s4 * Sk4f(255); |
| 165 while (count >= 4) { | 166 while (count >= 4) { |
| 166 Sk4f aa4 = SkNx_cast<float>(Sk4b::Load(aa)) * Sk4f(1/255.f); | 167 Sk4f aa4 = SkNx_cast<float>(Sk4b::Load(aa)) * Sk4f(1/255.f); |
| 167 Sk4f r0 = lerp(s4_255, to_4f(dst[0]), Sk4f(aa4[0])) + Sk4f(0.5f)
; | 168 Sk4f r0 = lerp(s4_255, to_4f(dst[0]), Sk4f(aa4[0])) + Sk4f(0.5f)
; |
| 168 Sk4f r1 = lerp(s4_255, to_4f(dst[1]), Sk4f(aa4[1])) + Sk4f(0.5f)
; | 169 Sk4f r1 = lerp(s4_255, to_4f(dst[1]), Sk4f(aa4[1])) + Sk4f(0.5f)
; |
| 169 Sk4f r2 = lerp(s4_255, to_4f(dst[2]), Sk4f(aa4[2])) + Sk4f(0.5f)
; | 170 Sk4f r2 = lerp(s4_255, to_4f(dst[2]), Sk4f(aa4[2])) + Sk4f(0.5f)
; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 226 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 226 | 227 |
| 227 template <DstType D> void srcover_n(const SkXfermode*, uint32_t dst[], | 228 template <DstType D> void srcover_n(const SkXfermode*, uint32_t dst[], |
| 228 const SkPM4f src[], int count, const SkAlpha
aa[]) { | 229 const SkPM4f src[], int count, const SkAlpha
aa[]) { |
| 229 if (aa) { | 230 if (aa) { |
| 230 for (int i = 0; i < count; ++i) { | 231 for (int i = 0; i < count; ++i) { |
| 231 unsigned a = aa[i]; | 232 unsigned a = aa[i]; |
| 232 if (0 == a) { | 233 if (0 == a) { |
| 233 continue; | 234 continue; |
| 234 } | 235 } |
| 235 Sk4f s4 = Sk4f::Load(src[i].fVec); | 236 Sk4f s4 = src[i].to4f_pmorder(); |
| 236 Sk4f d4 = load_dst<D>(dst[i]); | 237 Sk4f d4 = load_dst<D>(dst[i]); |
| 237 if (a != 0xFF) { | 238 if (a != 0xFF) { |
| 238 s4 = scale_by_coverage(s4, a); | 239 s4 = scale_by_coverage(s4, a); |
| 239 } | 240 } |
| 240 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); | 241 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); |
| 241 dst[i] = store_dst<D>(r4); | 242 dst[i] = store_dst<D>(r4); |
| 242 } | 243 } |
| 243 } else { | 244 } else { |
| 244 for (int i = 0; i < count; ++i) { | 245 for (int i = 0; i < count; ++i) { |
| 245 Sk4f s4 = Sk4f::Load(src[i].fVec); | 246 Sk4f s4 = src[i].to4f_pmorder(); |
| 246 Sk4f d4 = load_dst<D>(dst[i]); | 247 Sk4f d4 = load_dst<D>(dst[i]); |
| 247 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); | 248 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); |
| 248 dst[i] = store_dst<D>(r4); | 249 dst[i] = store_dst<D>(r4); |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 | 253 |
| 253 static void srcover_linear_dst_1(const SkXfermode*, uint32_t dst[], | 254 static void srcover_linear_dst_1(const SkXfermode*, uint32_t dst[], |
| 254 const SkPM4f* src, int count, const SkAlpha aa[
]) { | 255 const SkPM4f* src, int count, const SkAlpha aa[
]) { |
| 255 const Sk4f s4 = Sk4f::Load(src->fVec); | 256 const Sk4f s4 = src->to4f_pmorder(); |
| 256 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); | 257 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); |
| 257 | 258 |
| 258 if (aa) { | 259 if (aa) { |
| 259 for (int i = 0; i < count; ++i) { | 260 for (int i = 0; i < count; ++i) { |
| 260 unsigned a = aa[i]; | 261 unsigned a = aa[i]; |
| 261 if (0 == a) { | 262 if (0 == a) { |
| 262 continue; | 263 continue; |
| 263 } | 264 } |
| 264 Sk4f d4 = Sk4f_fromL32(dst[i]); | 265 Sk4f d4 = Sk4f_fromL32(dst[i]); |
| 265 Sk4f r4; | 266 Sk4f r4; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 288 } | 289 } |
| 289 for (int i = 0; i < count; ++i) { | 290 for (int i = 0; i < count; ++i) { |
| 290 Sk4f d4 = to_4f(dst[i]); | 291 Sk4f d4 = to_4f(dst[i]); |
| 291 dst[i] = to_4b(s4_255 + d4 * dst_scale); | 292 dst[i] = to_4b(s4_255 + d4 * dst_scale); |
| 292 } | 293 } |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 | 296 |
| 296 static void srcover_srgb_dst_1(const SkXfermode*, uint32_t dst[], | 297 static void srcover_srgb_dst_1(const SkXfermode*, uint32_t dst[], |
| 297 const SkPM4f* src, int count, const SkAlpha aa[])
{ | 298 const SkPM4f* src, int count, const SkAlpha aa[])
{ |
| 298 Sk4f s4 = Sk4f::Load(src->fVec); | 299 Sk4f s4 = src->to4f_pmorder(); |
| 299 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); | 300 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); |
| 300 | 301 |
| 301 if (aa) { | 302 if (aa) { |
| 302 for (int i = 0; i < count; ++i) { | 303 for (int i = 0; i < count; ++i) { |
| 303 unsigned a = aa[i]; | 304 unsigned a = aa[i]; |
| 304 if (0 == a) { | 305 if (0 == a) { |
| 305 continue; | 306 continue; |
| 306 } | 307 } |
| 307 Sk4f d4 = srgb_4b_to_linear_unit(dst[i]); | 308 Sk4f d4 = srgb_4b_to_linear_unit(dst[i]); |
| 308 Sk4f r4; | 309 Sk4f r4; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 464 |
| 464 const LCD32Proc procs[] = { | 465 const LCD32Proc procs[] = { |
| 465 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>, | 466 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>, |
| 466 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>, | 467 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>, |
| 467 | 468 |
| 468 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>, | 469 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>, |
| 469 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>, | 470 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>, |
| 470 }; | 471 }; |
| 471 return procs[flags]; | 472 return procs[flags]; |
| 472 } | 473 } |
| OLD | NEW |