A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2007, 2011 Michael Sevakis
11 *
12 * Shared C code for memory framebuffer LCDs
13 *
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.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "config.h"
24#include "system.h"
25#include "lcd.h"
26#include "lcd-target.h"
27
28/*** Misc. functions ***/
29bool lcd_on SHAREDBSS_ATTR = false;
30
31#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
32bool lcd_active(void)
33{
34 return lcd_on;
35}
36
37/* For use by target driver only! */
38void lcd_set_active(bool active)
39{
40 lcd_on = active;
41}
42
43#else
44#define lcd_on true
45#endif
46
47#ifndef lcd_write_enabled
48#define lcd_write_enabled() lcd_on
49#endif
50
51
52/*** Blitting functions ***/
53
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. */
57extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
58 int width, int height);
59
60#ifndef LCD_OPTIMIZED_UPDATE
61/* Update the display.
62 This must be called after all other LCD functions that change the display. */
63void lcd_update(void)
64{
65 if (!lcd_write_enabled())
66 return;
67
68 /* Copy the Rockbox framebuffer to the second framebuffer */
69 lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), FBADDR(0,0),
70 LCD_WIDTH*LCD_HEIGHT, 1);
71}
72#endif /* LCD_OPTIMIZED_UPDATE */
73
74#ifndef LCD_OPTIMIZED_UPDATE_RECT
75/* Update a fraction of the display. */
76void lcd_update_rect(int x, int y, int width, int height)
77{
78 fb_data *dst, *src;
79
80 if (!lcd_write_enabled())
81 return;
82
83 if (x + width > LCD_WIDTH)
84 width = LCD_WIDTH - x; /* Clip right */
85 if (x < 0)
86 width += x, x = 0; /* Clip left */
87 if (width <= 0)
88 return; /* nothing left to do */
89
90 if (y + height > LCD_HEIGHT)
91 height = LCD_HEIGHT - y; /* Clip bottom */
92 if (y < 0)
93 height += y, y = 0; /* Clip top */
94 if (height <= 0)
95 return; /* nothing left to do */
96
97 dst = LCD_FRAMEBUF_ADDR(x, y);
98 src = FBADDR(x,y);
99
100 /* Copy part of the Rockbox framebuffer to the second framebuffer */
101 if (width < LCD_WIDTH)
102 {
103 /* Not full width - do line-by-line */
104 lcd_copy_buffer_rect(dst, src, width, height);
105 }
106 else
107 {
108 /* Full width - copy as one line */
109 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
110 }
111}
112#endif /* LCD_OPTIMIZED_UPDATE_RECT */
113
114
115/*** YUV functions ***/
116static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
117
118
119/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
120extern void lcd_write_yuv420_lines(fb_data *dst,
121 unsigned char const * const src[3],
122 int width,
123 int stride);
124extern void lcd_write_yuv420_lines_odither(fb_data *dst,
125 unsigned char const * const src[3],
126 int width,
127 int stride,
128 int x_screen, /* To align dither pattern */
129 int y_screen);
130
131void lcd_yuv_set_options(unsigned options)
132{
133 lcd_yuv_options = options;
134}
135
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
139 * boundaries.
140 *
141 * For portrait LCDs, show it rotated counterclockwise by 90 degrees
142 */
143void 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)
146{
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
155#else
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
162#endif
163
164 if (!lcd_write_enabled())
165 return;
166
167 /* Sorry, but width and height must be >= 2 or else */
168 width &= ~1;
169 height >>= 1;
170
171#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
172 /* Adjust portrait coordinates to make (0, 0) the upper right corner */
173 y = LCD_WIDTH - 1 - y;
174#endif
175
176 fb_data *dst = LCD_FRAMEBUF_ADDR_ORIENTED(x, y);
177 int z = stride*src_y;
178
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]);
183
184 if (lcd_yuv_options & LCD_YUV_DITHER)
185 {
186 do
187 {
188 lcd_write_yuv420_lines_odither_oriented(dst, yuv_src, width,
189 stride, x, y);
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();
194 }
195 while (--height > 0);
196 }
197 else
198 {
199 do
200 {
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;
205 YUV_NEXTLINE();
206 }
207 while (--height > 0);
208 }
209}
210#endif /* LCD_OPTIMIZED_BLIT_YUV */