blob: c85848c18bb63225950df52c860668a741f143df [file] [log] [blame]
Daniel Stenbergd20e6ee2002-03-26 10:06:28 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
Daniel Stenberg319d1f32002-03-26 10:59:39 +000020#include <stdio.h>
21#include <string.h>
22#include <stdarg.h>
23#include <stdlib.h>
24#include <ctype.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28
29#include <errno.h>
30#include <ctype.h>
31#include <time.h>
32
33#include "screenhack.h"
Björn Stenberg8b695042004-09-16 14:36:08 +000034#include "config.h"
Dan Everton3ba00602006-02-13 21:46:28 +000035#include "debug.h"
Daniel Stenberg319d1f32002-03-26 10:59:39 +000036
Daniel Stenbergd20e6ee2002-03-26 10:06:28 +000037/*
Daniel Stenberg319d1f32002-03-26 10:59:39 +000038 * Specific implementations for X11, using the generic LCD API and data.
Daniel Stenbergd20e6ee2002-03-26 10:06:28 +000039 */
40
Daniel Stenberga1fd2552002-03-26 14:27:03 +000041#include "lcd-x11.h"
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +000042#include "lcd-playersim.h"
Daniel Stenberg319d1f32002-03-26 10:59:39 +000043
Jens Arnoldf894a4c2005-07-06 22:58:02 +000044#if LCD_DEPTH == 2
45#define YBLOCK 4
Daniel Stenberg98728132005-07-14 10:02:04 +000046#define ANDBIT 3 /* AND with this to get the color number */
Jens Arnoldf894a4c2005-07-06 22:58:02 +000047#else
48#define YBLOCK 8
Daniel Stenberg98728132005-07-14 10:02:04 +000049#define ANDBIT 1
Jens Arnoldf894a4c2005-07-06 22:58:02 +000050#endif
51
Björn Stenbergf9429cc2002-04-19 12:55:12 +000052extern void screen_resized(int width, int height);
Jens Arnold48be8e62005-10-23 23:49:46 +000053extern bool lcd_display_redraw;
Daniel Stenberg319d1f32002-03-26 10:59:39 +000054
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +000055#ifdef HAVE_LCD_BITMAP
Dave Chapmanfca01132005-11-14 02:11:26 +000056#if LCD_DEPTH==16
Daniel Stenberg95c00322005-11-17 07:17:03 +000057fb_data lcd_framebuffer_copy[LCD_HEIGHT][LCD_WIDTH*2];
Dave Chapmanfca01132005-11-14 02:11:26 +000058#else
Daniel Stenberg95c00322005-11-17 07:17:03 +000059fb_data lcd_framebuffer_copy[LCD_HEIGHT/YBLOCK][LCD_WIDTH];
Dave Chapmanfca01132005-11-14 02:11:26 +000060#endif
Daniel Stenbergc1543512002-04-27 23:41:41 +000061
Daniel Stenberg319d1f32002-03-26 10:59:39 +000062void lcd_update (void)
63{
Daniel Stenberg98728132005-07-14 10:02:04 +000064 /* update a full screen rect */
65 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
Daniel Stenbergcd864072002-09-10 07:07:44 +000066}
67
68void lcd_update_rect(int x_start, int y_start,
69 int width, int height)
70{
71 int x;
72 int yline=y_start;
73 int y;
74 int p=0;
75 int bit;
Daniel Stenbergcd864072002-09-10 07:07:44 +000076 int xmax;
77 int ymax;
Daniel Stenberg98728132005-07-14 10:02:04 +000078 int colors[LCD_WIDTH * LCD_HEIGHT];
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +000079 struct coordinate points[LCD_WIDTH * LCD_HEIGHT];
Jens Arnold48be8e62005-10-23 23:49:46 +000080 unsigned force_mask = lcd_display_redraw ? 0xFF : 0;
Daniel Stenbergcd864072002-09-10 07:07:44 +000081
Daniel Stenberg4ccffb62003-04-23 18:49:24 +000082#if 0
Daniel Stenbergae262332003-02-07 09:42:57 +000083 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
84 counter++, x_start, y_start, width, height);
Daniel Stenberg4ccffb62003-04-23 18:49:24 +000085#endif
Jens Arnoldf894a4c2005-07-06 22:58:02 +000086 /* The Y coordinates have to work on even YBLOCK pixel rows */
87 ymax = (yline + height)/YBLOCK;
88 yline /= YBLOCK;
Jens Arnold74b731e2005-03-18 23:51:52 +000089
Daniel Stenbergcd864072002-09-10 07:07:44 +000090 xmax = x_start + width;
91
92 if(xmax > LCD_WIDTH)
93 xmax = LCD_WIDTH;
Jens Arnoldf894a4c2005-07-06 22:58:02 +000094 if(ymax >= LCD_HEIGHT/YBLOCK)
95 ymax = LCD_HEIGHT/YBLOCK-1;
Daniel Stenbergcd864072002-09-10 07:07:44 +000096
Jens Arnold48be8e62005-10-23 23:49:46 +000097 for(; yline <= ymax; yline++) {
Jens Arnoldf894a4c2005-07-06 22:58:02 +000098 y = yline * YBLOCK;
Jens Arnold48be8e62005-10-23 23:49:46 +000099 for(x = x_start; x < xmax; x++) {
100 unsigned char diff = (lcd_framebuffer[yline][x]
101 ^ lcd_framebuffer_copy[yline][x])
102 | force_mask;
103 if(diff) {
Daniel Stenbergcd864072002-09-10 07:07:44 +0000104 /* one or more bits/pixels are changed */
Jens Arnold48be8e62005-10-23 23:49:46 +0000105 unsigned char mask = ANDBIT;
106 for(bit = 0; bit < YBLOCK; bit++) {
107 if(diff & mask) {
108 /* pixel has changed */
109 unsigned int col = lcd_framebuffer[yline][x] & mask;
Daniel Stenberg98728132005-07-14 10:02:04 +0000110#if LCD_DEPTH == 2
Jens Arnold48be8e62005-10-23 23:49:46 +0000111 colors[p] = col >> (bit * LCD_DEPTH);
Daniel Stenberg98728132005-07-14 10:02:04 +0000112#else
Jens Arnold48be8e62005-10-23 23:49:46 +0000113 colors[p] = col ? 3 : 0;
Daniel Stenberg98728132005-07-14 10:02:04 +0000114#endif
Jens Arnold48be8e62005-10-23 23:49:46 +0000115 points[p].x = x + MARGIN_X;
116 points[p].y = y + bit + MARGIN_Y;
117 p++; /* increase the point counter */
118 }
119 mask <<= LCD_DEPTH;
Daniel Stenbergcd864072002-09-10 07:07:44 +0000120 }
121
122 /* update the copy */
Jörg Hohensohn5040cc52003-12-23 23:41:45 +0000123 lcd_framebuffer_copy[yline][x] = lcd_framebuffer[yline][x];
Daniel Stenbergcd864072002-09-10 07:07:44 +0000124 }
125 }
126 }
Daniel Stenbergc1543512002-04-27 23:41:41 +0000127
Daniel Stenberg98728132005-07-14 10:02:04 +0000128 dots(colors, &points[0], p);
Jens Arnold74b731e2005-03-18 23:51:52 +0000129 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
130 XtAppLock(app);
Björn Stenbergf9429cc2002-04-19 12:55:12 +0000131 XSync(dpy,False);
Jens Arnold74b731e2005-03-18 23:51:52 +0000132 XtAppUnlock(app);
Jens Arnold48be8e62005-10-23 23:49:46 +0000133 lcd_display_redraw=false;
Daniel Stenberg319d1f32002-03-26 10:59:39 +0000134}
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000135
136#ifdef LCD_REMOTE_HEIGHT
137extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
138unsigned char lcd_remote_framebuffer_copy[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH];
139
Jens Arnoldfc03c8e2005-10-23 13:06:25 +0000140#define REMOTE_START_Y (LCD_HEIGHT + 2*MARGIN_Y)
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000141
142void lcd_remote_update (void)
143{
Daniel Stenberg98728132005-07-14 10:02:04 +0000144 lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000145}
146
147void lcd_remote_update_rect(int x_start, int y_start,
148 int width, int height)
149{
150 int x;
151 int yline=y_start;
152 int y;
153 int p=0;
154 int bit;
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000155 int xmax;
156 int ymax;
Jens Arnold48be8e62005-10-23 23:49:46 +0000157 struct coordinate points[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
158 int colors[LCD_REMOTE_WIDTH * LCD_REMOTE_HEIGHT];
159 unsigned force_mask = lcd_display_redraw ? 0xFF : 0;
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000160
161#if 0
162 fprintf(stderr, "%04d: lcd_update_rect(%d, %d, %d, %d)\n",
163 counter++, x_start, y_start, width, height);
164#endif
165 /* The Y coordinates have to work on even 8 pixel rows */
166 ymax = (yline + height)/8;
167 yline /= 8;
168
169 xmax = x_start + width;
170
171 if(xmax > LCD_REMOTE_WIDTH)
172 xmax = LCD_REMOTE_WIDTH;
173 if(ymax >= LCD_REMOTE_HEIGHT/8)
174 ymax = LCD_REMOTE_HEIGHT/8-1;
175
Jens Arnold48be8e62005-10-23 23:49:46 +0000176 for(; yline <= ymax; yline++) {
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000177 y = yline * 8;
Jens Arnold48be8e62005-10-23 23:49:46 +0000178 for(x = x_start; x < xmax; x++) {
179 unsigned char diff = (lcd_remote_framebuffer[yline][x]
180 ^ lcd_remote_framebuffer_copy[yline][x])
181 | force_mask;
182 if(diff) {
183 unsigned char mask = 1;
184 for(bit = 0; bit < 8; bit++) {
185 if(diff & mask) {
186 unsigned int col = lcd_remote_framebuffer[yline][x] & mask;
187 colors[p] = col ? 3 : 0;
Jens Arnoldfc03c8e2005-10-23 13:06:25 +0000188 points[p].x = x + MARGIN_X;
Jens Arnold48be8e62005-10-23 23:49:46 +0000189 points[p].y = y + bit + (REMOTE_START_Y + MARGIN_Y);
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000190 p++; /* increase the point counter */
191 }
Jens Arnold48be8e62005-10-23 23:49:46 +0000192 mask <<= 1;
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000193 }
Daniel Stenberg98728132005-07-14 10:02:04 +0000194
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000195 /* update the copy */
196 lcd_remote_framebuffer_copy[yline][x] =
197 lcd_remote_framebuffer[yline][x];
198 }
199 }
200 }
201
Daniel Stenberg98728132005-07-14 10:02:04 +0000202 dots(colors, &points[0], p);
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000203 /* printf("lcd_update_rect: Draws %d pixels, clears %d pixels\n", p, cp);*/
204 XtAppLock(app);
205 XSync(dpy,False);
206 XtAppUnlock(app);
Jens Arnold48be8e62005-10-23 23:49:46 +0000207 lcd_display_redraw=false;
Daniel Stenbergac31e6a2005-05-23 16:23:25 +0000208}
209
210
211#endif
212
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +0000213#endif
214#ifdef HAVE_LCD_CHARCELLS
Daniel Stenbergcd864072002-09-10 07:07:44 +0000215
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +0000216/* Defined in lcd-playersim.c */
217extern void lcd_print_char(int x, int y);
218extern unsigned char lcd_buffer[2][11];
219extern void drawrect(int color, int x1, int y1, int x2, int y2);
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +0000220
Kjell Ericson1cb80612003-01-10 10:03:07 +0000221extern unsigned char hardware_buffer_lcd[11][2];
222static unsigned char lcd_buffer_copy[11][2];
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +0000223
224void lcd_update (void)
225{
Jens Arnold31b28f52005-03-18 00:03:22 +0000226 bool changed=false;
227 int x, y;
228 for (y=0; y<2; y++) {
229 for (x=0; x<11; x++) {
230 if (lcd_display_redraw ||
231 lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) {
232 lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y];
233 lcd_print_char(x, y);
234 changed=true;
235 }
236 }
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +0000237 }
Jens Arnold31b28f52005-03-18 00:03:22 +0000238 if (changed)
Jens Arnold74b731e2005-03-18 23:51:52 +0000239 {
240 XtAppLock(app);
Jens Arnold31b28f52005-03-18 00:03:22 +0000241 XSync(dpy,False);
Jens Arnold74b731e2005-03-18 23:51:52 +0000242 XtAppUnlock(app);
243 }
Jens Arnold31b28f52005-03-18 00:03:22 +0000244 lcd_display_redraw=false;
Kjell Ericsonf7a4b2b2002-10-28 20:08:40 +0000245}
246
247#endif
Dan Everton3ba00602006-02-13 21:46:28 +0000248
249#ifdef CONFIG_BACKLIGHT
250void sim_backlight(int value)
251{
252 DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
253}
254#endif
255
256#ifdef HAVE_REMOTE_LCD
257void sim_remote_backlight(int value)
258{
259 DEBUGF("remote backlight: %s\n", (value > 0) ? "on" : "off");
260}
261#endif
262