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

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

Issue 1642703003: starter procs for blending with pm4f (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: int to float 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
« src/core/SkPM4fPriv.h ('K') | « src/core/SkXfer4f.h ('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
(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 #include "SkXfer4f.h"
9 #include "SkPM4fPriv.h"
10 #include "SkUtils.h"
11
12 //////////////////////////////////////////////////////////////////////////////// ///////////////////
13
14 void CLEAR_pm41p(uint32_t dst[], const SkPM4f& src, int count) {
mtklein 2016/01/29 15:23:00 pm41p / pm4np is a bit beyond my readability decry
15 sk_bzero(dst, count * sizeof(uint32_t));
16 }
17
18 void CLEAR_pm4np(uint32_t dst[], const SkPM4f src[], int count) {
19 sk_bzero(dst, count * sizeof(uint32_t));
20 }
21
22 //////////
23
24 template <bool isSRGB> void SRC_pm41p(uint32_t dst[], const SkPM4f& src, int cou nt) {
25 uint32_t res;
26 if (isSRGB) {
27 res = Sk4f_toS32(Sk4f::Load(src.fVec));
28 } else {
29 res = Sk4f_toL32(Sk4f::Load(src.fVec));
30 }
31 sk_memset32(dst, res, count);
32 }
33
34 template <bool isSRGB> void SRC_pm4np(uint32_t dst[], const SkPM4f src[], int co unt) {
35 if (isSRGB) {
36 SkPM4f_s32_src_mode(dst, src, count);
37 } else {
38 SkPM4f_l32_src_mode(dst, src, count);
39 }
40 }
41
42 //////////
43
44 void DST_pm41p(uint32_t dst[], const SkPM4f& src, int count) {}
45 void DST_pm4np(uint32_t dst[], const SkPM4f src[], int count) {}
46
47 //////////
48
49 template <bool isSRGB> void SRCOVER_pm41p(uint32_t dst[], const SkPM4f& src, int count) {
50 SkASSERT(src.isUnit());
51 Sk4f s4 = Sk4f::Load(src.fVec);
52 Sk4f scale(1 - s4.kth<SkPM4f::A>());
53
54 if (!isSRGB) {
55 s4 = s4 * Sk4f(255);
mtklein 2016/01/29 15:41:31 I think if we break these problems apart into inde
56 }
57
58 for (int i = 0; i < count; ++i) {
59 if (isSRGB) {
60 Sk4f d4 = Sk4f_fromS32(dst[i]);
61 dst[i] = Sk4f_toS32(s4 + d4 * scale);
62 } else {
63 Sk4f d4 = to_4f(dst[i]);
64 dst[i] = to_4b(s4 + d4 * scale + Sk4f(0.5f));
mtklein 2016/01/29 15:23:00 Add the half to s4 outside the loop too?
65 }
66 }
67 }
68
69 template <bool isSRGB> void SRCOVER_pm4np(uint32_t dst[], const SkPM4f src[], in t count) {
70 if (isSRGB) {
71 SkPM4f_s32_srcover_mode(dst, src, count);
72 } else {
73 SkPM4f_l32_srcover_mode(dst, src, count);
74 }
75 }
76
77 //////////////////////////////////////////////////////////////////////////////// ///////////////////
78
79 struct Pair {
mtklein 2016/01/29 15:23:00 This struct seems a little dangerous without an an
80 SkPM4fXfer1Proc fProc1;
81 SkPM4fXferNProc fProcN;
82 };
83
84 const Pair gClearPairs[] = {
mtklein 2016/01/29 15:23:00 static for all these too?
85 { CLEAR_pm41p, CLEAR_pm4np },
86 { CLEAR_pm41p, CLEAR_pm4np },
87 { CLEAR_pm41p, CLEAR_pm4np },
88 { CLEAR_pm41p, CLEAR_pm4np },
89 };
90
91 const Pair gSrcPairs[] = {
92 { SRC_pm41p<false>, SRC_pm4np<false> }, // linear [alpha ignored]
93 { SRC_pm41p<false>, SRC_pm4np<false> }, // linear [opaque ignored]
94 { SRC_pm41p<true>, SRC_pm4np<true> }, // srgb [alpha ignored]
95 { SRC_pm41p<true>, SRC_pm4np<true> }, // srgb [opaque ignored]
96 };
97
98 const Pair gDstPairs[] = {
99 { DST_pm41p, DST_pm4np },
100 { DST_pm41p, DST_pm4np },
101 { DST_pm41p, DST_pm4np },
102 { DST_pm41p, DST_pm4np },
103 };
104
105 const Pair gSrcOverPairs[] = {
106 { SRCOVER_pm41p<false>, SRCOVER_pm4np<false> }, // linear alpha
107 { SRC_pm41p<false>, SRC_pm4np<false> }, // linear opaque
108 { SRCOVER_pm41p<true>, SRCOVER_pm4np<true> }, // srgb alpha
109 { SRC_pm41p<true>, SRC_pm4np<true> }, // srgb opaque
110 };
111
112 static const Pair* find_pair(SkXfermode::Mode mode, uint32_t flags) {
113 SkASSERT(0 == (flags & ~3));
114 const Pair* pairs = nullptr;
115
116 switch (mode) {
117 case SkXfermode::kClear_Mode: pairs = gClearPairs;
mtklein 2016/01/29 15:23:00 I think you've missed some breaks?
118 case SkXfermode::kSrc_Mode: pairs = gSrcPairs; break;
119 case SkXfermode::kDst_Mode: pairs = gDstPairs;
120 case SkXfermode::kSrcOver_Mode: pairs = gSrcOverPairs; break;
121 default: return nullptr;
122 }
123 return &pairs[flags & 3];
mtklein 2016/01/29 15:23:00 I think this could be a lot simpler if we return P
124 }
125
126 SkPM4fXfer1Proc SkPM4fXfer1ProcFactory(SkXfermode::Mode mode, uint32_t flags) {
127 const Pair* pair = find_pair(mode, flags);
128 return pair ? pair->fProc1 : nullptr;
129 }
130
131 SkPM4fXferNProc SkPM4fXferNProcFactory(SkXfermode::Mode mode, uint32_t flags) {
132 const Pair* pair = find_pair(mode, flags);
133 return pair ? pair->fProcN : nullptr;
134 }
OLDNEW
« src/core/SkPM4fPriv.h ('K') | « src/core/SkXfer4f.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698