source: titan/titan/bcm.h @ 39231

Last change on this file since 39231 was 36554, checked in by gost, 8 years ago

[titan] BCM accel Step1

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