Merge commit 'origin/upstream' into juha-devel
[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 #define SKIP_PIXEL(to)          to += deststep
29 #if DEPTH == 8
30 # define PIXEL_TYPE             uint8_t
31 # define COPY_PIXEL(to, from)   *to = from; SKIP_PIXEL(to)
32 # define COPY_PIXEL1(to, from)  *to ++ = from
33 #elif DEPTH == 15 || DEPTH == 16
34 # define PIXEL_TYPE             uint16_t
35 # define COPY_PIXEL(to, from)   *to = from; SKIP_PIXEL(to)
36 # define COPY_PIXEL1(to, from)  *to ++ = from
37 #elif DEPTH == 24
38 # define PIXEL_TYPE             uint8_t
39 # define COPY_PIXEL(to, from)   \
40     to[0] = from; to[1] = (from) >> 8; to[2] = (from) >> 16; SKIP_PIXEL(to)
41 # define COPY_PIXEL1(to, from)  \
42     *to ++ = from; *to ++ = (from) >> 8; *to ++ = (from) >> 16
43 #elif DEPTH == 32
44 # define PIXEL_TYPE             uint32_t
45 # define COPY_PIXEL(to, from)   *to = from; SKIP_PIXEL(to)
46 # define COPY_PIXEL1(to, from)  *to ++ = from
47 #else
48 # error unknown bit depth
49 #endif
50
51 #ifdef WORDS_BIGENDIAN
52 # define SWAP_WORDS     1
53 #endif
54
55
56 static void glue(omap3_lcd_panel_draw_line16_, DEPTH)(PIXEL_TYPE *dest,
57                                                       const uint16_t *src,
58                                                       unsigned int width)
59 {
60 #if !defined(SWAP_WORDS) && DEPTH == 16
61     memcpy(dest, src, width);
62 #else
63     uint16_t data;
64     unsigned int r, g, b;
65     const uint16_t *end = (const void *) src + width;
66     while (src < end) {
67         data = lduw_raw(src ++);
68         b = (data & 0x1f) << 3;
69         data >>= 5;
70         g = (data & 0x3f) << 2;
71         data >>= 6;
72         r = (data & 0x1f) << 3;
73         data >>= 5;
74         COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
75     }
76 #endif
77 }
78
79 static void glue(omap3_lcd_panel_draw_line24a_, DEPTH)(PIXEL_TYPE *dest,
80                                                        const uint8_t *src,
81                                                        unsigned int width)
82 {
83 #if !defined(SWAP_WORDS) && DEPTH == 32
84     memcpy(dest, src, width);
85 #else
86     unsigned int r, g, b;
87     const uint8_t *end = (const void *) src + width;
88     while (src < end) {
89         b = *(src++);
90         g = *(src++);
91         r = *(src++);
92         src++;
93         COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
94     }
95 #endif
96 }
97
98 static void glue(omap3_lcd_panel_draw_line24b_, DEPTH)(PIXEL_TYPE *dest,
99                                                        const uint8_t *src,
100                                                        unsigned int width)
101 {
102 #if DEPTH == 24
103     memcpy(dest, src, width);
104 #else
105     unsigned int r, g, b;
106     const uint8_t *end = (const void *) src + width;
107     while (src < end) {
108         b = *(src++);
109         g = *(src++);
110         r = *(src++);
111         COPY_PIXEL1(dest, glue(rgb_to_pixel, DEPTH)(r, g, b));
112     }
113 #endif
114 }
115
116 /* No rotation */
117 static omap3_lcd_panel_fn_t glue(omap3_lcd_panel_draw_fn_, DEPTH)[0x10] = {
118     NULL,
119     NULL,
120     NULL,
121     NULL,
122     NULL,
123     NULL,
124     (omap3_lcd_panel_fn_t)glue(omap3_lcd_panel_draw_line16_, DEPTH),
125     NULL,
126     (omap3_lcd_panel_fn_t)glue(omap3_lcd_panel_draw_line24a_, DEPTH),
127     (omap3_lcd_panel_fn_t)glue(omap3_lcd_panel_draw_line24b_, DEPTH),
128     NULL,
129     NULL,
130     NULL,
131     NULL,
132     NULL,
133     NULL,
134 };
135
136 /* 90deg, 180deg and 270deg rotation */
137 static omap3_lcd_panel_fn_t glue(omap3_lcd_panel_draw_fn_r_, DEPTH)[0x10] = {
138     /* TODO */
139     [0 ... 0xf] = NULL,
140 };
141
142 #undef DEPTH
143 #undef SKIP_PIXEL
144 #undef COPY_PIXEL
145 #undef COPY_PIXEL1
146 #undef PIXEL_TYPE
147
148 #undef SWAP_WORDS
149
150