root / hw / pl110_template.h @ 50132156
History | View | Annotate | Download (7 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | bdd5003a | pbrook | * Arm PrimeCell PL110 Color LCD Controller
|
3 | bdd5003a | pbrook | *
|
4 | bdd5003a | pbrook | * Copyright (c) 2005 CodeSourcery, LLC.
|
5 | bdd5003a | pbrook | * Written by Paul Brook
|
6 | bdd5003a | pbrook | *
|
7 | bdd5003a | pbrook | * This code is licenced under the GNU LGPL
|
8 | bdd5003a | pbrook | *
|
9 | bdd5003a | pbrook | * Framebuffer format conversion routines.
|
10 | bdd5003a | pbrook | */
|
11 | bdd5003a | pbrook | |
12 | bdd5003a | pbrook | #ifndef ORDER
|
13 | bdd5003a | pbrook | |
14 | bdd5003a | pbrook | #if BITS == 8 |
15 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(to++) = from
|
16 | bdd5003a | pbrook | #elif BITS == 15 || BITS == 16 |
17 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2; |
18 | 5fafdf24 | ths | #elif BITS == 24 |
19 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) \
|
20 | bdd5003a | pbrook | *(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16 |
21 | bdd5003a | pbrook | #elif BITS == 32 |
22 | bdd5003a | pbrook | #define COPY_PIXEL(to, from) *(uint32_t *)to = from; to += 4; |
23 | bdd5003a | pbrook | #else
|
24 | bdd5003a | pbrook | #error unknown bit depth
|
25 | bdd5003a | pbrook | #endif
|
26 | bdd5003a | pbrook | |
27 | e9c05b42 | balrog | #undef RGB
|
28 | e9c05b42 | balrog | #define BORDER bgr
|
29 | bdd5003a | pbrook | #define ORDER 0 |
30 | bdd5003a | pbrook | #include "pl110_template.h" |
31 | bdd5003a | pbrook | #define ORDER 1 |
32 | bdd5003a | pbrook | #include "pl110_template.h" |
33 | bdd5003a | pbrook | #define ORDER 2 |
34 | bdd5003a | pbrook | #include "pl110_template.h" |
35 | e9c05b42 | balrog | #undef BORDER
|
36 | e9c05b42 | balrog | #define RGB
|
37 | e9c05b42 | balrog | #define BORDER rgb
|
38 | e9c05b42 | balrog | #define ORDER 0 |
39 | e9c05b42 | balrog | #include "pl110_template.h" |
40 | e9c05b42 | balrog | #define ORDER 1 |
41 | e9c05b42 | balrog | #include "pl110_template.h" |
42 | e9c05b42 | balrog | #define ORDER 2 |
43 | e9c05b42 | balrog | #include "pl110_template.h" |
44 | e9c05b42 | balrog | #undef BORDER
|
45 | bdd5003a | pbrook | |
46 | e9c05b42 | balrog | static drawfn glue(pl110_draw_fn_,BITS)[36] = |
47 | bdd5003a | pbrook | { |
48 | e9c05b42 | balrog | glue(pl110_draw_line1_lblp_bgr,BITS), |
49 | e9c05b42 | balrog | glue(pl110_draw_line2_lblp_bgr,BITS), |
50 | e9c05b42 | balrog | glue(pl110_draw_line4_lblp_bgr,BITS), |
51 | e9c05b42 | balrog | glue(pl110_draw_line8_lblp_bgr,BITS), |
52 | e9c05b42 | balrog | glue(pl110_draw_line16_lblp_bgr,BITS), |
53 | e9c05b42 | balrog | glue(pl110_draw_line32_lblp_bgr,BITS), |
54 | e9c05b42 | balrog | |
55 | e9c05b42 | balrog | glue(pl110_draw_line1_bbbp_bgr,BITS), |
56 | e9c05b42 | balrog | glue(pl110_draw_line2_bbbp_bgr,BITS), |
57 | e9c05b42 | balrog | glue(pl110_draw_line4_bbbp_bgr,BITS), |
58 | e9c05b42 | balrog | glue(pl110_draw_line8_bbbp_bgr,BITS), |
59 | e9c05b42 | balrog | glue(pl110_draw_line16_bbbp_bgr,BITS), |
60 | e9c05b42 | balrog | glue(pl110_draw_line32_bbbp_bgr,BITS), |
61 | e9c05b42 | balrog | |
62 | e9c05b42 | balrog | glue(pl110_draw_line1_lbbp_bgr,BITS), |
63 | e9c05b42 | balrog | glue(pl110_draw_line2_lbbp_bgr,BITS), |
64 | e9c05b42 | balrog | glue(pl110_draw_line4_lbbp_bgr,BITS), |
65 | e9c05b42 | balrog | glue(pl110_draw_line8_lbbp_bgr,BITS), |
66 | e9c05b42 | balrog | glue(pl110_draw_line16_lbbp_bgr,BITS), |
67 | e9c05b42 | balrog | glue(pl110_draw_line32_lbbp_bgr,BITS), |
68 | e9c05b42 | balrog | |
69 | e9c05b42 | balrog | glue(pl110_draw_line1_lblp_rgb,BITS), |
70 | e9c05b42 | balrog | glue(pl110_draw_line2_lblp_rgb,BITS), |
71 | e9c05b42 | balrog | glue(pl110_draw_line4_lblp_rgb,BITS), |
72 | e9c05b42 | balrog | glue(pl110_draw_line8_lblp_rgb,BITS), |
73 | e9c05b42 | balrog | glue(pl110_draw_line16_lblp_rgb,BITS), |
74 | e9c05b42 | balrog | glue(pl110_draw_line32_lblp_rgb,BITS), |
75 | e9c05b42 | balrog | |
76 | e9c05b42 | balrog | glue(pl110_draw_line1_bbbp_rgb,BITS), |
77 | e9c05b42 | balrog | glue(pl110_draw_line2_bbbp_rgb,BITS), |
78 | e9c05b42 | balrog | glue(pl110_draw_line4_bbbp_rgb,BITS), |
79 | e9c05b42 | balrog | glue(pl110_draw_line8_bbbp_rgb,BITS), |
80 | e9c05b42 | balrog | glue(pl110_draw_line16_bbbp_rgb,BITS), |
81 | e9c05b42 | balrog | glue(pl110_draw_line32_bbbp_rgb,BITS), |
82 | e9c05b42 | balrog | |
83 | e9c05b42 | balrog | glue(pl110_draw_line1_lbbp_rgb,BITS), |
84 | e9c05b42 | balrog | glue(pl110_draw_line2_lbbp_rgb,BITS), |
85 | e9c05b42 | balrog | glue(pl110_draw_line4_lbbp_rgb,BITS), |
86 | e9c05b42 | balrog | glue(pl110_draw_line8_lbbp_rgb,BITS), |
87 | e9c05b42 | balrog | glue(pl110_draw_line16_lbbp_rgb,BITS), |
88 | e9c05b42 | balrog | glue(pl110_draw_line32_lbbp_rgb,BITS), |
89 | bdd5003a | pbrook | }; |
90 | bdd5003a | pbrook | |
91 | bdd5003a | pbrook | #undef BITS
|
92 | bdd5003a | pbrook | #undef COPY_PIXEL
|
93 | bdd5003a | pbrook | |
94 | bdd5003a | pbrook | #else
|
95 | bdd5003a | pbrook | |
96 | bdd5003a | pbrook | #if ORDER == 0 |
97 | e9c05b42 | balrog | #define NAME glue(glue(lblp_, BORDER), BITS)
|
98 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
99 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
100 | bdd5003a | pbrook | #endif
|
101 | bdd5003a | pbrook | #elif ORDER == 1 |
102 | e9c05b42 | balrog | #define NAME glue(glue(bbbp_, BORDER), BITS)
|
103 | e2542fe2 | Juan Quintela | #ifndef HOST_WORDS_BIGENDIAN
|
104 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
105 | bdd5003a | pbrook | #endif
|
106 | bdd5003a | pbrook | #else
|
107 | bdd5003a | pbrook | #define SWAP_PIXELS 1 |
108 | e9c05b42 | balrog | #define NAME glue(glue(lbbp_, BORDER), BITS)
|
109 | e2542fe2 | Juan Quintela | #ifdef HOST_WORDS_BIGENDIAN
|
110 | bdd5003a | pbrook | #define SWAP_WORDS 1 |
111 | bdd5003a | pbrook | #endif
|
112 | bdd5003a | pbrook | #endif
|
113 | bdd5003a | pbrook | |
114 | bdd5003a | pbrook | #define FN_2(x, y) FN(x, y) FN(x+1, y) |
115 | 1f9519c9 | pbrook | #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y) |
116 | bdd5003a | pbrook | #define FN_8(y) FN_4(0, y) FN_4(4, y) |
117 | bdd5003a | pbrook | |
118 | 714fa308 | pbrook | static void glue(pl110_draw_line1_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
119 | bdd5003a | pbrook | { |
120 | 714fa308 | pbrook | uint32_t *pallette = opaque; |
121 | bdd5003a | pbrook | uint32_t data; |
122 | bdd5003a | pbrook | while (width > 0) { |
123 | bdd5003a | pbrook | data = *(uint32_t *)src; |
124 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
125 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 7 - (x))) & 1]); |
126 | bdd5003a | pbrook | #else
|
127 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x) + y)) & 1]); |
128 | bdd5003a | pbrook | #endif
|
129 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
130 | bdd5003a | pbrook | FN_8(24)
|
131 | bdd5003a | pbrook | FN_8(16)
|
132 | bdd5003a | pbrook | FN_8(8)
|
133 | bdd5003a | pbrook | FN_8(0)
|
134 | bdd5003a | pbrook | #else
|
135 | bdd5003a | pbrook | FN_8(0)
|
136 | bdd5003a | pbrook | FN_8(8)
|
137 | bdd5003a | pbrook | FN_8(16)
|
138 | bdd5003a | pbrook | FN_8(24)
|
139 | bdd5003a | pbrook | #endif
|
140 | bdd5003a | pbrook | #undef FN
|
141 | bdd5003a | pbrook | width -= 32;
|
142 | bdd5003a | pbrook | src += 4;
|
143 | bdd5003a | pbrook | } |
144 | bdd5003a | pbrook | } |
145 | bdd5003a | pbrook | |
146 | 714fa308 | pbrook | static void glue(pl110_draw_line2_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
147 | bdd5003a | pbrook | { |
148 | 714fa308 | pbrook | uint32_t *pallette = opaque; |
149 | bdd5003a | pbrook | uint32_t data; |
150 | bdd5003a | pbrook | while (width > 0) { |
151 | bdd5003a | pbrook | data = *(uint32_t *)src; |
152 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
153 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 6 - (x)*2)) & 3]); |
154 | bdd5003a | pbrook | #else
|
155 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*2 + y)) & 3]); |
156 | bdd5003a | pbrook | #endif
|
157 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
158 | bdd5003a | pbrook | FN_4(0, 24) |
159 | bdd5003a | pbrook | FN_4(0, 16) |
160 | bdd5003a | pbrook | FN_4(0, 8) |
161 | bdd5003a | pbrook | FN_4(0, 0) |
162 | bdd5003a | pbrook | #else
|
163 | bdd5003a | pbrook | FN_4(0, 0) |
164 | bdd5003a | pbrook | FN_4(0, 8) |
165 | bdd5003a | pbrook | FN_4(0, 16) |
166 | bdd5003a | pbrook | FN_4(0, 24) |
167 | bdd5003a | pbrook | #endif
|
168 | bdd5003a | pbrook | #undef FN
|
169 | bdd5003a | pbrook | width -= 16;
|
170 | bdd5003a | pbrook | src += 4;
|
171 | bdd5003a | pbrook | } |
172 | bdd5003a | pbrook | } |
173 | bdd5003a | pbrook | |
174 | 714fa308 | pbrook | static void glue(pl110_draw_line4_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
175 | bdd5003a | pbrook | { |
176 | 714fa308 | pbrook | uint32_t *pallette = opaque; |
177 | bdd5003a | pbrook | uint32_t data; |
178 | bdd5003a | pbrook | while (width > 0) { |
179 | bdd5003a | pbrook | data = *(uint32_t *)src; |
180 | bdd5003a | pbrook | #ifdef SWAP_PIXELS
|
181 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> (y + 4 - (x)*4)) & 0xf]); |
182 | bdd5003a | pbrook | #else
|
183 | bdd5003a | pbrook | #define FN(x, y) COPY_PIXEL(d, pallette[(data >> ((x)*4 + y)) & 0xf]); |
184 | bdd5003a | pbrook | #endif
|
185 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
186 | bdd5003a | pbrook | FN_2(0, 24) |
187 | bdd5003a | pbrook | FN_2(0, 16) |
188 | bdd5003a | pbrook | FN_2(0, 8) |
189 | bdd5003a | pbrook | FN_2(0, 0) |
190 | bdd5003a | pbrook | #else
|
191 | bdd5003a | pbrook | FN_2(0, 0) |
192 | bdd5003a | pbrook | FN_2(0, 8) |
193 | bdd5003a | pbrook | FN_2(0, 16) |
194 | bdd5003a | pbrook | FN_2(0, 24) |
195 | bdd5003a | pbrook | #endif
|
196 | bdd5003a | pbrook | #undef FN
|
197 | bdd5003a | pbrook | width -= 8;
|
198 | bdd5003a | pbrook | src += 4;
|
199 | bdd5003a | pbrook | } |
200 | bdd5003a | pbrook | } |
201 | bdd5003a | pbrook | |
202 | 714fa308 | pbrook | static void glue(pl110_draw_line8_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
203 | bdd5003a | pbrook | { |
204 | 714fa308 | pbrook | uint32_t *pallette = opaque; |
205 | bdd5003a | pbrook | uint32_t data; |
206 | bdd5003a | pbrook | while (width > 0) { |
207 | bdd5003a | pbrook | data = *(uint32_t *)src; |
208 | bdd5003a | pbrook | #define FN(x) COPY_PIXEL(d, pallette[(data >> (x)) & 0xff]); |
209 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
210 | bdd5003a | pbrook | FN(24)
|
211 | bdd5003a | pbrook | FN(16)
|
212 | bdd5003a | pbrook | FN(8)
|
213 | bdd5003a | pbrook | FN(0)
|
214 | bdd5003a | pbrook | #else
|
215 | bdd5003a | pbrook | FN(0)
|
216 | bdd5003a | pbrook | FN(8)
|
217 | bdd5003a | pbrook | FN(16)
|
218 | bdd5003a | pbrook | FN(24)
|
219 | bdd5003a | pbrook | #endif
|
220 | bdd5003a | pbrook | #undef FN
|
221 | bdd5003a | pbrook | width -= 4;
|
222 | bdd5003a | pbrook | src += 4;
|
223 | bdd5003a | pbrook | } |
224 | bdd5003a | pbrook | } |
225 | bdd5003a | pbrook | |
226 | 714fa308 | pbrook | static void glue(pl110_draw_line16_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
227 | bdd5003a | pbrook | { |
228 | bdd5003a | pbrook | uint32_t data; |
229 | bdd5003a | pbrook | unsigned int r, g, b; |
230 | bdd5003a | pbrook | while (width > 0) { |
231 | bdd5003a | pbrook | data = *(uint32_t *)src; |
232 | be9d3657 | pbrook | #ifdef SWAP_WORDS
|
233 | bdd5003a | pbrook | data = bswap32(data); |
234 | bdd5003a | pbrook | #endif
|
235 | e9c05b42 | balrog | #ifdef RGB
|
236 | e9c05b42 | balrog | #define LSB r
|
237 | e9c05b42 | balrog | #define MSB b
|
238 | e9c05b42 | balrog | #else
|
239 | e9c05b42 | balrog | #define LSB b
|
240 | e9c05b42 | balrog | #define MSB r
|
241 | e9c05b42 | balrog | #endif
|
242 | bdd5003a | pbrook | #if 0
|
243 | e9c05b42 | balrog | LSB = data & 0x1f;
|
244 | bdd5003a | pbrook | data >>= 5;
|
245 | bdd5003a | pbrook | g = data & 0x3f;
|
246 | bdd5003a | pbrook | data >>= 6;
|
247 | e9c05b42 | balrog | MSB = data & 0x1f;
|
248 | bdd5003a | pbrook | data >>= 5;
|
249 | bdd5003a | pbrook | #else
|
250 | e9c05b42 | balrog | LSB = (data & 0x1f) << 3; |
251 | bdd5003a | pbrook | data >>= 5;
|
252 | bdd5003a | pbrook | g = (data & 0x3f) << 2; |
253 | bdd5003a | pbrook | data >>= 6;
|
254 | e9c05b42 | balrog | MSB = (data & 0x1f) << 3; |
255 | bdd5003a | pbrook | data >>= 5;
|
256 | bdd5003a | pbrook | #endif
|
257 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
258 | e9c05b42 | balrog | LSB = (data & 0x1f) << 3; |
259 | bdd5003a | pbrook | data >>= 5;
|
260 | bdd5003a | pbrook | g = (data & 0x3f) << 2; |
261 | bdd5003a | pbrook | data >>= 6;
|
262 | e9c05b42 | balrog | MSB = (data & 0x1f) << 3; |
263 | bdd5003a | pbrook | data >>= 5;
|
264 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
265 | e9c05b42 | balrog | #undef MSB
|
266 | e9c05b42 | balrog | #undef LSB
|
267 | bdd5003a | pbrook | width -= 2;
|
268 | bdd5003a | pbrook | src += 4;
|
269 | bdd5003a | pbrook | } |
270 | bdd5003a | pbrook | } |
271 | bdd5003a | pbrook | |
272 | 714fa308 | pbrook | static void glue(pl110_draw_line32_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep) |
273 | bdd5003a | pbrook | { |
274 | bdd5003a | pbrook | uint32_t data; |
275 | bdd5003a | pbrook | unsigned int r, g, b; |
276 | bdd5003a | pbrook | while (width > 0) { |
277 | bdd5003a | pbrook | data = *(uint32_t *)src; |
278 | e9c05b42 | balrog | #ifdef RGB
|
279 | e9c05b42 | balrog | #define LSB r
|
280 | e9c05b42 | balrog | #define MSB b
|
281 | e9c05b42 | balrog | #else
|
282 | e9c05b42 | balrog | #define LSB b
|
283 | e9c05b42 | balrog | #define MSB r
|
284 | e9c05b42 | balrog | #endif
|
285 | 399a4e21 | Paul Brook | #ifndef SWAP_WORDS
|
286 | e9c05b42 | balrog | LSB = data & 0xff;
|
287 | bdd5003a | pbrook | g = (data >> 8) & 0xff; |
288 | e9c05b42 | balrog | MSB = (data >> 16) & 0xff; |
289 | bdd5003a | pbrook | #else
|
290 | e9c05b42 | balrog | LSB = (data >> 24) & 0xff; |
291 | bdd5003a | pbrook | g = (data >> 16) & 0xff; |
292 | e9c05b42 | balrog | MSB = (data >> 8) & 0xff; |
293 | bdd5003a | pbrook | #endif
|
294 | bdd5003a | pbrook | COPY_PIXEL(d, glue(rgb_to_pixel,BITS)(r, g, b)); |
295 | e9c05b42 | balrog | #undef MSB
|
296 | e9c05b42 | balrog | #undef LSB
|
297 | bdd5003a | pbrook | width--; |
298 | bdd5003a | pbrook | src += 4;
|
299 | bdd5003a | pbrook | } |
300 | bdd5003a | pbrook | } |
301 | bdd5003a | pbrook | |
302 | bdd5003a | pbrook | #undef SWAP_PIXELS
|
303 | bdd5003a | pbrook | #undef NAME
|
304 | bdd5003a | pbrook | #undef SWAP_WORDS
|
305 | bdd5003a | pbrook | #undef ORDER
|
306 | bdd5003a | pbrook | |
307 | bdd5003a | pbrook | #endif |