1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Copyright 2023 Valve Corporation
3*61046927SAndroid Build Coastguard Worker * Copyright 2007 VMware, Inc.
4*61046927SAndroid Build Coastguard Worker * SPDX-License-Identifier: MIT
5*61046927SAndroid Build Coastguard Worker */
6*61046927SAndroid Build Coastguard Worker
7*61046927SAndroid Build Coastguard Worker #ifndef UTIL_BLEND_H
8*61046927SAndroid Build Coastguard Worker #define UTIL_BLEND_H
9*61046927SAndroid Build Coastguard Worker
10*61046927SAndroid Build Coastguard Worker #include <stdbool.h>
11*61046927SAndroid Build Coastguard Worker
12*61046927SAndroid Build Coastguard Worker #define PIPE_BLENDFACTOR_INVERT_BIT (0x10)
13*61046927SAndroid Build Coastguard Worker
14*61046927SAndroid Build Coastguard Worker enum pipe_blendfactor {
15*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_ONE = 1,
16*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_SRC_COLOR,
17*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_SRC_ALPHA,
18*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_DST_ALPHA,
19*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_DST_COLOR,
20*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE,
21*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_CONST_COLOR,
22*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_CONST_ALPHA,
23*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_SRC1_COLOR,
24*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_SRC1_ALPHA,
25*61046927SAndroid Build Coastguard Worker
26*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_ZERO = PIPE_BLENDFACTOR_INVERT_BIT | PIPE_BLENDFACTOR_ONE,
27*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_SRC_COLOR,
28*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_SRC_ALPHA,
29*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_DST_ALPHA,
30*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_DST_COLOR,
31*61046927SAndroid Build Coastguard Worker
32*61046927SAndroid Build Coastguard Worker /* Intentionally weird wrapping due to Gallium trace parsing this file */
33*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_CONST_COLOR = PIPE_BLENDFACTOR_INVERT_BIT
34*61046927SAndroid Build Coastguard Worker | PIPE_BLENDFACTOR_CONST_COLOR,
35*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_CONST_ALPHA,
36*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_SRC1_COLOR,
37*61046927SAndroid Build Coastguard Worker PIPE_BLENDFACTOR_INV_SRC1_ALPHA,
38*61046927SAndroid Build Coastguard Worker };
39*61046927SAndroid Build Coastguard Worker
40*61046927SAndroid Build Coastguard Worker static inline bool
util_blendfactor_is_inverted(enum pipe_blendfactor factor)41*61046927SAndroid Build Coastguard Worker util_blendfactor_is_inverted(enum pipe_blendfactor factor)
42*61046927SAndroid Build Coastguard Worker {
43*61046927SAndroid Build Coastguard Worker /* By construction of the enum */
44*61046927SAndroid Build Coastguard Worker return (factor & PIPE_BLENDFACTOR_INVERT_BIT);
45*61046927SAndroid Build Coastguard Worker }
46*61046927SAndroid Build Coastguard Worker
47*61046927SAndroid Build Coastguard Worker static inline enum pipe_blendfactor
util_blendfactor_without_invert(enum pipe_blendfactor factor)48*61046927SAndroid Build Coastguard Worker util_blendfactor_without_invert(enum pipe_blendfactor factor)
49*61046927SAndroid Build Coastguard Worker {
50*61046927SAndroid Build Coastguard Worker /* By construction of the enum */
51*61046927SAndroid Build Coastguard Worker return (enum pipe_blendfactor)(factor & ~PIPE_BLENDFACTOR_INVERT_BIT);
52*61046927SAndroid Build Coastguard Worker }
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker enum pipe_blend_func {
55*61046927SAndroid Build Coastguard Worker PIPE_BLEND_ADD,
56*61046927SAndroid Build Coastguard Worker PIPE_BLEND_SUBTRACT,
57*61046927SAndroid Build Coastguard Worker PIPE_BLEND_REVERSE_SUBTRACT,
58*61046927SAndroid Build Coastguard Worker PIPE_BLEND_MIN,
59*61046927SAndroid Build Coastguard Worker PIPE_BLEND_MAX,
60*61046927SAndroid Build Coastguard Worker };
61*61046927SAndroid Build Coastguard Worker
62*61046927SAndroid Build Coastguard Worker enum pipe_logicop {
63*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_CLEAR,
64*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_NOR,
65*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_AND_INVERTED,
66*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_COPY_INVERTED,
67*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_AND_REVERSE,
68*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_INVERT,
69*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_XOR,
70*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_NAND,
71*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_AND,
72*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_EQUIV,
73*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_NOOP,
74*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_OR_INVERTED,
75*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_COPY,
76*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_OR_REVERSE,
77*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_OR,
78*61046927SAndroid Build Coastguard Worker PIPE_LOGICOP_SET,
79*61046927SAndroid Build Coastguard Worker };
80*61046927SAndroid Build Coastguard Worker
81*61046927SAndroid Build Coastguard Worker /**
82*61046927SAndroid Build Coastguard Worker * When faking RGBX render target formats with RGBA ones, the blender is still
83*61046927SAndroid Build Coastguard Worker * supposed to treat the destination's alpha channel as 1 instead of the
84*61046927SAndroid Build Coastguard Worker * garbage that's there. Return a blend factor that will take that into
85*61046927SAndroid Build Coastguard Worker * account.
86*61046927SAndroid Build Coastguard Worker */
87*61046927SAndroid Build Coastguard Worker static inline enum pipe_blendfactor
util_blend_dst_alpha_to_one(enum pipe_blendfactor factor)88*61046927SAndroid Build Coastguard Worker util_blend_dst_alpha_to_one(enum pipe_blendfactor factor)
89*61046927SAndroid Build Coastguard Worker {
90*61046927SAndroid Build Coastguard Worker switch (factor) {
91*61046927SAndroid Build Coastguard Worker case PIPE_BLENDFACTOR_DST_ALPHA:
92*61046927SAndroid Build Coastguard Worker return PIPE_BLENDFACTOR_ONE;
93*61046927SAndroid Build Coastguard Worker case PIPE_BLENDFACTOR_INV_DST_ALPHA:
94*61046927SAndroid Build Coastguard Worker return PIPE_BLENDFACTOR_ZERO;
95*61046927SAndroid Build Coastguard Worker default:
96*61046927SAndroid Build Coastguard Worker return factor;
97*61046927SAndroid Build Coastguard Worker }
98*61046927SAndroid Build Coastguard Worker }
99*61046927SAndroid Build Coastguard Worker
100*61046927SAndroid Build Coastguard Worker #endif
101