updated on Tue Jan 10 12:02:00 UTC 2012
[aur-mirror.git] / tmview / 204_framebuffer_updates.diff
blobd830350335f2fae9d9ce6d2817cec6965007b060
1 --- tmview-01.03.orig/fb/writefb.c
2 +++ tmview-01.03/fb/writefb.c
3 @@ -18,16 +19,19 @@
5 /* framebuffer globals */
6 static uchar *thefb=NULL;
7 +static struct fb_var_screeninfo thefbvarinfo;
8 static long thefblen;
9 +static int thefbdepth;
10 static int thefbxdim;
11 static int thefbydim;
12 -static int thefbbyteswidth;
13 +static int thefbstride;
14 static int thefbfd=-1;
15 static struct fb_cmap origpalette={0,0,NULL,NULL,NULL,NULL};
16 static unsigned short origreds[256];
17 static unsigned short origgreens[256];
18 static unsigned short origblues[256];
19 static unsigned short origtrans[256];
20 +static unsigned int newpalette[256];
22 /* terminal related stuff */
23 static struct termios origtermattr;
24 @@ -84,7 +88,7 @@
25 close(zwfd);
27 if(thefbfd!=-1) {
28 - if(origpalette.len!=0) {
29 + if(thefbdepth==1 && origpalette.len!=0) {
30 pfprot("c");
31 ioctl(thefbfd,FBIOPUTCMAP, &origpalette);
32 origpalette.len=0;
33 @@ -177,6 +181,7 @@
34 static volatile int pendingswitch=0;
36 void setpalette(void); /* foreward */
37 +void updateline(uchar *, uchar *, int);
39 static void vtrelease(int n){ /* switch away */
40 #ifdef DEBUGFB
41 @@ -190,19 +195,51 @@
44 static void vtaquire(int n) { /* come back */
45 + int h;
46 + uchar *src, *dst;
47 #ifdef DEBUGFB
48 pfprot("(vtaquire)");
49 #endif
50 ioctl(thevtfd, VT_RELDISP, VT_ACKACQ);
51 if(offscreen!=NULL && thefb!=NULL) {
52 - memcpy(thefb,offscreen,thefblen);
53 - setpalette();
54 + for(
55 + h=vgaydim,
56 + src=offscreen,
57 + dst=thefb;
58 + h>0;
59 + h--,
60 + src+=vgaxdim,
61 + dst+=thefbstride)
62 + updateline(dst,src,vgaxdim);
63 + setpalette();
65 pendingswitch=0; /* discard a pending request ... */
66 donotupdate=0; /* drawwings welcome again */
70 +void updateline(uchar *dst, uchar *src, int len) {
71 + switch(thefbdepth) {
72 + case 1:
73 + memcpy(dst,src,len);
74 + break;
75 + case 2: {
76 + int i;
77 + uint16_t*target=(uint16_t*)dst;
78 + for(i=len;i--;)
79 + *target++=newpalette[*src++];
80 + }
81 + break;
82 + case 4: {
83 + int i;
84 + uint32_t*target=(uint32_t*)dst;
85 + for(i=len;i--;)
86 + *target++=newpalette[*src++];
87 + }
88 + break;
89 + }
92 void myupdate(int x1, int y1, int x2, int y2) {
93 int h,w;
94 uchar *src, *dst;
95 @@ -221,13 +258,13 @@
96 for(
97 w=x2-x1+1,
98 h=y2-y1+1,
99 - src=offscreen+thefbbyteswidth*y1+x1,
100 - dst=thefb+thefbbyteswidth*y1+x1;
101 + src=offscreen+vgaxdim*y1+x1,
102 + dst=thefb+thefbstride*y1+thefbdepth*x1;
103 h>0;
104 h--,
105 - src+=thefbbyteswidth,
106 - dst+=thefbbyteswidth)
107 - memcpy(dst,src,w);
108 + src+=vgaxdim,
109 + dst+=thefbstride)
110 + updateline(dst,src,w);
112 updateinprogress=0; /* all drawings done so far */
113 if(pendingswitch){ /* aha: console switch requested while we were busy */
114 @@ -250,8 +287,18 @@
115 fbc.green=&g;
116 fbc.blue=&b;
117 fbc.transp=NULL;
118 - if(0!=ioctl(thefbfd,FBIOPUTCMAP, &fbc))
119 - vgaerror("\nerror: writefb: setpalette\n");
120 + switch(thefbdepth) {
121 + case 1:
122 + if(0!=ioctl(thefbfd,FBIOPUTCMAP, &fbc)) {
123 + /*vgaerror("\nerror: writefb: setpalette\n")*/;
125 + break;
126 + default:
127 + newpalette[num] = (((int)r>>(16-thefbvarinfo.red.length))<<thefbvarinfo.red.offset)
128 + | (((int)g>>(16-thefbvarinfo.green.length))<<thefbvarinfo.green.offset)
129 + | (((int)b>>(16-thefbvarinfo.blue.length))<<thefbvarinfo.blue.offset);
130 + break;
134 void setpalette(void) {
135 @@ -279,7 +326,6 @@
137 void vgaopen(void) {
138 struct fb_fix_screeninfo fixinfo;
139 - struct fb_var_screeninfo varinfo;
140 char vtdevice[50];
141 char* str;
142 int ttyfd, vtno;
143 @@ -304,27 +350,34 @@
144 /* Why? */
145 pfprot("f");
146 str=getenv("FRAMEBUFFER");
147 - if(str==NULL) str=THEFBDEV;/* is this a security problem? */
148 + if(str!=NULL) {
149 + thefbfd=open(str,O_RDWR); /* want write-only here */
150 + } else {
151 + str=THEFBDEV; /* is this a security problem? */
152 + thefbfd=open(str,O_RDWR);
153 + if(thefbfd==-1) {
154 + str=THEOTHERFBDEV;
155 + thefbfd=open(str,O_RDWR);
158 pfprot("(%s)",str);
159 - thefbfd=open(str,O_RDWR); /* want write-only here */
160 - if(thefbfd==-1)
161 + if(thefbfd==-1)
162 vgaerror("cannot open framebuffer device");
163 if(0!=ioctl(thefbfd,FBIOGET_FSCREENINFO, &fixinfo))
164 vgaerror("cannot get fixed info: its not a framebuffer?");
165 pfprot("(%s)",fixinfo.id);
166 - if(0!=ioctl(thefbfd,FBIOGET_VSCREENINFO, &varinfo))
167 + if(0!=ioctl(thefbfd,FBIOGET_VSCREENINFO, &thefbvarinfo))
168 vgaerror("cannot get var info");
169 - if(varinfo.xres!= varinfo.xres_virtual || varinfo.yres!= varinfo.yres_virtual)
170 - vgaerror("virtual res doesn't equal physical res");
171 - if(fixinfo.type!=FB_TYPE_PACKED_PIXELS || fixinfo.visual!= FB_VISUAL_PSEUDOCOLOR
172 - || varinfo.bits_per_pixel != 8)
173 - vgaerror("pseudocolor, packed-pixels, 8bpp required\n ... try fbset utility?");
174 - thefbxdim=varinfo.xres;
175 - thefbydim=varinfo.yres;
176 + if(fixinfo.type!=FB_TYPE_PACKED_PIXELS)
177 + vgaerror("packed-pixels required\n ... try fbset utility?");
178 + thefbdepth=(thefbvarinfo.bits_per_pixel+7) / 8;
179 + if(thefbdepth==3)
180 + thefbdepth=4;
181 + thefbxdim=thefbvarinfo.xres;
182 + thefbydim=thefbvarinfo.yres;
183 pfprot("(%dx%d)",thefbxdim,thefbydim);
184 - thefbbyteswidth=varinfo.xres;
185 - thefblen=((((long)thefbbyteswidth * (long)varinfo.yres * varinfo.bits_per_pixel+7)/8)
186 - + 0x0fffL) & ~0x0fffL;
187 + thefbstride=thefbvarinfo.xres_virtual * thefbdepth;
188 + thefblen=(((long)thefbstride * (long)thefbydim) + 0x0fffL) & ~0x0fffL;
189 if(thefblen>fixinfo.smem_len)
190 pfprot("warning: writefb: mapping more than there is?\n");
191 pfprot("m");
192 @@ -333,9 +386,9 @@
193 thefb=NULL;
194 vgaerror("memory mapping of framebuffer failed");
196 - seteuid(getuid()); /* give back root permissions */
197 + setegid(getgid()); /* give back video group permissions */
198 #ifdef DEBUGFB
199 - pfprot("(set euid %d uid %d)",geteuid(),getuid());
200 + pfprot("(set egid %d gid %d)",getegid(),getgid());
201 #endif
203 /* .. some basic tests, copied from below: under certain */
204 @@ -358,13 +411,13 @@
205 origpalette.green=origgreens;
206 origpalette.blue=origblues;
207 origpalette.transp=origtrans;
208 - if(0!=ioctl(thefbfd,FBIOGETCMAP, &origpalette)){
209 + if(thefbdepth==1 && 0!=ioctl(thefbfd,FBIOGETCMAP, &origpalette)){
210 origpalette.len=0;
211 - vgaerror("\nerror: writefb: readpalette\n");
212 + /*vgaerror("\nerror: writefb: readpalette\n");*/
215 /* accocaletmviews offscreenbuffer */
216 - allocmem(&offscreen,thefblen);
217 + allocmem(&offscreen,((long)thefbxdim * (long)thefbydim + 0x0fffL) & ~0x0fffL);
219 /* open mouse deveice */
220 #ifdef HASMOUSE
221 @@ -390,6 +443,13 @@
222 vtno=ttystat.v_active;
223 sprintf(vtdevice,"/dev/tty%d",vtno);
224 thevtfd=open(vtdevice, O_RDWR | O_NDELAY);
225 + if(thevtfd<0) {
226 + /* try the devfs name */
227 + sprintf(vtdevice,"/dev/vc/%d",vtno);
228 + thevtfd=open(vtdevice, O_RDWR | O_NDELAY);
229 + if(thevtfd<0)
230 + vgaerror("cannot open vt");
232 if(thevtfd<0)
233 vgaerror("cannot open vt");
234 if(ioctl(thevtfd, VT_GETMODE, &vtmode)!=0)
235 @@ -403,6 +463,17 @@
236 vgaerror("cannot install vtswitch handles");
237 ioctl(thevtfd, KDSETMODE, KD_GRAPHICS);
239 + /* now that we switched to graphics mode, pan the display */
240 + thefbvarinfo.xoffset=0;
241 + thefbvarinfo.yoffset=0;
242 + ioctl(thefbfd,FBIOPUT_VSCREENINFO, &thefbvarinfo);
243 + /* don't check the return value; some buggy framebuffer */
244 + /* drivers will return an error while correctly panning */
245 + /* the display, we have no real choice. */
246 + thefbvarinfo.xoffset=0;
247 + thefbvarinfo.yoffset=0;
248 + ioctl(thefbfd,FBIOPAN_DISPLAY, &thefbvarinfo);
250 /* set the terminal to noblocking/noecho */
251 pfprot("a");
252 if(!isatty(STDIN_FILENO))
253 @@ -425,7 +496,7 @@
254 vgaydim=truevgaydim=thefbydim;
255 ptorigin=offscreen;
256 #define PTDELTAH (1)
257 - #define PTDELTAV (thefbbyteswidth)
258 + #define PTDELTAV (vgaxdim)
259 ofscx1=0; ofscy1=0; ofscx2=vgaxdim-1; ofscy2=vgaydim-1;
260 setpalette();
261 preparefont();
262 @@ -452,17 +523,17 @@
263 dst=offscreen;
264 i>0;
265 i--,
266 - src+=thefbbyteswidth,
267 - dst+=thefbbyteswidth)
268 + src+=vgaxdim,
269 + dst+=vgaxdim)
270 memmove(dst,src,vgaxdim-dx);
271 - else
272 + else /* dx>=0 */
273 for(i=vgaydim,
274 src=offscreen,
275 dst=offscreen+dx;
276 i>0;
277 i--,
278 - src+=thefbbyteswidth,
279 - dst+=thefbbyteswidth)
280 + src+=vgaxdim,
281 + dst+=vgaxdim)
282 memmove(dst,src,vgaxdim-dx);
285 @@ -473,22 +544,22 @@
286 if(dy<0)
287 for(
288 i=vgaydim+dy,
289 - src=offscreen+thefbbyteswidth*(-dy),
290 + src=offscreen+vgaxdim*(-dy),
291 dst=offscreen;
292 i>0;
293 i--,
294 - src+=thefbbyteswidth,
295 - dst+=thefbbyteswidth)
296 + src+=vgaxdim,
297 + dst+=vgaxdim)
298 memcpy(dst,src,vgaxdim);
299 - else /* dy>0 */
300 + else /* dy>=0 */
301 for(
302 i=vgaydim-dy,
303 - src=offscreen+thefbbyteswidth*(vgaydim-dy-1),
304 - dst=offscreen+thefbbyteswidth*(vgaydim-1);
305 + src=offscreen+vgaxdim*(vgaydim-dy-1),
306 + dst=offscreen+vgaxdim*(vgaydim-1);
307 i>0;
308 i--,
309 - src-=thefbbyteswidth,
310 - dst-=thefbbyteswidth)
311 + src-=vgaxdim,
312 + dst-=vgaxdim)
313 memcpy(dst,src,vgaxdim);
316 --- tmview-01.03.orig/fb/defsfb.h
317 +++ tmview-01.03/fb/defsfb.h
318 @@ -31,8 +32,10 @@
319 #include <stdlib.h>
322 -/* the framebuffer devive to use */
323 +/* the framebuffer device to use */
324 #define THEFBDEV "/dev/fb0"
325 +/* for devfs */
326 +#define THEOTHERFBDEV "/dev/fb/0"