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

Side by Side Diff: src/effects/gradients/Sk4fGradientPriv.h

Issue 1783823002: Generic 4f gradient T sampler fallback (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review comments Created 4 years, 9 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef Sk4fGradientPriv_DEFINED
9 #define Sk4fGradientPriv_DEFINED
10
11 #include "SkColor.h"
12 #include "SkNx.h"
13 #include "SkPM4f.h"
14
15 // Templates shared by various 4f gradient flavors.
16
17 namespace {
18
19 inline Sk4f premul_4f(const Sk4f& c) {
20 const float alpha = c[SkPM4f::A];
21 // FIXME: portable swizzle?
22 return c * Sk4f(alpha, alpha, alpha, 1);
23 }
24
25 template <bool do_premul>
26 inline SkPMColor trunc_from_255(const Sk4f& c) {
27 SkPMColor pmc;
28 SkNx_cast<uint8_t>(c).store(&pmc);
29 if (do_premul) {
30 pmc = SkPreMultiplyARGB(SkGetPackedA32(pmc), SkGetPackedR32(pmc),
31 SkGetPackedG32(pmc), SkGetPackedB32(pmc));
32 }
33 return pmc;
34 }
35
36 template<typename DstType, bool do_premul>
37 void store(const Sk4f& color, DstType* dst);
38
39 template<>
40 inline void store<SkPM4f, false>(const Sk4f& c, SkPM4f* dst) {
41 c.store(dst);
42 }
43
44 template<>
45 inline void store<SkPM4f, true>(const Sk4f& c, SkPM4f* dst) {
46 store<SkPM4f, false>(premul_4f(c), dst);
47 }
48
49 template<>
50 inline void store<SkPMColor, false>(const Sk4f& c, SkPMColor* dst) {
51 *dst = trunc_from_255<false>(c);
52 }
53
54 template<>
55 inline void store<SkPMColor, true>(const Sk4f& c, SkPMColor* dst) {
56 *dst = trunc_from_255<true>(c);
57 }
58
59 template<typename DstType, bool do_premul>
60 inline void store4x(const Sk4f& c0,
61 const Sk4f& c1,
62 const Sk4f& c2,
63 const Sk4f& c3,
64 DstType* dst) {
65 store<DstType, do_premul>(c0, dst++);
66 store<DstType, do_premul>(c1, dst++);
67 store<DstType, do_premul>(c2, dst++);
68 store<DstType, do_premul>(c3, dst++);
69 }
70
71 template<>
72 inline void store4x<SkPMColor, false>(const Sk4f& c0,
73 const Sk4f& c1,
74 const Sk4f& c2,
75 const Sk4f& c3,
76 SkPMColor* dst) {
77 Sk4f_ToBytes((uint8_t*)dst, c0, c1, c2, c3);
78 }
79
80 template<typename DstType>
81 float dst_component_scale();
82
83 template<>
84 inline float dst_component_scale<SkPM4f>() {
85 return 1;
86 }
87
88 template<>
89 inline float dst_component_scale<SkPMColor>() {
90 return 255;
91 }
92
93 template<typename DstType>
94 Sk4f dst_swizzle(const SkPM4f&);
95
96 template<>
97 inline Sk4f dst_swizzle<SkPM4f>(const SkPM4f& c) {
98 return c.to4f();
99 }
100
101 template<>
102 inline Sk4f dst_swizzle<SkPMColor>(const SkPM4f& c) {
103 return c.to4f_pmorder();
104 }
105
106 }
107
108 #endif // Sk4fGradientPriv_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698