set SHELL
[qemu] / hw / omap3_lcd_panel_template.h
1 /*
2  * QEMU Epson S1D13744/S1D13745 templates
3  *
4  * Copyright (C) 2008 Nokia Corporation
5  * Written by Andrzej Zaborowski <andrew@openedhand.com>
6  *
7  * QEMU OMAP3 LCD Panel Emulation templates
8  *
9  * Copyright (c) 2008 yajin  <yajin@vm-kernel.org>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 or
14  * (at your option) version 3 of the License.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27
28 #if DEPTH == 8
29 # define PIXEL_TYPE             uint8_t
30 # define COPY_PIXEL1(to, from)  *to ++ = from
31 #elif DEPTH == 15 || DEPTH == 16
32 # define PIXEL_TYPE             uint16_t
33 # define COPY_PIXEL1(to, from)  *to ++ = from
34 #elif DEPTH == 24
35 # define PIXEL_TYPE             uint8_t
36 # define COPY_PIXEL1(to, from)  \
37     *to ++ = from; *to ++ = (from) >> 8; *to ++ = (from) >> 16
38 #elif DEPTH == 32
39 # define PIXEL_TYPE             uint32_t
40 # define COPY_PIXEL1(to, from)  *to ++ = from
41 #else
42 # error unknown bit depth
43 #endif
44
45 #ifdef WORDS_BIGENDIAN
46 # define SWAP_WORDS     1
47 #endif
48
49
50 static void glue(omap3_lcd_panel_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
51                                                       const uint16_t *src,
52                                                       unsigned int width)
53 {
54 #if !defined(SWAP_WORDS) && DEPTH == 16
55     memcpy(dest, src, width);
56 #else
57     uint16_t data;
58     unsigned int r, g, b;
59     const uint16_t *end = (const void *) src + width;
60     while (src < end) {
61         data = lduw_raw(src ++);
62         b = (data & 0x1f) << 3;
63         data >>= 5;
64         g = (data & 0x3f) << 2;
65         data >>= 6;
66         r = (data & 0x1f) << 3;
67         data >>= 5;
68         COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
69     }
70 #endif
71 }
72
73 static void glue(omap3_lcd_panel_draw_line24a_, DEPTH)(PIXEL_TYPE *dest,
74                                                        const uint8_t *src,
75                                                        unsigned int width)
76 {
77 #if !defined(SWAP_WORDS) && DEPTH == 32
78     memcpy(dest, src, width);
79 #else
80     unsigned int r, g, b;
81     const uint8_t *end = (const void *) src + width;
82     while (src < end) {
83         b = *(src++);
84         g = *(src++);
85         r = *(src++);
86         src++;
87         COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
88     }
89 #endif
90 }
91
92 static void glue(omap3_lcd_panel_draw_line24b_, DEPTH)(PIXEL_TYPE *dest,
93                                                        const uint8_t *src,
94                                                        unsigned int width)
95 {
96 #if DEPTH == 24
97     memcpy(dest, src, width);
98 #else
99     unsigned int r, g, b;
100     const uint8_t *end = (const void *) src + width;
101     while (src < end) {
102         b = *(src++);
103         g = *(src++);
104         r = *(src++);
105         COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
106     }
107 #endif
108 }
109
110 /* No rotation */
111 static omap3_lcd_panel_fn_t glue(omap3_lcd_panel_draw_fn_, DEPTH)[0x10] = {
112     NULL,
113     NULL,
114     NULL,
115     NULL,
116     NULL,
117     NULL,
118     (omap3_lcd_panel_fn_t)glue(omap3_lcd_panel_draw_line16_, DEPTH),
119     NULL,
120     (omap3_lcd_panel_fn_t)glue(omap3_lcd_panel_draw_line24a_, DEPTH),
121     (omap3_lcd_panel_fn_t)glue(omap3_lcd_panel_draw_line24b_, DEPTH),
122     NULL,
123     NULL,
124     NULL,
125     NULL,
126     NULL,
127     NULL,
128 };
129
130 /* 90deg, 180deg and 270deg rotation */
131 static omap3_lcd_panel_fn_t glue(omap3_lcd_panel_draw_fn_r_, DEPTH)[0x10] = {
132     /* TODO */
133     [0 ... 0xf] = NULL,
134 };
135
136 #undef DEPTH
137 #undef SKIP_PIXEL
138 #undef COPY_PIXEL
139 #undef COPY_PIXEL1
140 #undef PIXEL_TYPE
141
142 #undef SWAP_WORDS
143
144