1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can
5  * be found in the LICENSE file.
6  *
7  */
8 
9 #ifndef SKC_ONCE_STYLING_TYPES
10 #define SKC_ONCE_STYLING_TYPES
11 
12 //
13 //
14 //
15 
16 #include "types.h"
17 #include "macros.h"
18 #include "skc_styling.h"
19 
20 //
21 //
22 //
23 
24 typedef skc_uint  skc_layer_id;
25 typedef skc_uint  skc_group_id;
26 
27 //
28 //
29 //
30 
31 union skc_styling_cmd
32 {
33   skc_uint                    u32;
34   skc_int                     s32;
35   skc_float                   f32;
36   skc_half                    f16a2[2];
37   skc_ushort2                 u16v2;
38   skc_styling_opcode_e        opcode;
39   skc_styling_gradient_type_e gradient_type;
40   skc_group_id                parent;
41 
42 #if 0
43 #if !defined(__OPENCL_C_VERSION__)
44   struct {
45     skc_uint                  opcode : 31;
46     skc_uint                  final  : 1;
47   };
48 #endif
49 #endif
50 };
51 
52 #define SKC_STYLING_OPCODE_MASK_OPCODE    SKC_BITS_TO_MASK(31)
53 #define SKC_STYLING_OPCODE_MASK_IS_FINAL  SKC_BITS_TO_MASK_AT(1,31)
54 
55 SKC_STATIC_ASSERT(sizeof(union skc_styling_cmd) == sizeof(skc_uint));
56 
57 //
58 //
59 //
60 
61 union skc_layer_node
62 {
63   skc_uint2      u32v2;
64 
65   struct {
66     skc_uint     cmds;   // starting index of sequence of command words
67     skc_group_id parent; // index of parent group
68   };
69 };
70 
71 SKC_STATIC_ASSERT(sizeof(union skc_layer_node) == sizeof(skc_uint2));
72 
73 //
74 //
75 //
76 
77 union skc_group_parents
78 {
79   skc_uint2  u32v2;
80 
81   struct {
82     skc_uint depth;
83     skc_uint base;
84   };
85 };
86 
87 SKC_STATIC_ASSERT(sizeof(union skc_group_parents) == sizeof(skc_uint2));
88 
89 //
90 // inclusive layer range [lo,hi]
91 //
92 
93 union skc_group_range
94 {
95   skc_uint2  u32v2;
96 
97   struct {
98     skc_uint lo; // first layer
99     skc_uint hi; // last  layer
100   };
101 };
102 
103 SKC_STATIC_ASSERT(sizeof(union skc_group_range) == sizeof(skc_uint2));
104 
105 //
106 //
107 //
108 
109 struct skc_group_node
110 {
111   union skc_group_parents parents; // path of parent groups leading back to root
112 
113   union skc_group_range   range;   // range of layers enclosed by this group
114 
115   struct {
116     skc_uint              enter;   // starting index of sequence of command words
117     skc_uint              leave;   // starting index of sequence of command words
118   } cmds;
119 };
120 
121 SKC_STATIC_ASSERT(sizeof(struct skc_group_node) == sizeof(skc_uint2) * 3); // 6 words
122 
123 //
124 //
125 //
126 
127 union skc_gradient_slope
128 {
129   skc_float  slope;
130   skc_half   color_pair[2];
131 };
132 
133 SKC_STATIC_ASSERT(sizeof(union skc_gradient_slope) == sizeof(skc_float));
134 
135 //
136 //
137 //
138 
139 union skc_gradient_vector
140 {
141   skc_float4               f32v4;
142 
143   struct {
144     skc_float              dx;
145     skc_float              p0;
146     skc_float              dy;
147     skc_float              denom;
148   };
149 
150   union skc_gradient_slope slopes[4];
151 };
152 
153 SKC_STATIC_ASSERT(sizeof(union skc_gradient_vector) == sizeof(skc_float4));
154 
155 //
156 // FIXME -- will eventually need to know if this gradient is
157 // perspective transformed and if so additional values will need to be
158 // encoded
159 //
160 // VERSION 1
161 // =============================================================
162 //
163 // LINEAR GRADIENT HEADER FOR N STOPS
164 //
165 // +----------+----------+------------+----------+-------------+
166 // |  HEADER  |   INFO   |    LUTS    |  FLOORS  |    COLORS   |
167 // +----------+----------+------------+----------+-------------+
168 // |  uintv4  | u32v2[1] | f32v2[N-1] | f32[N-2] | ushort2[4N] |
169 // +----------+----------+------------+----------+-------------+
170 //
171 //   COLOR PAIR            WORD EXPANSION            TOTAL
172 // +------------+---------------------------------+--------+-------------------------+
173 // |  ushort2   |  4 + 2 + 2*(N-1) + N - 2 + 4*N  | 7N + 2 | = 7(N-1+1)+2 = 7(N-1)+9 |
174 // +------------+---------------------------------+--------+-------------------------+
175 //
176 // COLOR LAYOUT:
177 //
178 //   R[0]R[1], R[1]R[2], ... R[N-1]R[N-1]
179 //   G[0]G[1], G[1]G[2], ... G[N-1]G[N-1]
180 //   B[0]B[1], B[1]B[2], ... B[N-1]B[N-1]
181 //   A[0]A[1], A[1]A[2], ... A[N-1]A[N-1]
182 //
183 //
184 // MINIMUM WORDS:  N=2 --> 16
185 //
186 //
187 // VERSION 2
188 // =============================================================
189 //
190 // LINEAR GRADIENT DESCRIPTOR FOR N STOPS
191 //
192 //                           +--------------- REMOVE ME LATER
193 //                           v
194 // +--------+------+-------+---+----------+-----------+
195 // | VECTOR | TYPE | COUNT | N |  SLOPES  |   COLORS  |
196 // +--------+------+-------+---+----------+-----------+
197 // |  f32v4 |   1  |   1   | 1 | f32[N-1] | f16v2[4N] |
198 // +--------+------+-------+---+----------+-----------+
199 //
200 //   COLOR PAIR           WORD EXPANSION            TOTAL
201 // +------------+--------------------------------+--------+
202 // |   f16v2    |  4 + 1 + 1 + 1 + [N-1] + [4*N] | 5N + 6 |
203 // +------------+--------------------------------+--------+
204 //
205 // COLOR LAYOUT:
206 //
207 //   R[0]R[1], R[1]R[2], ... R[N-1]R[N-1] <-------------------------- FIXME -- USE HERB'S SINGLE FMA REPRESENTATION
208 //   G[0]G[1], G[1]G[2], ... G[N-1]G[N-1] <-------------------------- FIXME -- USE HERB'S SINGLE FMA REPRESENTATION
209 //   B[0]B[1], B[1]B[2], ... B[N-1]B[N-1] <-------------------------- FIXME -- USE HERB'S SINGLE FMA REPRESENTATION
210 //   A[0]A[1], A[1]A[2], ... A[N-1]A[N-1] <-------------------------- FIXME -- USE HERB'S SINGLE FMA REPRESENTATION
211 //
212 //
213 // MINIMUM WORDS:  N=2 --> 16
214 //
215 //
216 // VERSION 3+
217 // =============================================================
218 //
219 // FIXME -- will probably want to try using the sampler/texture
220 // hardware to interpolate colors.
221 //
222 // This will require that the colors are laid out in sampler-friendly
223 // order:
224 //
225 //    RGBA[0]RGBA[1], RGBA[1]RGBA[2], ..., RGBA[N-1]RGBA[N-1]
226 //
227 //
228 
229 #if 0
230 #define SKC_GRADIENT_HEADER_WORDS_LUTS_OFFSET       4
231 #define SKC_GRADIENT_HEADER_WORDS_TOTAL(n_minus_1)  (7 * (n_minus_1) + 9)
232 #define SKC_GRADIENT_HEADER_WORDS_MIN               SKC_GRADIENT_HEADER_WORDS_TOTAL(1)
233 #define SKC_GRADIENT_CMD_WORDS_V1(n)                (1 + SKC_GRADIENT_HEADER_WORDS_TOTAL(n-1))
234 #endif
235 
236 #define SKC_GRADIENT_CMD_WORDS_V1(n)                (7 * (n) + 2)
237 #define SKC_GRADIENT_CMD_WORDS_V2(n)                (5 * (n) + 6)
238 #define SKC_GRADIENT_CMD_WORDS_V2_ADJUST(v1,v2)     (SKC_GRADIENT_CMD_WORDS_V1(v1) - ((v2) + 6))
239 
240 //
241 //
242 //
243 
244 #endif
245 
246 //
247 //
248 //
249