source: titan/titan/mipselport.h @ 44611

Last change on this file since 44611 was 44611, checked in by obi, 4 years ago

sh4 oebuild fix rtc time

File size: 47.1 KB
Line 
1#ifndef MIPSELPORT_H
2#define MIPSELPORT_H
3
4#ifdef CONFIG_ION
5
6//#include <interfaces/ion.h>
7#define ION_HEAP_TYPE_BMEM      (ION_HEAP_TYPE_CUSTOM + 1)
8#define ION_HEAP_ID_MASK        (1 << ION_HEAP_TYPE_BMEM)
9#define ACCEL_MEM_SIZE          (32*1024*1024)
10
11#elif !defined(FBIO_BLIT)
12
13//#define FBIO_SET_MANUAL_BLIT _IOW('F', 0x20, __u32)
14#define FBIO_SET_MANUAL_BLIT _IOW('F', 0x21, __u8)
15#define FBIO_BLIT 0x22
16
17#endif
18
19#ifndef FBIO_WAITFORVSYNC
20#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
21#endif
22
23//fuer Funktion memcpy_word
24volatile char *memcpy_word_src;
25volatile char *memcpy_word_dest;
26volatile long  memcpy_word_anzw = 0;
27
28//fuer Funktion memcpy_byte
29volatile char *memcpy_byte_src;
30volatile char *memcpy_byte_dest;
31volatile long  memcpy_byte_anzb = 0;
32
33unsigned char *lfb = NULL;
34int g_manual_blit = 0;
35struct fb_fix_screeninfo fix_screeninfo;
36struct fb_var_screeninfo var_screeninfo;
37
38void memcpy_area(unsigned char* targetADDR, unsigned char* startADDR, long pxAbs, long hight, long widthAbs, long FBwidthAbs);
39
40int setmixer(struct dvbdev* node, int left, int right)
41{
42        return audiosetmixer(node, left, right);
43}
44
45int setencoding(struct channel* chnode, struct dvbdev* videonode)
46{
47        int ret = 1;
48        if(chnode == NULL) return ret;
49       
50        switch(chnode->videocodec)
51        {
52                case MPEGV:
53                        ret = videosetstreamtype(videonode, 0);
54                        break;
55                case MPEG4V:
56                        ret = videosetstreamtype(videonode, 4);
57                        break;
58                case H264:
59                        ret = videosetstreamtype(videonode, 1);
60                        break;
61                case H265:
62                        ret = videosetstreamtype(videonode, H265);
63                        break;
64                case VC1:
65                        ret = videosetstreamtype(videonode, 3);
66                        break;
67                default:
68                        ret = videosetstreamtype(videonode, 0);
69        }
70        return ret;
71}
72
73int videodiscontinuityskip(struct dvbdev* node, int flag)
74{
75        return 0;
76}
77
78void fbsave()
79{
80}
81
82void fbrestore()
83{
84}
85
86void setfbvarsize(struct fb* newnode)
87{
88        if(newnode != NULL)
89#ifndef CONFIG_ION             
90                newnode->varfbsize = 1920 * 1080 * newnode->colbytes;
91//              newnode->varfbsize = 1920 * 1080 * (newnode->colbytes * 8);
92#else
93        newnode->varfbsize = newnode->width * newnode->height * newnode->colbytes;
94#endif
95
96}
97
98void enablemanualblit()
99{
100#if !defined(CONFIG_ION) && !defined(CONFIG_HISILICON_FB)
101        unsigned char tmp = 1;
102        if (ioctl(fb->fd, FBIO_SET_MANUAL_BLIT, &tmp)<0)
103                perror("FBIO_SET_MANUAL_BLIT");
104        else
105                g_manual_blit = 1;
106#endif
107}
108
109void disablemanualblit()
110{
111#if !defined(CONFIG_ION) && !defined(CONFIG_HISILICON_FB)
112        unsigned char tmp = 0;
113        if (ioctl(fb->fd, FBIO_SET_MANUAL_BLIT, &tmp)<0)
114                perror("FBIO_SET_MANUAL_BLIT");
115        else
116                g_manual_blit = 0;
117#endif
118}
119
120void blit()
121{
122#if !defined(CONFIG_ION) && !defined(CONFIG_HISILICON_FB)
123        if (g_manual_blit == 1) {
124                if (ioctl(fb->fd, FBIO_BLIT) < 0)
125                        perror("FBIO_BLIT");
126        }
127#endif
128}
129
130int waitvsync()
131{
132        int c = 0;
133        return ioctl(fb->fd, FBIO_WAITFORVSYNC, &c);
134}
135
136void fbsetoffset(int x, int y)
137{
138        struct fb_var_screeninfo var_screeninfo;
139
140        var_screeninfo.xoffset = x;
141        var_screeninfo.yoffset = y;
142
143        if(ioctl(fb->fd, FBIOPAN_DISPLAY, &var_screeninfo) < 0)
144        {
145                perr("FBIOPAN_DISPLAY");
146        }
147}
148
149//flag 0 = no animation
150//flag 1 = animation
151void blitfb2(struct fb* fbnode, int flag)
152{
153        int doblit = 1;
154        int m_number_of_pages = 1;
155        struct fb_var_screeninfo var_screeninfo;
156
157        var_screeninfo.xres_virtual = fb->width;
158        var_screeninfo.xres = fb->width;
159//      if(checkbox("VUSOLO2") == 0)
160                var_screeninfo.yres_virtual = fb->height * 2;
161//      else
162//              var_screeninfo.yres_virtual = fb->height;
163        var_screeninfo.yres = fb->height;
164        var_screeninfo.height = 0;
165        var_screeninfo.width = 0;
166        var_screeninfo.xoffset = 0;
167        var_screeninfo.yoffset = 0;
168//      if(checkbox("VUSOLO2") == 0)
169                var_screeninfo.bits_per_pixel = fb->colbytes * 8;
170//      else
171//              var_screeninfo.bits_per_pixel = fb->colbytes;
172       
173        switch(fb->colbytes)
174        {
175                case 2:
176                        var_screeninfo.transp.offset = 15;
177                        var_screeninfo.transp.length = 1;
178                        var_screeninfo.red.offset = 10;
179                        var_screeninfo.red.length = 5;
180                        var_screeninfo.green.offset = 5;
181                        var_screeninfo.green.length = 5;
182                        var_screeninfo.blue.offset = 0;
183                        var_screeninfo.blue.length = 5;
184                        break;
185                case 4:
186                        var_screeninfo.transp.offset = 24;
187                        var_screeninfo.transp.length = 8;
188                        var_screeninfo.red.offset = 16;
189                        var_screeninfo.red.length = 8;
190                        var_screeninfo.green.offset = 8;
191                        var_screeninfo.green.length = 8;
192                        var_screeninfo.blue.offset = 0;
193                        var_screeninfo.blue.length = 8;
194                        break;
195        }
196       
197        debug(444, "FB: line_length %d", fix_screeninfo.line_length);
198        debug(444, "FB: var_screeninfo.xres %d", var_screeninfo.xres);
199        debug(444, "FB: var_screeninfo.yres %d", var_screeninfo.yres);
200        debug(444, "FB: var_screeninfo.xres_virt %d", var_screeninfo.xres_virtual);
201        debug(444, "FB: var_screeninfo.yres_virt %d", var_screeninfo.yres_virtual);
202        debug(444, "FB: var_screeninfo.xoffset %d", var_screeninfo.xoffset);
203        debug(444, "FB: var_screeninfo.yoffset %d", var_screeninfo.yoffset);
204        debug(444, "FB: var_screeninfo.bits_per_pixel %d", var_screeninfo.bits_per_pixel);
205        debug(444, "FB: var_screeninfo.grayscale %d", var_screeninfo.grayscale);
206       
207        if(checkchipset("HI3798MV200") == 0 && checkrealbox("HD51") == 0 && checkrealbox("HD60") == 0 && checkrealbox("HD61") == 0 && checkbox("DM7020HD") == 0 && checkbox("DM7020HDV2") == 0 && checkbox("DM900") == 0 && checkbox("DM920") == 0 && checkbox("WETEK") == 0 && checkbox("DM520") == 0 && checkbox("DM525") == 0 && checkchipset("3798MV200") == 0)
208        {
209                if(ioctl(fb->fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0)
210                {
211                        var_screeninfo.yres_virtual = fb->height;
212                        if(ioctl(fb->fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0)
213                        {
214                                perr("FBIOPUT_VSCREENINFO");
215                        }
216                        debug(444, "FB: double buffering not available");
217                        debug(10, "FB: double buffering not available");
218                }
219                else
220                {
221                        debug(444, "FB: double buffering available!");
222                        debug(10, "FB: double buffering available!");
223                }
224
225                m_number_of_pages = var_screeninfo.yres_virtual / fb->height;
226                debug(444, "FB: %d page(s) available!", m_number_of_pages);
227                debug(10, "FB: %d page(s) available!", m_number_of_pages);
228
229                ioctl(fb->fd, FBIOGET_VSCREENINFO, &var_screeninfo);
230                if ((var_screeninfo.xres!=fb->width) && (var_screeninfo.yres!=fb->height) && (var_screeninfo.bits_per_pixel!=fb->colbytes))
231                {
232                        debug(444, "SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
233                                fb->width, fb->height, fb->colbytes,
234                                var_screeninfo.xres, var_screeninfo.yres, var_screeninfo.bits_per_pixel);
235                }
236        }
237       
238        int posx = 0;
239        int posy = 0;
240        int width = 0;
241        int height = 0;
242       
243        if(status.bcm == 1 && status.usedirectfb == 0)
244        {
245                posx = getconfigint("fbleftoffset", NULL) * 5;
246                posy = getconfigint("fbtopoffset", NULL) * 5;
247                width = (fb->width - posx) - (getconfigint("fbrightoffset", NULL) * 5);
248                height = (fb->height - posy) - (getconfigint("fbbottomoffset", NULL) * 5);
249        }
250        else
251        {
252                posx = getconfigint("fbleftoffset", NULL);
253                posy = getconfigint("fbtopoffset", NULL);
254                width = (720 - posx) - (getconfigint("fbrightoffset", NULL));
255                height = (576 - posy) - (getconfigint("fbbottomoffset", NULL));
256        }
257        //printf("posx:%i posy:%i width:%i height:%i\n", posx, posy, width, height);
258
259        if(flag == 0 || checkbox("ATEMIO5200") == 1 || status.screenanim == 0)
260        {
261                if(status.bcm == 1 && status.usedirectfb == 0)
262                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
263#ifdef HAVE_HISILICON_ACCEL
264                else if(status.usedirectfb == 0)
265                        dinobot_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0, 0);
266#endif
267                blit();
268               
269                //woraround pixel fehler
270                if(checkbox("DM900") == 1 || checkbox("DM920") == 1)
271                {
272                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
273#ifdef HAVE_HISILICON_ACCEL
274                        dinobot_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0, 0);
275#endif
276                        blit();
277                }
278               
279                return;
280        }
281       
282
283        int i = 0, max = 1, wstep = 0, hstep = 0;
284        int dst_left = 0, dst_width = 0, dst_top = 0, dst_height = 0;
285        int mode3d = 0;
286
287        if(flag == 1 && status.screenanim > 0 && mode3d == 0)
288        {
289                doblit = 0;
290                //max = 25;
291                max = 8;
292                dst_left = posx;
293                dst_width = width;
294                dst_top = posy;
295                dst_height = height;
296               
297                char* fbleftdev = "/proc/stb/fb/dst_left";
298                char* fbwidthdev = "/proc/stb/fb/dst_width";
299                char* fbtopdev = "/proc/stb/fb/dst_top";
300                char* fbheightdev = "/proc/stb/fb/dst_height";
301               
302                int screenanimspeed = 0;       
303               
304                if(status.bcm == 1 && status.usedirectfb == 0)
305                {
306                        if(status.screenanimspeed == 1 || status.screenanimspeed == 0)
307                                max = 4;
308                        else if(status.screenanimspeed == 5)
309                                max = 8;
310                        else
311                                screenanimspeed = status.screenanimspeed;
312                }
313                else
314                        screenanimspeed = status.screenanimspeed;
315                       
316                if(status.screenanim == 1 || status.screenanim == 3)
317                {
318                        dst_left = (width / 2) - 1;
319                        dst_width = 2;
320                }
321                if(status.screenanim == 2 || status.screenanim == 3)
322                {
323                        dst_top = (height / 2) - 1;
324                        dst_height = 2;
325                }
326                if(status.screenanim == 4 || status.screenanim == 11)
327                {
328                        dst_top = posy;
329                        dst_height = height;
330                        dst_left = posx;
331                        dst_width = 2;
332                }
333                if(status.screenanim == 5 || status.screenanim == 12)
334                {
335                        dst_top = posy;
336                        dst_height = 2;
337                        dst_left = posx;
338                        dst_width = width;
339                }
340               
341                wstep = width / max;
342                hstep = height / max;
343                       
344                for(i = 0; i <= max; i++)
345                {
346                        if(status.screenanim == 1 || status.screenanim == 3)
347                        {
348                                int tmpleft = dst_left - (wstep/2);
349                                int tmpwidth = dst_width + wstep;
350                                if(tmpleft < posx)
351                                        tmpleft = posx;
352                                if(tmpwidth > width)
353                                        tmpwidth = width;
354                                dst_left = tmpleft;
355                                dst_width = tmpwidth;
356                        }
357                        if(status.screenanim == 2 || status.screenanim == 3)
358                        {
359                                int tmptop = dst_top - (hstep/2);
360                                int tmpheight = dst_height + hstep;
361                                if(tmptop < posy)
362                                        tmptop = posy;
363                                if(tmpheight > height)
364                                        tmpheight = height;
365                                dst_top = tmptop;
366                                dst_height = tmpheight;
367                        }
368                        if(status.screenanim == 4 || status.screenanim == 11)
369                        {
370                                int tmpwidth = dst_width + wstep;
371                                if(tmpwidth > width)
372                                        tmpwidth = width;
373                                dst_width = tmpwidth;
374                        }
375                        if(status.screenanim == 5 || status.screenanim == 12)
376                        {
377                                int tmpheight = dst_height + hstep;
378                                if(tmpheight > height)
379                                        tmpheight = height;
380                                dst_height = tmpheight;
381                        }
382                        dst_width = dst_width+posx;
383                        dst_height = dst_height+posy;
384                        if((dst_width + dst_left) > width)
385                                dst_width = dst_width - dst_left;
386                                                       
387                        if((dst_height + dst_top) > height)
388                                dst_height = dst_height - dst_top;
389                                                               
390                        //printf("left:%i width:%i top:%i height:%i\n", dst_left, dst_width, dst_top, dst_height);
391                        //waitvsync();
392                        if(status.bcm == 1 && status.usedirectfb == 0)
393                        {
394                                if(status.screenanim < 10)
395                                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, dst_left, dst_top, dst_width, dst_height, 0, 0);
396#ifdef HAVE_HISILICON_ACCEL
397                                if(status.screenanim < 10)
398                                        dinobot_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, dst_left, dst_top, dst_width, dst_height, 0, 0, 0);
399#endif
400                                else
401                                {
402                                        int dswidth = (dst_width + posx*2) * skinfb->width / (width + posx*2);
403                                        int dsheight = (dst_height + posy*2) * skinfb->height / (height + posy*2);
404                                        int dsleft = skinfb->width - dswidth;
405                                        int dstop = skinfb->height - dsheight;
406                                        if(status.screenanim == 11)
407                                                dstop = 0;
408                                        if(status.screenanim == 12)
409                                                dsleft = 0;
410                                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, dsleft, dstop, dswidth, dsheight, dst_left, dst_top, dst_width, dst_height, 0, 0);
411#ifdef HAVE_HISILICON_ACCEL
412                                        dinobot_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, dsleft, dstop, dswidth, dsheight, dst_left, dst_top, dst_width, dst_height, 0, 0, 0);
413#endif
414                                }       
415                        }       
416                        else
417                        {
418                                setfbosddev(fbleftdev, dst_left);
419                                setfbosddev(fbwidthdev, dst_width);
420                                setfbosddev(fbtopdev, dst_top);
421                                setfbosddev(fbheightdev, dst_height);
422                                usleep(1000);
423                        }
424                        if(status.screenanim > 0) usleep(status.screenanimspeed * 1000);
425                        blit();
426                }
427                if(status.bcm == 1 && status.usedirectfb == 0)
428                {
429                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
430                }
431#ifdef HAVE_HISILICON_ACCEL
432                else if(status.usedirectfb == 0)
433                        dinobot_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0, 0);
434#endif
435                else
436                {
437                        setfbosddev(fbleftdev, posx);
438                        setfbosddev(fbwidthdev, width);
439                        setfbosddev(fbtopdev, posy);
440                        setfbosddev(fbheightdev, height);
441                }
442                blit();
443        }
444        else
445        {
446                if(status.bcm == 1 && status.usedirectfb == 0)
447                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
448#ifdef HAVE_HISILICON_ACCEL
449                else if(status.usedirectfb == 0)
450                        dinobot_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0, 0);
451#endif
452        }
453        if(doblit == 1)
454                blit();
455       
456/*     
457        int xRes, yRes, stride, bpp;
458       
459        xRes=var_screeninfo.xres;
460        yRes=var_screeninfo.yres;
461        bpp=var_screeninfo.bits_per_pixel;
462//      fb_fix_screeninfo fix;
463//      struct fb_fix_screeninfo fix_screeninfo;
464        if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fix_screeninfo)<0)
465        {
466                perror("FBIOGET_FSCREENINFO");
467                printf("fb failed\n");
468        }
469        stride=fix_screeninfo.line_length;
470        memset(lfb, 0, stride*yRes);
471*/
472//      blit();
473       
474/*
475        int i = 0, max = 1, wstep = 0, hstep = 0, ret = 0;
476        unsigned char buf[10];
477
478        if(fbnode == NULL) return;
479#ifndef NOHWBLIT
480        if(fbnode == fb) return;
481
482        if(status.rguidfd > -1)
483        {
484                m_lock(&status.accelfbmutex, 16);
485               
486                int zlen = 0;
487                char* zbuf = NULL;
488                blitscale(0, 0, fbnode->width, fbnode->height, 440, 330, 1);
489                ret = ozip((char*)accelfb->fb, 440 * 330 * 4, &zbuf, &zlen, 1);
490
491                if(ret == 0)
492                {
493                        memset(buf, 0, 10);
494                        char* tmpnr = oitoa(zlen);
495                        memcpy(buf, tmpnr, strlen(tmpnr));
496                        free(tmpnr); tmpnr = NULL;
497                        socksend(&status.rguidfd, buf, 10, 5000 * 1000);
498                        socksend(&status.rguidfd, (unsigned char*)zbuf, zlen, 5000 * 1000);
499                }
500                free(zbuf); zbuf = NULL;
501                zlen = 0;
502
503                m_unlock(&status.accelfbmutex, 16);
504        }
505
506        if(status.write_png == 1 && status.infobaraktiv == 0)
507        {
508                m_lock(&status.accelfbmutex, 16);
509                blitscale(0, 0, fbnode->width, fbnode->height, 320, 240, 1);
510                if(writeFBfile.ActBuf == NULL)
511                {
512                        writeFBfile.buf1 = malloc(4 * 320 * 240);
513                        writeFBfile.ActBuf = writeFBfile.buf1;
514                        memcpy(writeFBfile.buf1, accelfb->fb, 4 * 320 * 240);
515                        addtimer(&fb2png_thread, START, 10000, 1, NULL, NULL, NULL);
516                }
517                else if(writeFBfile.buf1 == writeFBfile.ActBuf)
518                {
519                        if(writeFBfile.buf2 == NULL)
520                                writeFBfile.buf2 = malloc(4 * 320 * 240);
521                        memcpy(writeFBfile.buf2, accelfb->fb, 4 * 320 * 240);
522                }
523                else if(writeFBfile.buf2 == writeFBfile.ActBuf)
524                {
525                        if(writeFBfile.buf1 == NULL)
526                                writeFBfile.buf1 = malloc(4 * 320 * 240);
527                        memcpy(writeFBfile.buf1, accelfb->fb, 4 * 320 * 240);
528                }
529                m_unlock(&status.accelfbmutex, 16);
530        }
531
532        int mode3d = 0, leftoffset = 0, rightoffset = 0, topoffset = 0, bottomoffset = 0;
533        char* mode3dstr = NULL;
534
535        if(status.leftoffset != 0) blitrect(0, 0, status.leftoffset, fb->height, 0, 255, 2);
536        if(status.rightoffset != 0) blitrect(fb->width - status.rightoffset, 0, status.rightoffset, fb->height, 0, 255, 2);
537        if(status.topoffset != 0) blitrect(0, 0, fb->width, status.topoffset, 0, 255, 2);
538        if(status.bottomoffset != 0) blitrect(0, fb->height - status.bottomoffset, fb->width, status.bottomoffset, 0, 255, 2);
539
540        mode3dstr = getconfig("av_mode3d", NULL);
541        if(ostrcmp(mode3dstr, "sbs") == 0)
542                mode3d = 1;
543        else if(ostrcmp(mode3dstr, "tab") == 0)
544                mode3d = 2;
545
546        STMFBIO_BLT_DATA  bltData;
547        memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA));
548
549        bltData.operation  = BLT_OP_COPY;
550        bltData.srcOffset  = fbnode->fb - fb->fb;
551        bltData.srcPitch   = fbnode->pitch;
552        bltData.src_top    = 0;
553        bltData.src_left   = 0;
554        bltData.src_right  = fbnode->width;
555        bltData.src_bottom = fbnode->height;
556        bltData.srcFormat  = SURF_BGRA8888;
557        bltData.srcMemBase = STMFBGP_FRAMEBUFFER;
558
559        bltData.dstOffset  = 0;
560        bltData.dstPitch   = fb->pitch;
561        bltData.dst_left   = status.leftoffset;
562        bltData.dst_top    = status.topoffset;
563        if(mode3d == 1)
564                bltData.dst_right = (fb->width - status.rightoffset) / 2;
565        else
566                bltData.dst_right = fb->width - status.rightoffset;
567        if(mode3d == 2)
568                bltData.dst_bottom = (fb->height - status.bottomoffset) / 2;
569        else
570                bltData.dst_bottom = fb->height - status.bottomoffset;
571        bltData.dstFormat  = SURF_BGRA8888;
572        bltData.dstMemBase = STMFBGP_FRAMEBUFFER;
573
574        if(flag == 1 && status.screenanim > 0 && mode3d == 0)
575        {
576                int width = (fb->width - status.rightoffset) - status.leftoffset;
577                int height = (fb->height - status.topoffset) - status.bottomoffset;
578                max = 25;
579                if(status.screenanim == 1 || status.screenanim == 3)
580                {
581                        bltData.dst_left = (width / 2) - 1;
582                        bltData.dst_right = (width / 2) + 1;
583                }
584                if(status.screenanim == 2 || status.screenanim == 3)
585                {
586                        bltData.dst_top = (height / 2) - 1;
587                        bltData.dst_bottom = (height / 2) + 1;
588                }
589                wstep = width / max;
590                hstep = height / max;
591        }
592
593        for(i = 0; i < max; i++)
594        {
595
596                if(status.screenanim == 1 || status.screenanim == 3)
597                {
598                        int tmpleft = bltData.dst_left - wstep;
599                        int tmpright = bltData.dst_right + wstep;
600                        if(tmpleft < status.leftoffset)
601                                tmpleft = status.leftoffset;
602                        if(tmpright > fb->width - status.rightoffset)
603                                tmpright = fb->width - status.rightoffset;
604                        bltData.dst_left = tmpleft;
605                        bltData.dst_right = tmpright;
606                }
607
608                if(status.screenanim == 2 || status.screenanim == 3)
609                {
610                        int tmptop = bltData.dst_top - hstep;
611                        int tmpbottom = bltData.dst_bottom + hstep;
612                        if(tmptop < status.topoffset)
613                                tmptop = status.topoffset;
614                        if(tmpbottom > fb->height - status.bottomoffset)
615                                tmpbottom = fb->height - status.bottomoffset;
616                        bltData.dst_top = tmptop;
617                        bltData.dst_bottom = tmpbottom;
618                }
619
620                if(status.screenanim > 0) usleep(status.screenanimspeed * 1000);
621
622                if (ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
623                {
624                        perr("ioctl STMFBIO_BLT");
625                }
626                if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
627                {
628                        perr("ioctl STMFBIO_SYNC_BLITTER");
629                }
630
631                if(mode3d != 0)
632                {
633                        if(mode3d == 1)
634                                bltData.dst_left = 0 + status.leftoffset + ((fb->width - status.rightoffset) / 2);
635                        if(mode3d == 2)
636                                bltData.dst_top = 0 + status.topoffset + ((fb->height - status.bottomoffset) / 2);
637                        bltData.dst_right  = fb->width - status.rightoffset;
638                        bltData.dst_bottom = fb->height - status.bottomoffset;
639
640                        if (ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
641                        {
642                                perr("ioctl STMFBIO_BLT");
643                        }
644                        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
645                        {
646                                perr("ioctl STMFBIO_SYNC_BLITTER");
647                        }
648                }
649        }
650#else
651#ifdef NOFB
652        if(status.rguidfd > -1)
653        {
654                char* buf = NULL;
655                buf = scale(fbnode->fb, fbnode->width, fbnode->height, 4, 320, 240, 0);
656                if(buf != NULL)
657                {
658                        socksend(&status.rguidfd, (unsigned char*)buf, 320 * 240 * 4, 5000 * 1000);
659                        free(buf); buf = NULL;
660                }
661        }
662        if(status.write_png == 1 && status.infobaraktiv == 0)
663        {
664                char* buf = NULL;
665                buf = scale(fbnode->fb, fbnode->width, fbnode->height, 4, 320, 240, 0);
666                if(buf != NULL)
667                {
668                        if(writeFBfile.ActBuf == NULL)
669                        {
670                                writeFBfile.buf1 = malloc(4 * 320 * 240);
671                                writeFBfile.ActBuf = writeFBfile.buf1;
672                                memcpy(writeFBfile.buf1, (unsigned char*)buf, 4 * 320 * 240);
673                                addtimer(&fb2png_thread, START, 10000, 1, NULL, NULL, NULL);
674                        }
675                        else if(writeFBfile.buf1 == writeFBfile.ActBuf)
676                        {
677                                if(writeFBfile.buf2 == NULL)
678                                        writeFBfile.buf2 = malloc(4 * 320 * 240);
679                                memcpy(writeFBfile.buf2, (unsigned char*)buf, 4 * 320 * 240);
680                        }
681                        else if(writeFBfile.buf2 == writeFBfile.ActBuf)
682                        {
683                                if(writeFBfile.buf1 == NULL)
684                                        writeFBfile.buf1 = malloc(4 * 320 * 240);
685                                memcpy(writeFBfile.buf1, (unsigned char*)buf, 4 * 320 * 240);
686                        }
687                        //fb2png((unsigned char*)buf, 320, 240, "/tmp/titanlcd.png");
688                        free(buf); buf = NULL;
689                }
690        }
691
692        if(fbnode != fb)
693        {
694                for(i = 0; i < fbnode->height; i++)
695                {
696                        memcpy(fb->fb + (i * fb->pitch), fbnode->fb + (i * fbnode->pitch), fbnode->width * fbnode->colbytes);
697                }
698        }
699        system("killall -9 xloadimage");
700
701        FILE *fd;
702        fd=fopen("titan.png", "w");
703        fwrite(fb->fb, fb->varfbsize, 1, fd);
704        fclose(fd);
705
706        system("fbgrab -f titan.png -w 1280 -h 720 -b 32 titan1.png > /dev/null");
707        system("xloadimage titan1.png > /dev/null &");
708#endif
709#endif
710*/
711}
712
713void setfbtransparent(int value)
714{
715        char* transparentdev;
716
717        transparentdev = getconfig("transparentdev", NULL);
718
719        if(transparentdev != NULL /*&& checkdev(transparentdev)*/)
720        {
721                debug(100, "set %s to %d", transparentdev, value);
722                writesysint(transparentdev, value, 1);
723                return;
724        }
725/*
726#ifndef SIMULATE
727        struct stmfbio_var_screeninfo_ex varEx = {0};
728
729        varEx.layerid  = 0;
730        varEx.activate = STMFBIO_ACTIVATE_IMMEDIATE;
731        varEx.caps = STMFBIO_VAR_CAPS_OPACITY;
732        varEx.opacity = value;
733
734
735        if(ioctl(fb->fd, STMFBIO_SET_VAR_SCREENINFO_EX, &varEx) < 0)
736                perr("STMFBIO_SET_VAR_SCREENINFO_EX");
737#endif
738*/
739}
740
741int allocbpamem(size_t size, int *memfd, unsigned char **mem)
742{
743        return -1;
744}
745
746void freebpamem(int memfd, unsigned char* mem, size_t len)
747{
748}
749
750//mode 0: with fill (draw to skinfb)
751//mode 1: without fill (draw to skinfb)
752//mode 2: with fill (draw to fb)
753//mode 3: without fill (draw to fb)
754void blitrect(int posx, int posy, int width, int height, long color, int transparent, int mode)
755{
756        int y, x;
757        unsigned long tmpcol;
758        struct fb* tmpfb = NULL;
759       
760        if(posx < 0) posx = 0;
761        if(posy < 0) posy = 0;
762        if(mode < 2)
763                tmpfb = skinfb;
764        else
765                tmpfb = fb;
766               
767        if(posx > tmpfb->width) posx = tmpfb->width;
768        if(posy > tmpfb->height) posy = tmpfb->height;
769        if(posx + width > tmpfb->width) width = tmpfb->width - posx;
770        if(posy + height > tmpfb->height) height = tmpfb->height - posy;
771
772        if(width <= 0 || height <= 0) return;
773
774        transparent = (transparent - 255) * -1;
775        tmpcol = color | ((transparent & 0xff) << 24);
776
777        if(mode == 0 || mode == 2)
778        {
779//#ifdef BCM_ACCEL     
780                if(status.bcm == 1 && tmpfb->data_phys != 0)
781                {
782                        bcm_accel_fill(tmpfb->data_phys, tmpfb->width, tmpfb->height, tmpfb->pitch, posx, posy, width, height, tmpcol);
783                }
784//#endif
785#ifdef HAVE_HISILICON_ACCEL
786                else if(tmpfb->data_phys != 0)
787                {
788                        dinobot_accel_fill(tmpfb->data_phys, tmpfb->width, tmpfb->height, tmpfb->pitch, posx, posy, width, height, tmpcol);
789                }
790#endif
791                else
792                {
793                        int yend = (posy + height) * tmpfb->width;
794                        posy *= tmpfb->width;
795                        int xend = posx + width;
796                        int xlen = (xend - posx) * tmpfb->colbytes;
797                        int r = 0;
798                        unsigned char* from = tmpfb->fb + (posy + posx) * tmpfb->colbytes;
799
800                        for(y = posy; y < yend; y += tmpfb->width)     
801                        {
802                                if(r == 0)
803                                {
804                                        r = 1;
805                                        for(x = posx; x < xend; x++)
806                                                drawpixelfastfb(tmpfb, x, y, tmpcol);
807                                }
808                                else
809                                {
810//                                      printf("befor memcpy_area\n");
811                                        memcpy(tmpfb->fb + (y + posx) * tmpfb->colbytes, from, xlen);
812                                        // return 100 error on branch 3.4
813//                                      memcpy_area(tmpfb->fb + (y + posx) * tmpfb->colbytes, from, posx * 4, height-1, width*4, tmpfb->width*4);
814                                        //y = yend;
815                                }
816                               
817                        }
818                }
819        }
820        else if(mode == 1 || mode == 3)
821        {
822                //topline
823                for(x = 0; x < width; x++)
824                        drawpixelfb(tmpfb, posx + x, posy, tmpcol);
825                //bottomline
826                for(x = 0; x < width; x++)
827                        drawpixelfb(tmpfb, posx + x, posy + height - 1, tmpcol);
828                //leftline
829                for(y = 0; y < height; y++)
830                        drawpixelfb(tmpfb, posx, posy + y, tmpcol);
831                //rightline
832                for(y = 0; y < height; y++)
833                        drawpixelfb(tmpfb, posx + width - 1, posy + y, tmpcol);
834        }
835
836/*
837        unsigned long tmpcol;
838
839        transparent = (transparent - 255) * -1;
840        tmpcol = color | ((transparent & 0xff) << 24);
841
842        STMFBIO_BLT_DATA  bltData;
843        memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA));
844
845        if(posx < 0) posx = 0;
846        if(posy < 0) posy = 0;
847        if(mode < 2)
848        {
849                if(posx > skinfb->width) posx = skinfb->width;
850                if(posy > skinfb->height) posy = skinfb->height;
851                if(posx + width > skinfb->width) width = skinfb->width - posx;
852                if(posy + height > skinfb->height) height = skinfb->height - posy;
853        }
854        else
855        {
856                if(posx > fb->width) posx = fb->width;
857                if(posy > fb->height) posy = fb->height;
858                if(posx + width > fb->width) width = fb->width - posx;
859                if(posy + height > fb->height) height = fb->height - posy;
860        }
861
862        if(width <= 0 || height <= 0) return;
863
864        if(mode == 0 || mode == 2)
865                bltData.operation  = BLT_OP_FILL;
866        else if(mode == 1 || mode == 3)
867                bltData.operation  = BLT_OP_DRAW_RECTANGLE;
868        bltData.colour     = tmpcol;
869        bltData.srcFormat  = SURF_ARGB8888;
870        bltData.srcMemBase = STMFBGP_FRAMEBUFFER;
871
872        if(status.usedirectfb == 1)
873                bltData.dstOffset  = 0;
874        else
875        {
876                if(mode < 2)
877                        bltData.dstOffset  = fb->varfbsize;
878                else
879                        bltData.dstOffset  = 0;
880        }
881        if(mode < 2)
882                bltData.dstPitch   = skinfb->pitch;
883        else
884                bltData.dstPitch   = fb->pitch;
885        bltData.dst_top    = posy;
886        bltData.dst_left   = posx;
887        bltData.dst_bottom = posy + height;
888        bltData.dst_right  = posx + width;
889        bltData.dstFormat  = SURF_ARGB8888;
890        bltData.dstMemBase = STMFBGP_FRAMEBUFFER;
891
892        if(ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
893        {
894                perr("ioctl STMFBIO_BLT");
895        }
896        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
897        {
898                perr("ioctl STMFBIO_SYNC_BLITTER");
899        }
900*/
901}
902
903int readjpg(const char* filename, unsigned long* width, unsigned long* height, unsigned long* rowbytes, int* channels, unsigned char **mem, int *memfd)
904{
905/*
906#ifndef SIMULATE
907        FILE *fp;
908        unsigned int temp1, temp2;
909
910        if(filename == NULL) return -1;
911
912        debug(200, "hardware decode picture (%s)...", filename);
913
914        if (!(fp = fopen(filename, "rb")))
915                return -1;
916         
917        if(get_jpeg_img_size(fp, &temp1, &temp2) != LIBMMEIMG_SUCCESS)
918                return -1;
919       
920        *width = temp1;
921        *height = temp2;
922        *channels = 3;
923        *rowbytes = *channels * temp1;
924       
925        if(allocbpamem(temp1 * temp2 * (*channels), memfd, mem) != 0)
926        {
927                fclose(fp);
928                return -1;
929        }
930               
931        if(decode_jpeg_noalloc(fp, temp1, temp2, temp1, temp2, (char *)*mem, 1) == LIBMMEIMG_SUCCESS)
932        {
933                fclose(fp);
934                return 0;
935        }
936       
937        fclose(fp);
938        freebpamem(*memfd, *mem, temp1 * temp2 * (*channels));
939        err("hardware decode error");
940#endif
941        return -1;
942*/
943return -1;
944}
945
946//flag 0: blit from accelfb to skinfb
947//flag 1: blit from skinfb to accelfb
948void blitscale(int posx, int posy, int width, int height, int scalewidth, int scaleheight, int flag)
949{
950#ifndef SIMULATE
951//#ifdef BLITHELP
952        unsigned char *source = NULL;
953        unsigned char *target = NULL;
954        int zpitch = 0;
955        int zheight = 0;
956        int zwidth = 0;
957        int qpitch = 0;
958        int qheight = 0;
959        int qwidth = 0;
960        unsigned long source_phys = 0;
961        unsigned long target_phys = 0;
962
963        if(scalewidth == 0) scalewidth = width;
964        if(scaleheight == 0) scaleheight = height;
965
966        if(posx < 0) posx = 0;
967        if(posx > skinfb->width) posx = skinfb->width;
968        if(posy < 0) posy = 0;
969        if(posy > skinfb->height) posy = skinfb->height;
970        if(posx + scalewidth > skinfb->width) scalewidth = skinfb->width - posx;
971        if(posy + scaleheight > skinfb->height) scaleheight = skinfb->height - posy;
972       
973        if(width <= 0 || height <= 0 || scalewidth <= 0 || scaleheight <= 0) return;
974       
975        if(flag == 1 && (scalewidth * scaleheight * 4) > accelfb->varfbsize)
976        {
977                err("accelfb to small %d -> %lu ", scalewidth * scaleheight * 4, accelfb->varfbsize);
978                return;
979        }
980        if(flag == 0)
981        {
982                source = accelfb->fb;
983                source_phys = accelfb->data_phys;
984                target_phys = skinfb->data_phys;
985
986                target = skinfb->fb + (posy * skinfb->pitch) + (posx*4);
987                zpitch = skinfb->pitch;
988                zheight = skinfb->height;
989                zwidth = skinfb->width;
990                qpitch = width*4;
991                qheight = height;
992                qwidth = width;
993        }
994        else
995        {
996                source = skinfb->fb;
997                source_phys = skinfb->data_phys;
998                target_phys = accelfb->data_phys;
999
1000                target = accelfb->fb + (posy * accelfb->pitch) + (posx*4);
1001                zpitch = accelfb->pitch;
1002                zheight = accelfb->height;
1003                zwidth = accelfb->width;
1004                qpitch = width*4;
1005                qheight = height;
1006                qwidth = width;
1007        }
1008       
1009        if(status.bcm == 1 && source_phys > 0 && target_phys >0)
1010        {
1011                bcm_accel_blit(source_phys, qwidth, qheight, qpitch, 0, target_phys, zwidth, zheight, zpitch, 0, 0, width, height, posx, posy, scalewidth, scaleheight, 0, 0);
1012                flag = 1;
1013        }
1014#ifdef HAVE_HISILICON_ACCEL
1015        else if(source_phys > 0 && target_phys >0)
1016        {
1017                dinobot_accel_blit(source_phys, qwidth, qheight, qpitch, 0, target_phys, zwidth, zheight, zpitch, 0, 0, width, height, posx, posy, scalewidth, scaleheight, 0, 0, 0);
1018                flag = 1;
1019        }
1020#endif
1021        else
1022        {
1023                unsigned char *helpbuf = NULL;
1024                helpbuf = scale(source, width, height, 4, scalewidth, scaleheight, 0);
1025       
1026                size_t helpb = 0;
1027                size_t helpz = 0;
1028                size_t help = 0;
1029       
1030                while(helpz < scaleheight && helpz < (zheight - posy)) {
1031                        //memcpy(target[help], helpbuf[helpb], scalewidth*4);
1032                        memcpy(target+help, helpbuf+helpb, scalewidth*4);
1033                        help = help + zpitch;
1034                        helpb = helpb + scalewidth*4;
1035                        helpz = helpz + 1;
1036                }
1037                free(helpbuf);
1038        }
1039       
1040       
1041        if(flag == 0)
1042                blit();
1043
1044//#endif
1045
1046/*
1047        STMFBIO_BLT_DATA  blt_data;
1048        memset(&blt_data, 0, sizeof(STMFBIO_BLT_DATA));
1049
1050        if(scalewidth == 0) scalewidth = width;
1051        if(scaleheight == 0) scaleheight = height;
1052
1053        if(posx < 0) posx = 0;
1054        if(posx > skinfb->width) posx = skinfb->width;
1055        if(posy < 0) posy = 0;
1056        if(posy > skinfb->height) posy = skinfb->height;
1057        if(posx + scalewidth > skinfb->width) scalewidth = skinfb->width - posx;
1058        if(posy + scaleheight > skinfb->height) scaleheight = skinfb->height - posy;
1059       
1060        if(width <= 0 || height <= 0 || scalewidth <= 0 || scaleheight <= 0) return;
1061       
1062        if(flag == 1 && (scalewidth * scaleheight * 4) > accelfb->varfbsize)
1063        {
1064                err("accelfb to small %d -> %lu ", scalewidth * scaleheight * 4, accelfb->varfbsize);
1065                return;
1066        }
1067
1068        blt_data.operation  = BLT_OP_COPY;
1069       
1070        if(flag == 0)
1071        {
1072                if(status.usedirectfb == 1)
1073                        blt_data.srcOffset  = fb->varfbsize;
1074                else
1075                        blt_data.srcOffset  = fb->varfbsize + skinfb->varfbsize;
1076        }
1077        else
1078        {
1079                if(status.usedirectfb == 1)
1080                        blt_data.srcOffset  = 0;
1081                else
1082                        blt_data.srcOffset  = fb->varfbsize;
1083        }
1084       
1085        blt_data.srcPitch   = width * 4;
1086        blt_data.src_top    = 0;
1087        blt_data.src_left   = 0;
1088        blt_data.src_right  = width;
1089        blt_data.src_bottom = height;
1090        blt_data.srcFormat  = SURF_ARGB8888;
1091        blt_data.srcMemBase = STMFBGP_FRAMEBUFFER;
1092       
1093        if(flag == 0)
1094        {
1095                if(status.usedirectfb == 1)
1096                {
1097                        blt_data.dstOffset  = 0;
1098                        blt_data.dstPitch   = fb->pitch;
1099                }
1100                else
1101                {
1102                        blt_data.dstOffset  = fb->varfbsize;
1103                        blt_data.dstPitch   = skinfb->pitch;
1104                }
1105        }
1106        else
1107        {
1108                if(status.usedirectfb == 1)
1109                {
1110                        blt_data.dstOffset  = fb->varfbsize;
1111                        blt_data.dstPitch   = skinfb->pitch;
1112                }
1113                else
1114                {
1115                        blt_data.dstOffset  = fb->varfbsize + skinfb->varfbsize;
1116                        blt_data.dstPitch   = scalewidth * 4;
1117                }
1118        }
1119       
1120        blt_data.dst_left   = posx;
1121        blt_data.dst_top    = posy;
1122        blt_data.dst_right  = posx + scalewidth;
1123        blt_data.dst_bottom = posy + scaleheight;
1124        blt_data.dstFormat  = SURF_ARGB8888;
1125        blt_data.dstMemBase = STMFBGP_FRAMEBUFFER;
1126       
1127        if (ioctl(fb->fd, STMFBIO_BLT, &blt_data) < 0)
1128        {
1129                perr("ioctl STMFBIO_BLT");
1130        }
1131        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
1132        {
1133                perr("ioctl STMFBIO_SYNC_BLITTER");
1134        }
1135*/
1136#endif
1137}
1138
1139void blitjpg(unsigned char* buf, int posx, int posy, int width, int height, int scalewidth, int scaleheight, int mwidth, int mheight, int halign, int valign)
1140//void blitjpg(unsigned char* buf, int posx, int posy, int width, int height, int scalewidth, int scaleheight)
1141{
1142#ifndef SIMULATE
1143#ifdef BLITHELP
1144        unsigned char *helpbuf = NULL;
1145        unsigned char *framebuf = NULL;
1146
1147        if(scalewidth != 0 || scaleheight != 0) {
1148                helpbuf = scale(buf, width, height, 3, scalewidth, scaleheight, 1);
1149                if(helpbuf == NULL)
1150                        return;
1151        }
1152        else {
1153                helpbuf = buf;
1154                scalewidth = width;
1155                scaleheight = height;
1156        }
1157        size_t helpb = 0;
1158        size_t helpz = 0;
1159        size_t help = 0;
1160       
1161        framebuf = skinfb->fb;
1162        framebuf = framebuf + (posy * skinfb->pitch) + (posx*4);
1163       
1164        while(helpz < scaleheight && helpz < (skinfb->height - posy)) {
1165                help = 0;
1166                while(help < (scalewidth*4) && help < (skinfb->pitch - (posx*4))) {
1167                        framebuf[help+0] = helpbuf[helpb+2];
1168                        framebuf[help+1] = helpbuf[helpb+1];
1169                        framebuf[help+2] = helpbuf[helpb+0];
1170                        framebuf[help+3] = 0xff;
1171                        help = help + 4;
1172                        helpb = helpb + 3;
1173                }
1174                if(help >= (skinfb->pitch - (posx*4)))
1175                        helpb = (helpz+1) * (scalewidth*3);
1176                framebuf = framebuf + skinfb->pitch;
1177                helpz = helpz + 1;
1178        }
1179        free(helpbuf);
1180        blit();
1181#endif
1182                 
1183/*
1184        STMFBIO_BLT_EXTERN_DATA blt_data;
1185        memset(&blt_data, 0, sizeof(STMFBIO_BLT_EXTERN_DATA));
1186
1187        blt_data.operation  = BLT_OP_COPY;
1188        blt_data.ulFlags    = 0;
1189        blt_data.srcOffset  = 0;
1190        blt_data.srcPitch   = width * 3;
1191        blt_data.dstOffset  = 0;
1192        blt_data.dstPitch   = skinfb->pitch;
1193        blt_data.src_top    = 0;
1194        blt_data.src_left   = 0;
1195        blt_data.src_right  = width;
1196        blt_data.src_bottom = height;
1197        blt_data.dst_left   = posx;
1198        blt_data.dst_top    = posy;
1199       
1200        if(scalewidth == 0)  scalewidth = width;
1201        if(scaleheight == 0) scaleheight = height;
1202       
1203        blt_data.dst_right  = posx + scalewidth;
1204        blt_data.dst_bottom = posy + scaleheight;
1205        blt_data.srcFormat  = SURF_BGR888;
1206        blt_data.dstFormat  = SURF_ARGB8888;
1207        blt_data.srcMemBase = (char *)buf;
1208        blt_data.dstMemBase = (char *)skinfb->fb;
1209        blt_data.srcMemSize = width * height * 3;
1210        blt_data.dstMemSize = skinfb->pitch * skinfb->height;
1211       
1212        if(ioctl(skinfb->fd, STMFBIO_BLT_EXTERN, &blt_data) < 0)
1213        {
1214                err("ioctl STMFBIO_BLT_EXTERN");
1215        }
1216        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
1217        {
1218                perr("ioctl STMFBIO_SYNC_BLITTER");
1219        }
1220*/
1221
1222#endif
1223}
1224
1225void initsignal(struct sigaction* sa)
1226{
1227        sigaction(SIGILL, sa, NULL);
1228        sigaction(SIGBUS, sa, NULL);
1229        sigaction(SIGFPE, sa, NULL);
1230        sigaction(SIGUSR1, sa, NULL);
1231        sigaction(SIGSEGV, sa, NULL);
1232        sigaction(SIGUSR2, sa, NULL);
1233        sigaction(SIGPIPE, sa, NULL);
1234        sigaction(SIGALRM, sa, NULL);
1235//      sigaction(SIGSTKFLT, sa, NULL);
1236        sigaction(SIGABRT, sa, NULL);
1237
1238        signal(SIGHUP, SIG_IGN);
1239        signal(SIGINT, SIG_IGN);
1240        signal(SIGTRAP, SIG_IGN);
1241        signal(SIGXCPU, SIG_IGN);
1242        signal(SIGXFSZ, SIG_IGN);
1243        signal(SIGVTALRM, SIG_IGN);
1244        signal(SIGPROF, SIG_IGN);
1245        signal(SIGPOLL, SIG_IGN);
1246        signal(SIGRTMAX, SIG_IGN);
1247        signal(SIGPWR, SIG_IGN);
1248        signal(SIGSYS, SIG_IGN);
1249}
1250
1251void sighandler(int sig, struct sigcontext ctx)
1252{
1253        switch(sig)
1254        {
1255                case SIGALRM:
1256                {
1257                        err("got signal sigalrm but ignore it");
1258                        break;
1259                }
1260                case SIGPIPE:
1261                {
1262                        err("got signal sigpipe but ignore it");
1263                        break;
1264                }
1265                case SIGUSR1:
1266                {
1267                        //todo all configs
1268                        reloadconfig(status.configfile);
1269                        reloadconfig(getconfig("ownconfig", NULL));
1270                        break;
1271                }
1272                case SIGUSR2: //called if hanging mainthread detect
1273                {
1274                        debugstack(sig, NULL, NULL);
1275                        break;
1276                }
1277                case SIGILL:
1278                case SIGBUS:
1279                case SIGFPE:
1280                case SIGSEGV:
1281//              case SIGSTKFLT:
1282                {
1283/*
1284#ifdef SIMULATE
1285                        //intel
1286                        debugstack((void *)ctx.eip, NULL);
1287                        err("got signal %d, fault address 0x%lx from 0x%lx", sig, ctx.cr2, ctx.eip);
1288#else
1289                        // sh4
1290                        //unsigned long sc_regs[16];
1291                        //unsigned long sc_pc; //programm counter register
1292                        //unsigned long sc_pr; //procedure register
1293                        //unsigned long sc_sr; //status register
1294                        //unsigned long sc_gbr;
1295                        //unsigned long sc_mach;
1296                        //unsigned long sc_macl;
1297
1298                        debugstack(sig, (void *)ctx.sc_pr, (void *)ctx.sc_pc);
1299                        err("got signal %d (%s), programm counter reg: 0x%lx,  procedure reg: 0x%lx", sig, strsignal(sig), ctx.sc_pc, ctx.sc_pr);
1300#endif
1301*/
1302                        if(getconfigint("saverun", NULL) == 1 && status.longjumpbuf != NULL)
1303                                siglongjmp(status.longjumpbuf, 999);
1304                        else
1305                                exit(100);
1306                        break;
1307                }
1308        }
1309}
1310
1311int setvmpeg(struct dvbdev* node, int value, int flag)
1312{
1313        debug(4440, "in");
1314        char* vmpegdev = NULL, *tmpstr = NULL, *buf = NULL;
1315        int ret = 0;
1316
1317        if(getskinconfigint("minitv", NULL) == 1)
1318                return 0;
1319
1320        if(node == NULL) return 1;
1321        if(flag == 0)  vmpegdev = getconfig("vmpegleftdev", NULL);
1322        if(flag == 1)  vmpegdev = getconfig("vmpegtopdev", NULL);
1323        if(flag == 2)  vmpegdev = getconfig("vmpegwidthdev", NULL);
1324        if(flag == 3)  vmpegdev = getconfig("vmpegheightdev", NULL);
1325        if(flag == 99) vmpegdev = getconfig("vmpegapplydev", NULL);
1326
1327        if(vmpegdev != NULL)
1328        {
1329                buf = malloc(MINMALLOC);
1330                if(buf == NULL)
1331                {
1332                        err("no mem");
1333                        return 1;
1334                }
1335               
1336                tmpstr = malloc(10);
1337                if(tmpstr == NULL)
1338                {
1339                        err("no mem");
1340                        free(buf);
1341                        return 1;
1342                }
1343               
1344                snprintf(buf, MINMALLOC, vmpegdev, node->devnr);
1345                snprintf(tmpstr, 10, "%x", value);
1346                debug(444, "set %s to %s", buf, tmpstr);
1347                status.tvpic = 1;
1348                ret = writesys(buf, tmpstr, 1);
1349               
1350                free(tmpstr);
1351                free(buf);
1352                return ret;
1353        }
1354
1355        debug(4440, "out");
1356        return 0;
1357}
1358
1359//flag 0: wh = width
1360//flag 1: wh = height
1361//int setvmpegrect(struct dvbdev* node, int left, int top, int wh, int flag)
1362int setvmpegrect(struct dvbdev* node, int posx, int posy, int wh, int flag)
1363{
1364        int ret = 0;
1365        int leftoffset = status.leftoffset;
1366        int rightoffset = status.rightoffset;
1367        int topoffset = status.topoffset;
1368        int bottomoffset = status.bottomoffset;
1369
1370        float rx = (float)720 / (float)(720 - leftoffset - rightoffset);
1371        float ry = (float)576 / (float)(576 - topoffset - bottomoffset);
1372
1373        posx = (float)posx / rx;
1374        posx += leftoffset;
1375
1376        posy = (float)posy / ry;
1377        posy += topoffset;
1378
1379        ret = setvmpeg(node, posx, 0);
1380        ret = setvmpeg(node, posy, 1);
1381       
1382        if(flag == 0)
1383        {
1384                wh = wh * (720 - leftoffset - rightoffset) / 720;
1385                ret = setvmpeg(node, wh, 2);
1386                ret = setvmpeg(node, (int)((float)wh / 1.2), 3);
1387        }
1388
1389        if(flag == 1)
1390        {
1391                wh = wh * (576 - topoffset - bottomoffset) / 576;
1392                ret = setvmpeg(node, wh, 3);
1393                ret = setvmpeg(node, (int)((float)wh * 1.2), 2);
1394        }
1395       
1396        setvmpeg(node, 0, 99);
1397       
1398        return ret;
1399}
1400       
1401int resetvmpeg(struct dvbdev* node)
1402{
1403        int ret = 0;
1404
1405        ret = setvmpeg(node, 0, 0);
1406        ret = setvmpeg(node, 0, 1);
1407        ret = setvmpeg(node, 0, 2);
1408        ret = setvmpeg(node, 0, 3);
1409       
1410        ret = setvmpeg(node, 0, 99);
1411
1412        status.tvpic = 0;
1413                       
1414        return ret;
1415}
1416
1417int resettvpic()
1418{
1419/*
1420        if(status.tvpic == 1 && status.aktservice != NULL)
1421        {
1422                status.tvpic = 0;
1423                resetvmpeg(status.aktservice->videodev);
1424        }
1425*/
1426        int ret = 0;
1427
1428        if(status.tvpic > 0 && status.aktservice != NULL)
1429                ret = resetvmpeg(status.aktservice->videodev);
1430
1431        return ret;
1432}
1433
1434int cagetslotinfo(struct dvbdev* node, ca_slot_info_t* info)
1435{
1436        int ret = 0;
1437       
1438        if(node == NULL || info == NULL)
1439        {
1440                err("NULL detect");
1441                return 1;
1442        }
1443       
1444        struct pollfd fds;
1445       
1446        fds.fd = node->fd;
1447        fds.events = POLLOUT | POLLPRI | POLLIN;
1448       
1449        info->flags = 0;
1450       
1451        ret = TEMP_FAILURE_RETRY(poll(&fds, 1, 1000));
1452       
1453        if(ret < 0)
1454        {
1455                err("poll data");
1456                return 1; //error
1457        }
1458        else if(ret == 0)
1459                return 0; //timeout
1460        else if(ret > 0)
1461        {
1462                if(fds.revents & POLLOUT)
1463                        info->flags = CA_CI_MODULE_READY;
1464                if(fds.revents & POLLIN)
1465                        info->flags = CA_CI_MODULE_READY;
1466                if(fds.revents & POLLPRI)
1467                        info->flags = 0;
1468        }
1469
1470        return 0;
1471}
1472
1473void memcpy_word(char* dest, char* src, long anzw)
1474{
1475        // Folgende Werte m�ssen volatile definiert sein
1476        // char* memcpy_word_src ---> pointer Quelle
1477        // char* memcpy_word_dest ---> pointer Ziehl
1478        // long  memcpy_word_anzw ---> Anzahl der W�rter (4 byte) die kopiert werden sollen.
1479       
1480        memcpy_word_src = src;
1481        memcpy_word_dest = dest;
1482        memcpy_word_anzw = anzw;
1483
1484#ifndef ARM     
1485        asm(   
1486                                "               lw        $8, memcpy_word_src           \n"
1487                                "               lw        $9, memcpy_word_dest  \n"                             
1488                                "               lw              $10, memcpy_word_anzw   \n"             
1489                                "               addi    $10, $10, -1                                    \n"
1490                                "loop1:                                                                                                 \n"
1491                                "               lw        $11, ($8)                                                     \n"
1492                                "               sw        $11, ($9)                                                     \n"
1493                                "               addi    $8, $8, 4                                                       \n"
1494                                "               addi    $9, $9, 4                                                       \n"
1495                                "               addi    $10, $10, -1                                    \n"
1496                                "               bgez    $10, loop1                                              \n"
1497                        );
1498#endif
1499
1500}
1501
1502void memcpy_byte(char* dest, char* src, long anzb)
1503{
1504        // Folgende Werte m�ssen volatile definiert sein
1505        // char* memcpy_byte_src ---> pointer Quelle
1506        // char* memcpy_byte_dest ---> pointer Ziehl
1507        // long  memcpy_byte_anzb ---> Anzahl bytes die kopiert werden sollen.
1508       
1509        memcpy_byte_src = src;
1510        memcpy_byte_dest = dest;
1511        memcpy_byte_anzb = anzb;
1512       
1513#ifndef ARM     
1514        asm (   
1515                                "               li    $12, 4                                                            \n"
1516                                "               lw        $8, memcpy_byte_src           \n"
1517                                "               lw        $9, memcpy_byte_dest  \n"                             
1518                                "               lw              $10, memcpy_byte_anzb   \n"             
1519                                "word:                                                                                                  \n"
1520                                "               bltu    $10, $12, byte                          \n"
1521                                "               lw        $11, ($8)                                                     \n"
1522                                "               sw        $11, ($9)                                                     \n"
1523                                "               addi    $8, $8, 4                                                       \n"
1524                                "               addi    $9, $9, 4                                                       \n"
1525                                "               addi    $10, $10, -4                                    \n"
1526                                "               b                       word                                                                    \n"
1527                                "byte:                                                                                                  \n"
1528                                "               beqz    $10, end                                                        \n"
1529                                "               lb        $11, ($8)                                                     \n"
1530                                "               sb        $11, ($9)                                                     \n"
1531                                "               addi    $8, $8, 1                                                       \n"
1532                                "               addi    $9, $9, 1                                                       \n"
1533                                "               addi    $10, $10, -1                                    \n"             
1534                                "               b     byte                                                                      \n"
1535                                "end:                                                                                                           \n"
1536                                "               nop                                                                                                     \n"       
1537                        );
1538#endif
1539}
1540
1541
1542void memcpy_area(unsigned char* targetADDR, unsigned char* startADDR, long pxAbs, long hight, long widthAbs, long FBwidthAbs)
1543{
1544
1545#ifndef ARM
1546        asm(   
1547
1548                                "               lw    $t3, %[targetADDR]                                                                                                        \n"
1549                                "               lw    $t4, %[startADDR]                                                                                                 \n"
1550                                "               lw              $t5, %[pxAbs]                                                                                                                   \n"
1551                                "               lw    $t6, %[widthAbs]                                                                                                  \n"
1552                                "               lw    $t7, %[FBwidthAbs]                                                                                                \n"
1553                                "               lw    $t8, %[hight]                                                                                                                     \n"
1554
1555                                "               move  $t0, $t4      # Temp-startADDR                                                    \n" 
1556                                "               move  $t1, $t6      # Temp-widthAbs                                                             \n"
1557                                "               add   $t2, $t5, $t6                                                                                                                             \n"
1558                                "               sub   $t7, $t7, $t2 # Diff withAbs und FBwidthAbs       \n"
1559
1560                                "p3NewLine2:                                                                                                                                                                    \n"             
1561                                "               beqz  $t8, p3End                                                                                                                                        \n"
1562                                "p3NextWord:                                                                                                                                                                    \n"
1563                                "   beqz  $t1, p3NewLine1                                                                                                                       \n"
1564                                "               lw    $t9, ($t0)                                                                                                                                        \n"
1565                                "               sw    $t9, ($t3)                                                                                                                                        \n"
1566                                "               addi  $t0, 4                                                                                                                                                    \n"
1567                                "               addi  $t3, 4                                                                                                                                                    \n"
1568                                "               addi  $t1, -4                                                                                                                                                   \n"
1569                                "               b     p3NextWord                                                                                                                                        \n"
1570
1571               
1572                                "p3NewLine1:                                                                                                                                                                    \n"
1573                                "               move  $t0, $t4                                                                                                                                          \n"
1574                                "               move  $t1, $t6                                                                                                                                          \n"
1575                                "               add   $t3, $t3, $t7                                                                                                                             \n"
1576                                "               add   $t3, $t3, $t5                                                                                                                             \n"
1577                                "               addi  $t8, -1                                                                                                                                                   \n"
1578                                "               b     p3NewLine2                                                                                                                                        \n"
1579
1580                                "p3End:                                                                                                                                                                                         \n"
1581                                "               nop                                                                                                                                                                                             \n"     
1582                                ::[targetADDR] "m" (targetADDR), [startADDR] "m" (startADDR), [pxAbs] "m" (pxAbs), [widthAbs] "m" (widthAbs), [FBwidthAbs] "m" (FBwidthAbs), [hight] "m" (hight)
1583                                );
1584#endif
1585                               
1586        return;
1587}
1588
1589int setfbosddev(char* dev, int value)
1590{
1591        char* tmpstr = NULL;
1592        int ret = 0;
1593
1594        tmpstr = malloc(10);
1595        if(tmpstr == NULL)
1596        {
1597                err("no mem");
1598                return 1;
1599        }
1600       
1601        sprintf(tmpstr, "%x", value);
1602        debug(101, "set %s to %s", dev, tmpstr);
1603
1604        if(dev != NULL)
1605        {
1606                ret = writesys(dev, tmpstr, 1);
1607                return ret;
1608        }
1609
1610        return 0;
1611}
1612
1613char* getfbosddev(char* dev)
1614{
1615        char *value = NULL;
1616
1617        if(dev == NULL)
1618        {
1619                err("NULL detect");
1620                return NULL;
1621        }
1622
1623        value = readsys(dev, 1);
1624        if(value == NULL)
1625        {
1626                err("NULL detect");
1627                return NULL;
1628        }
1629
1630        debug(101, "get %s to %s", dev, value);
1631               
1632        return value;
1633}
1634
1635void setfbosdnull()
1636{
1637        char* fbleftdev = "/proc/stb/fb/dst_left";
1638        char* fbwidthdev = "/proc/stb/fb/dst_width";
1639        char* fbtopdev = "/proc/stb/fb/dst_top";
1640        char* fbheightdev = "/proc/stb/fb/dst_height";
1641        char* fbapplydev = "/proc/stb/fb/dst_apply";
1642        setfbosddev(fbleftdev, 0);
1643        setfbosddev(fbwidthdev, 720);
1644        setfbosddev(fbtopdev, 0);
1645        setfbosddev(fbheightdev, 576);
1646        setfbosddev(fbapplydev, 0);
1647}
1648
1649void setfbosd()
1650{
1651#ifndef ARM
1652        debug(101, "################## set osd offset ####################");
1653        debug(101, "status.leftoffset: %d", status.leftoffset);
1654        debug(101, "status.rightoffset: %d", status.rightoffset);
1655        debug(101, "status.topoffset: %d", status.topoffset);
1656        debug(101, "status.bottomoffset: %d", status.bottomoffset);
1657       
1658        char* fbleftdev = "/proc/stb/fb/dst_left";
1659        char* fbwidthdev = "/proc/stb/fb/dst_width";
1660        char* fbtopdev = "/proc/stb/fb/dst_top";
1661        char* fbheightdev = "/proc/stb/fb/dst_height";
1662       
1663        int fbleft = strtol(getfbosddev(fbleftdev) , NULL, 16);
1664        int fbwidth = strtol(getfbosddev(fbwidthdev) , NULL, 16);
1665        int fbtop = strtol(getfbosddev(fbtopdev) , NULL, 16);
1666        int fbheight = strtol(getfbosddev(fbheightdev) , NULL, 16);
1667        debug(101, "Setting OSD position: %d %d %d %d", fbleft ,fbwidth ,fbtop ,fbheight);
1668       
1669        fbleft = status.leftoffset;
1670        fbwidth = 720 - status.leftoffset - status.rightoffset;
1671        fbtop = status.topoffset;
1672        fbheight = 576 - status.topoffset - status.bottomoffset;
1673        debug(101, "Setting OSD position changed: %d %d %d %d", fbleft ,fbwidth ,fbtop ,fbheight);
1674        debug(10, "Setting OSD position changed: %d %d %d %d", fbleft ,fbwidth ,fbtop ,fbheight);
1675       
1676        setfbosddev(fbleftdev, fbleft);
1677        setfbosddev(fbwidthdev, fbwidth);
1678        setfbosddev(fbtopdev, fbtop);
1679        setfbosddev(fbheightdev, fbheight);
1680        debug(101, "######################################################");
1681#endif
1682}
1683
1684#ifdef CONFIG_ION
1685void SetMode()
1686{
1687        printf("****** SetMode **********\n");
1688        struct fb_var_screeninfo var_screeninfo;
1689       
1690        lfb = fb->fb;
1691        /* unmap old framebuffer with old size */
1692        if (lfb)
1693                //munmap(lfb, stride * screeninfo.yres_virtual);
1694                munmap(lfb, fb->varfbsize);
1695
1696        var_screeninfo.xres_virtual = fb->width;
1697        var_screeninfo.xres = fb->width;
1698        var_screeninfo.yres_virtual = fb->height * 2;
1699        var_screeninfo.yres = fb->height;
1700        var_screeninfo.height = 0;
1701        var_screeninfo.width = 0;
1702        var_screeninfo.xoffset = 0;
1703        var_screeninfo.yoffset = 0;
1704        var_screeninfo.bits_per_pixel = fb->colbytes * 8;
1705       
1706        switch(fb->colbytes)
1707        {
1708                case 2:
1709                        var_screeninfo.transp.offset = 15;
1710                        var_screeninfo.transp.length = 1;
1711                        var_screeninfo.red.offset = 10;
1712                        var_screeninfo.red.length = 5;
1713                        var_screeninfo.green.offset = 5;
1714                        var_screeninfo.green.length = 5;
1715                        var_screeninfo.blue.offset = 0;
1716                        var_screeninfo.blue.length = 5;
1717                        break;
1718                case 4:
1719                        var_screeninfo.transp.offset = 24;
1720                        var_screeninfo.transp.length = 8;
1721                        var_screeninfo.red.offset = 16;
1722                        var_screeninfo.red.length = 8;
1723                        var_screeninfo.green.offset = 8;
1724                        var_screeninfo.green.length = 8;
1725                        var_screeninfo.blue.offset = 0;
1726                        var_screeninfo.blue.length = 8;
1727                        break;
1728        }
1729       
1730        debug(444, "FB: line_length %d", fix_screeninfo.line_length);
1731        debug(444, "FB: var_screeninfo.xres %d", var_screeninfo.xres);
1732        debug(444, "FB: var_screeninfo.yres %d", var_screeninfo.yres);
1733        debug(444, "FB: var_screeninfo.xres_virt %d", var_screeninfo.xres_virtual);
1734        debug(444, "FB: var_screeninfo.yres_virt %d", var_screeninfo.yres_virtual);
1735        debug(444, "FB: var_screeninfo.xoffset %d", var_screeninfo.xoffset);
1736        debug(444, "FB: var_screeninfo.yoffset %d", var_screeninfo.yoffset);
1737        debug(444, "FB: var_screeninfo.bits_per_pixel %d", var_screeninfo.bits_per_pixel);
1738        debug(444, "FB: var_screeninfo.grayscale %d", var_screeninfo.grayscale);
1739       
1740        if(ioctl(fb->fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0)
1741        {
1742                var_screeninfo.yres_virtual = fb->height;
1743                if(ioctl(fb->fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0)
1744                {
1745                        perr("FBIOPUT_VSCREENINFO");
1746                }
1747                debug(444, "FB: double buffering not available");
1748        }
1749        else
1750        {
1751                debug(444, "FB: double buffering available!");
1752        }
1753
1754        ioctl(fb->fd, FBIOGET_VSCREENINFO, &var_screeninfo);
1755        if ((var_screeninfo.xres!=fb->width) && (var_screeninfo.yres!=fb->height) && (var_screeninfo.bits_per_pixel!=fb->colbytes))
1756        {
1757                debug(444, "SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
1758                        fb->width, fb->height, fb->colbytes,
1759                        var_screeninfo.xres, var_screeninfo.yres, var_screeninfo.bits_per_pixel);
1760        }
1761        struct fb_fix_screeninfo fix;
1762        if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fix)<0)
1763        {
1764                perror("FBIOGET_FSCREENINFO");
1765                printf("fb failed\n");
1766        }
1767        /* map new framebuffer */
1768        lfb=(unsigned char*)mmap(0, fix.line_length * var_screeninfo.yres_virtual, PROT_WRITE|PROT_READ, MAP_SHARED, fb->fd, 0);
1769        fb->fb = lfb;
1770        fb->fblong = (unsigned long*)fb->fb;
1771        memset(lfb, 0, fix.line_length * var_screeninfo.yres_virtual);
1772        fb->varfbsize = fix.line_length * var_screeninfo.yres_virtual;
1773        blit();
1774}
1775#endif
1776
1777
1778#endif
Note: See TracBrowser for help on using the repository browser.