1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2007, 2011 Michael Sevakis
12 * Shared C code for memory framebuffer LCDs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
26 #include "lcd-target.h"
28 /*** Misc. functions ***/
29 bool lcd_on SHAREDBSS_ATTR
= false;
31 #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
37 /* For use by target driver only! */
38 void lcd_set_active(bool active
)
47 #ifndef lcd_write_enabled
48 #define lcd_write_enabled() lcd_on
52 /*** Blitting functions ***/
54 /* Copies a rectangle from one framebuffer to another. Can be used in
55 single transfer mode with width = num pixels, and height = 1 which
56 allows a full-width rectangle to be copied more efficiently. */
57 extern void lcd_copy_buffer_rect(fb_data
*dst
, const fb_data
*src
,
58 int width
, int height
);
60 #ifndef LCD_OPTIMIZED_UPDATE
61 /* Update the display.
62 This must be called after all other LCD functions that change the display. */
65 if (!lcd_write_enabled())
68 /* Copy the Rockbox framebuffer to the second framebuffer */
69 lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), &lcd_framebuffer
[0][0],
70 LCD_WIDTH
*LCD_HEIGHT
, 1);
72 #endif /* LCD_OPTIMIZED_UPDATE */
74 #ifndef LCD_OPTIMIZED_UPDATE_RECT
75 /* Update a fraction of the display. */
76 void lcd_update_rect(int x
, int y
, int width
, int height
)
80 if (!lcd_write_enabled())
83 if (x
+ width
> LCD_WIDTH
)
84 width
= LCD_WIDTH
- x
; /* Clip right */
86 width
+= x
, x
= 0; /* Clip left */
88 return; /* nothing left to do */
90 if (y
+ height
> LCD_HEIGHT
)
91 height
= LCD_HEIGHT
- y
; /* Clip bottom */
93 height
+= y
, y
= 0; /* Clip top */
95 return; /* nothing left to do */
97 dst
= LCD_FRAMEBUF_ADDR(x
, y
);
98 src
= &lcd_framebuffer
[y
][x
];
100 /* Copy part of the Rockbox framebuffer to the second framebuffer */
101 if (width
< LCD_WIDTH
)
103 /* Not full width - do line-by-line */
104 lcd_copy_buffer_rect(dst
, src
, width
, height
);
108 /* Full width - copy as one line */
109 lcd_copy_buffer_rect(dst
, src
, LCD_WIDTH
*height
, 1);
112 #endif /* LCD_OPTIMIZED_UPDATE_RECT */
115 /*** YUV functions ***/
116 static unsigned lcd_yuv_options SHAREDBSS_ATTR
= 0;
119 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
120 extern void lcd_write_yuv420_lines(fb_data
*dst
,
121 unsigned char const * const src
[3],
124 extern void lcd_write_yuv420_lines_odither(fb_data
*dst
,
125 unsigned char const * const src
[3],
128 int x_screen
, /* To align dither pattern */
131 void lcd_yuv_set_options(unsigned options
)
133 lcd_yuv_options
= options
;
136 #ifndef LCD_OPTIMIZED_BLIT_YUV
137 /* Performance function to blit a YUV bitmap directly to the LCD
138 * src_x, src_y, width and height should be even and within the LCD's
141 * For portrait LCDs, show it rotated counterclockwise by 90 degrees
143 void lcd_blit_yuv(unsigned char * const src
[3],
144 int src_x
, int src_y
, int stride
,
145 int x
, int y
, int width
, int height
)
147 /* Macrofy the bits that change between orientations */
148 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
149 #define LCD_FRAMEBUF_ADDR_ORIENTED(col, row) \
150 LCD_FRAMEBUF_ADDR(row, col)
151 #define lcd_write_yuv420_lines_odither_oriented(dst, src, w, s, col, row) \
152 lcd_write_yuv420_lines_odither(dst, src, w, s, row, col)
153 #define YUV_NEXTLINE() dst -= 2
154 #define YUV_DITHER_NEXTLINE() dst -= 2, y -= 2
156 #define LCD_FRAMEBUF_ADDR_ORIENTED(col, row) \
157 LCD_FRAMEBUF_ADDR(col, row)
158 #define lcd_write_yuv420_lines_odither_oriented(dst, src, w, s, col, row) \
159 lcd_write_yuv420_lines_odither(dst, src, w, s, col, row)
160 #define YUV_NEXTLINE() dst += 2*LCD_FBWIDTH
161 #define YUV_DITHER_NEXTLINE() dst += 2*LCD_FBWIDTH, y += 2
164 if (!lcd_write_enabled())
167 /* Sorry, but width and height must be >= 2 or else */
171 #if CONFIG_ORIENTATION == SCREEN_PORTRAIT
172 /* Adjust portrait coordinates to make (0, 0) the upper right corner */
173 y
= LCD_WIDTH
- 1 - y
;
176 fb_data
*dst
= LCD_FRAMEBUF_ADDR_ORIENTED(x
, y
);
177 int z
= stride
*src_y
;
179 unsigned char const * yuv_src
[3];
180 yuv_src
[0] = src
[0] + z
+ src_x
;
181 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
182 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
184 if (lcd_yuv_options
& LCD_YUV_DITHER
)
188 lcd_write_yuv420_lines_odither_oriented(dst
, yuv_src
, width
,
190 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
191 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
192 yuv_src
[2] += stride
>> 1;
193 YUV_DITHER_NEXTLINE();
195 while (--height
> 0);
201 lcd_write_yuv420_lines(dst
, yuv_src
, width
, stride
);
202 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
203 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
204 yuv_src
[2] += stride
>> 1;
207 while (--height
> 0);
210 #endif /* LCD_OPTIMIZED_BLIT_YUV */