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