1 | // [Blend2D] |
2 | // 2D Vector Graphics Powered by a JIT Compiler. |
3 | // |
4 | // [License] |
5 | // Zlib - See LICENSE.md file in the package. |
6 | |
7 | #ifndef BLEND2D_BLCOMPOP_P_H |
8 | #define BLEND2D_BLCOMPOP_P_H |
9 | |
10 | #include "./blapi-internal_p.h" |
11 | #include "./blcontext.h" |
12 | #include "./blformat_p.h" |
13 | #include "./blpipedefs_p.h" |
14 | #include "./bltables_p.h" |
15 | |
16 | //! \cond INTERNAL |
17 | //! \addtogroup blend2d_internal |
18 | //! \{ |
19 | |
20 | // ============================================================================ |
21 | // [Constants] |
22 | // ============================================================================ |
23 | |
24 | //! Additional composition operators used internally. |
25 | enum BLCompOpInternal : uint32_t { |
26 | //! Set destination alpha to 1 (alpha formats only). |
27 | BL_COMP_OP_INTERNAL_ALPHA_SET = BL_COMP_OP_COUNT, |
28 | //! Invert destination alpha (alpha formats only). |
29 | BL_COMP_OP_INTERNAL_ALPHA_INV, |
30 | //! Count of all composition operators including internal ones.. |
31 | BL_COMP_OP_INTERNAL_COUNT |
32 | }; |
33 | |
34 | //! Simplification of a composition operator that leads to SOLID fill instead. |
35 | enum BLCompOpSolidId : uint32_t { |
36 | //! Source pixels are used. |
37 | //! |
38 | //! \note This value must be zero as it's usually combined with rendering |
39 | //! context flags and then used for decision making about the whole command. |
40 | BL_COMP_OP_SOLID_ID_NONE = 0, |
41 | //! Source pixels are always treated as transparent zero (all 0). |
42 | BL_COMP_OP_SOLID_ID_TRANSPARENT = 1, |
43 | //! Source pixels are always treated as opaque black (R|G|B=0 A=1). |
44 | BL_COMP_OP_SOLID_ID_OPAQUE_BLACK = 2, |
45 | //! Source pixels are always treated as opaque white (R|G|B=1 A=1). |
46 | BL_COMP_OP_SOLID_ID_OPAQUE_WHITE = 3 |
47 | }; |
48 | |
49 | //! Composition operator flags that can be retrieved through BLCompOpInfo[] table. |
50 | enum BLCompOpFlags : uint32_t { |
51 | //! TypeA operator - "D*(1-M) + Op(D, S)*M" == "Op(D, S * M)". |
52 | BL_COMP_OP_FLAG_TYPE_A = 0x00000001u, |
53 | //! TypeB operator - "D*(1-M) + Op(D, S)*M" == "Op(D, S*M) + D*(1-M)". |
54 | BL_COMP_OP_FLAG_TYPE_B = 0x00000002u, |
55 | //! TypeC operator - cannot be simplified. |
56 | BL_COMP_OP_FLAG_TYPE_C = 0x00000004u, |
57 | |
58 | //! Non-separable operator. |
59 | BL_COMP_OP_FLAG_NON_SEPARABLE = 0x00000008u, |
60 | |
61 | //! Uses `Dc` (destination color or luminance channel). |
62 | BL_COMP_OP_FLAG_DC = 0x00000010u, |
63 | //! Uses `Da` (destination alpha channel). |
64 | BL_COMP_OP_FLAG_DA = 0x00000020u, |
65 | //! Uses both `Dc` and `Da`. |
66 | BL_COMP_OP_FLAG_DC_DA = 0x00000030u, |
67 | |
68 | //! Uses `Sc` (source color or luminance channel). |
69 | BL_COMP_OP_FLAG_SC = 0x00000040u, |
70 | //! Uses `Sa` (source alpha channel). |
71 | BL_COMP_OP_FLAG_SA = 0x00000080u, |
72 | //! Uses both `Sc` and `Sa`, |
73 | BL_COMP_OP_FLAG_SC_SA = 0x000000C0u, |
74 | |
75 | //! Destination is never changed (NOP). |
76 | BL_COMP_OP_FLAG_NOP = 0x00000800u, |
77 | //! Destination is changed only if `Da != 0`. |
78 | BL_COMP_OP_FLAG_NOP_IF_DA_0 = 0x00001000u, |
79 | //! Destination is changed only if `Da != 1`. |
80 | BL_COMP_OP_FLAG_NOP_IF_DA_1 = 0x00002000u, |
81 | //! Destination is changed only if `Sa != 0`. |
82 | BL_COMP_OP_FLAG_NOP_IF_SA_0 = 0x00004000u, |
83 | //! Destination is changed only if `Sa != 1`. |
84 | BL_COMP_OP_FLAG_NOP_IF_SA_1 = 0x00008000u |
85 | }; |
86 | |
87 | // ============================================================================ |
88 | // [BLCompOpInfo] |
89 | // ============================================================================ |
90 | |
91 | //! Information about a composition operator. |
92 | struct BLCompOpInfo { |
93 | uint32_t flags; |
94 | }; |
95 | |
96 | //! Provides flags for each composition operator. |
97 | BL_HIDDEN extern const BLLookupTable<BLCompOpInfo, BL_COMP_OP_INTERNAL_COUNT> blCompOpInfo; |
98 | |
99 | // ============================================================================ |
100 | // [BLCompOpSimplifyInfo] |
101 | // ============================================================================ |
102 | |
103 | //! Information that can be used to simplify a "Dst CompOp Src" into a simpler |
104 | //! composition operator with a possible format conversion and arbitrary source |
105 | //! to solid conversion. This is used by the rendering engine to simplify every |
106 | //! composition operator before it considers which pipeline to use. |
107 | //! |
108 | //! There are two reasons for simplification - the first is performance and the |
109 | //! second reason is to decrease the number of possible pipeline signatures the |
110 | //! rendering context may require. For example by using "SRC-COPY" operator |
111 | //! instead of "CLEAR" operator the rendering engine basically eliminated a |
112 | //! possible compilation of "CLEAR" operator that would perform exactly same as |
113 | //! "SRC-COPY". |
114 | struct BLCompOpSimplifyInfo { |
115 | //! Alternative composition operator of the simplified operation. |
116 | uint16_t altCompOp : 6; |
117 | //! Source solid id, see `BLCompOpSolidId`. |
118 | uint16_t srcSolidId : 2; |
119 | //! Destination format of the simplified operation. |
120 | uint16_t dstFormat : 4; |
121 | //! Source format of the simplified operation. |
122 | uint16_t srcFormat : 4; |
123 | }; |
124 | |
125 | // Initially we have used a single table, however, some older compilers would |
126 | // reach template instantiation depth limit (as the table is not small), so the |
127 | // implementation was changed to this instead to make sure this won't happen. |
128 | enum : uint32_t { BL_COMP_OP_SIMPLIFY_RECORD_SIZE = BL_COMP_OP_INTERNAL_COUNT * BL_FORMAT_RESERVED_COUNT }; |
129 | typedef BLLookupTable<BLCompOpSimplifyInfo, BL_COMP_OP_SIMPLIFY_RECORD_SIZE> BLCompOpSimplifyInfoRecordSet; |
130 | |
131 | struct BLCompOpSimplifyInfoTable { BLCompOpSimplifyInfoRecordSet data[BL_FORMAT_COUNT]; }; |
132 | BL_HIDDEN extern const BLCompOpSimplifyInfoTable blCompOpSimplifyInfoTable; |
133 | |
134 | static BL_INLINE const BLCompOpSimplifyInfo* blCompOpSimplifyInfoArrayOf(uint32_t compOp, uint32_t dstFormat) noexcept { |
135 | return &blCompOpSimplifyInfoTable.data[dstFormat][compOp * BL_FORMAT_RESERVED_COUNT]; |
136 | } |
137 | |
138 | static BL_INLINE const BLCompOpSimplifyInfo& blCompOpSimplifyInfo(uint32_t compOp, uint32_t dstFormat, uint32_t srcFormat) noexcept { |
139 | return blCompOpSimplifyInfoArrayOf(compOp, dstFormat)[srcFormat]; |
140 | } |
141 | |
142 | //! \} |
143 | //! \endcond |
144 | |
145 | #endif // BLEND2D_BLCOMPOP_P_H |
146 | |