source: titan/titan/bcm.h @ 26727

Last change on this file since 26727 was 26432, checked in by obi, 10 years ago

add missing file

File size: 3.7 KB
Line 
1#ifndef BCM_H
2#define BCM_H
3
4/*
5  Interface to the Dreambox dm800/dm8000 proprietary accel interface.
6*/
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <fcntl.h>
11#include <unistd.h>
12#include <linux/fb.h>
13#include <sys/mman.h>
14#include <sys/ioctl.h>
15
16#define FBIO_ACCEL  0x23
17
18// bool work start
19typedef int bool;
20enum { false, true };
21// bool work end
22
23static unsigned int displaylist[1024];
24static int ptr;
25static bool supportblendingflags = true;
26
27#define P(x, y) do { displaylist[ptr++] = x; displaylist[ptr++] = y; } while (0)
28#define C(x) P(x, 0)
29
30static int fb_fd = -1;
31static int exec_list(void);
32
33int bcm_accel_init(void)
34{
35        fb_fd = open("/dev/fb0", O_RDWR);
36        if (fb_fd < 0)
37        {
38                perror("/dev/fb0");
39                return 1;
40        }
41        if (exec_list())
42        {
43                fprintf(stderr, "BCM accel interface not available - %m\n");
44                close(fb_fd);
45                fb_fd = -1;
46                return 1;
47        }
48        /* now test for blending flags support */
49        P(0x80, 0);
50        if (exec_list())
51        {
52                supportblendingflags = false;
53        }
54#ifdef FORCE_NO_BLENDING_ACCELERATION
55        /* hardware doesn't allow us to detect whether the opcode is working */
56        supportblendingflags = false;
57#endif
58        return 0;
59}
60
61void bcm_accel_close(void)
62{
63        if (fb_fd >= 0)
64        {
65                close(fb_fd);
66                fb_fd = -1;
67        }
68}
69
70static int exec_list(void)
71{
72        int ret;
73        struct
74        {
75                void *ptr;
76                int len;
77        } l;
78
79        l.ptr = displaylist;
80        l.len = ptr;
81        ret = ioctl(fb_fd, FBIO_ACCEL, &l);
82        ptr = 0;
83        return ret;
84}
85
86bool bcm_accel_has_alphablending()
87{
88        return supportblendingflags;
89}
90
91void bcm_accel_blit(
92                int src_addr, int src_width, int src_height, int src_stride, int src_format,
93                int dst_addr, int dst_width, int dst_height, int dst_stride,
94                int src_x, int src_y, int width, int height,
95                int dst_x, int dst_y, int dwidth, int dheight,
96                int pal_addr, int flags)
97{
98        C(0x43); // reset source
99        C(0x53); // reset dest
100        C(0x5b);  // reset pattern
101        C(0x67); // reset blend
102        C(0x75); // reset output
103
104        P(0x0, src_addr); // set source addr
105        P(0x1, src_stride);  // set source pitch
106        P(0x2, src_width); // source width
107        P(0x3, src_height); // height
108        switch (src_format)
109        {
110        case 0:
111                P(0x4, 0x7e48888); // format: ARGB 8888
112                break;
113        case 1:
114                P(0x4, 0x12e40008); // indexed 8bit
115                P(0x78, 256);
116                P(0x79, pal_addr);
117                P(0x7a, 0x7e48888);
118                break;
119        }
120
121        C(0x5); // set source surface (based on last parameters)
122
123        P(0x2e, src_x); // define  rect
124        P(0x2f, src_y);
125        P(0x30, width);
126        P(0x31, height);
127
128        C(0x32); // set this rect as source rect
129
130        P(0x0, dst_addr); // prepare output surface
131        P(0x1, dst_stride);
132        P(0x2, dst_width);
133        P(0x3, dst_height);
134        P(0x4, 0x7e48888);
135       
136        C(0x69); // set output surface
137       
138        P(0x2e, dst_x); // prepare output rect
139        P(0x2f, dst_y);
140        P(0x30, dwidth);
141        P(0x31, dheight);
142
143        C(0x6e); // set this rect as output rect
144
145        if (supportblendingflags && flags) P(0x80, flags); /* blend flags... We'd really like some blending support in the drivers, to avoid punching holes in the osd */
146
147        C(0x77);  // do it
148
149        exec_list();
150}
151
152void bcm_accel_fill(
153                int dst_addr, int dst_width, int dst_height, int dst_stride,
154                int x, int y, int width, int height,
155                unsigned long color)
156{
157        C(0x43); // reset source
158        C(0x53); // reset dest
159        C(0x5b); // reset pattern
160        C(0x67); // reset blend
161        C(0x75); // reset output
162
163        // clear dest surface
164        P(0x0, 0);
165        P(0x1, 0);
166        P(0x2, 0);
167        P(0x3, 0);
168        P(0x4, 0);
169        C(0x45);
170
171        // clear src surface
172        P(0x0, 0);
173        P(0x1, 0);
174        P(0x2, 0);
175        P(0x3, 0);
176        P(0x4, 0);
177        C(0x5);
178
179        P(0x2d, color);
180
181        P(0x2e, x); // prepare output rect
182        P(0x2f, y);
183        P(0x30, width);
184        P(0x31, height);
185        C(0x6e); // set this rect as output rect
186
187        P(0x0, dst_addr); // prepare output surface
188        P(0x1, dst_stride);
189        P(0x2, dst_width);
190        P(0x3, dst_height);
191        P(0x4, 0x7e48888);
192        C(0x69); // set output surface
193
194        P(0x6f, 0);
195        P(0x70, 0);
196        P(0x71, 2);
197        P(0x72, 2);
198        C(0x73); // select color keying
199
200        C(0x77);  // do it
201
202        exec_list();
203}
204
205#endif
206
Note: See TracBrowser for help on using the repository browser.