Rev 6137 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5371 | serge | 1 | #include |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | |||
6 | #include "pixlib3.h" |
||
7 | #include "pixdriver.h" |
||
8 | |||
9 | #define DISPLAY_VERSION 0x0200 /* 2.00 */ |
||
10 | |||
11 | #define SRV_GETVERSION 0 |
||
12 | #define SRV_GET_CAPS 3 |
||
13 | |||
14 | |||
15 | #define BUFFER_SIZE(n) ((n)*sizeof(uint32_t)) |
||
16 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
||
17 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
||
18 | |||
19 | struct bitmap |
||
20 | { |
||
21 | uint32_t width; |
||
22 | uint32_t height; |
||
23 | uint32_t pitch; |
||
24 | void *buffer; |
||
25 | uint32_t size; |
||
26 | }; |
||
27 | |||
28 | static uint32_t fd; |
||
29 | static struct pix_driver *driver; |
||
30 | |||
31 | |||
32 | static bitmap_t *sw_create_bitmap(uint32_t width, uint32_t height) |
||
33 | { |
||
34 | bitmap_t *bitmap; |
||
35 | |||
36 | bitmap = malloc(sizeof(bitmap_t)); |
||
37 | if(bitmap == NULL) |
||
38 | goto err_0; |
||
39 | |||
40 | bitmap->width = width; |
||
41 | bitmap->height = height; |
||
42 | |||
43 | bitmap->pitch = ALIGN(width * 4, 16); |
||
44 | bitmap->size = ALIGN(bitmap->pitch * height, 4096); |
||
45 | |||
46 | bitmap->buffer = user_alloc(bitmap->size); |
||
47 | if (bitmap->buffer == NULL) |
||
48 | goto err_1; |
||
49 | |||
50 | return bitmap; |
||
51 | |||
52 | err_1: |
||
53 | free(bitmap); |
||
54 | err_0: |
||
55 | return NULL; |
||
56 | }; |
||
57 | |||
58 | static int sw_destroy_bitmap(bitmap_t * bitmap) |
||
59 | { |
||
60 | user_free(bitmap->buffer); |
||
61 | free(bitmap); |
||
62 | return 0; |
||
63 | }; |
||
64 | |||
65 | static void *sw_lock_bitmap(bitmap_t *bitmap, uint32_t *pitch) |
||
66 | { |
||
67 | *pitch = bitmap->pitch; |
||
68 | |||
69 | return bitmap->buffer; |
||
70 | }; |
||
71 | |||
72 | static int sw_resize_bitmap(bitmap_t * bitmap, uint32_t width, uint32_t height) |
||
73 | { |
||
74 | uint32_t size; |
||
75 | uint32_t pitch; |
||
76 | |||
77 | pitch = ALIGN(width * 4, 16); |
||
78 | size = ALIGN(pitch * height, 4096); |
||
79 | |||
80 | if (size > bitmap->size) |
||
81 | { |
||
82 | bitmap->buffer = user_realloc(bitmap->buffer, size); /* grow buffer */ |
||
83 | if (bitmap->buffer == NULL) |
||
84 | return -1; |
||
85 | |||
86 | bitmap->size = size; |
||
87 | } |
||
88 | else if (size < bitmap->size) |
||
89 | user_unmap(bitmap->buffer, size, bitmap->size - size); /* unmap unused pages */ |
||
90 | |||
91 | bitmap->width = width; |
||
92 | bitmap->height = height; |
||
93 | bitmap->pitch = pitch; |
||
94 | |||
95 | return 0; |
||
96 | }; |
||
97 | |||
98 | static int sw_blit(bitmap_t * bitmap, int dst_x, int dst_y, |
||
99 | uint32_t w, uint32_t h, int src_x, int src_y) |
||
100 | { |
||
101 | struct blit_call bc; |
||
102 | int ret; |
||
103 | |||
104 | bc.dstx = dst_x; |
||
105 | bc.dsty = dst_y; |
||
106 | bc.w = w; |
||
107 | bc.h = h; |
||
108 | bc.srcx = src_x; |
||
109 | bc.srcy = src_y; |
||
110 | bc.srcw = bitmap->width; |
||
111 | bc.srch = bitmap->height; |
||
112 | bc.stride = bitmap->pitch; |
||
113 | bc.bitmap = bitmap->buffer; |
||
114 | |||
115 | __asm__ __volatile__( |
||
116 | "int $0x40":"=a"(ret):"a"(73), "b"(0x00), |
||
117 | "c"(&bc):"memory"); |
||
118 | |||
119 | return ret; |
||
120 | }; |
||
121 | |||
122 | static int sw_create_client(int x, int y, uint32_t width, uint32_t height) |
||
123 | { |
||
124 | return 0; |
||
125 | }; |
||
126 | |||
127 | static int sw_resize_client(int x, int y, uint32_t width, uint32_t height) |
||
128 | { |
||
129 | return 0; |
||
130 | }; |
||
131 | |||
132 | bitmap_t *pxCreateBitmap(uint32_t width, uint32_t height) |
||
133 | { |
||
134 | return driver->create_bitmap(width, height); |
||
135 | }; |
||
136 | |||
137 | int pxDestroyBitmap(bitmap_t *bitmap) |
||
138 | { |
||
139 | return driver->destroy_bitmap(bitmap); |
||
140 | }; |
||
141 | |||
142 | void *pxLockBitmap(bitmap_t *bitmap, uint32_t *pitch) |
||
143 | { |
||
144 | return driver->lock_bitmap(bitmap, pitch); |
||
145 | }; |
||
146 | |||
147 | int pxResizeBitmap(bitmap_t *bitmap, uint32_t width, uint32_t height) |
||
148 | { |
||
149 | return driver->resize_bitmap(bitmap, width, height); |
||
150 | }; |
||
151 | |||
152 | int pxBlitBitmap(bitmap_t *bitmap, int dst_x, int dst_y, |
||
153 | uint32_t w, uint32_t h, int src_x, int src_y) |
||
154 | { |
||
155 | return driver->blit_bitmap(bitmap, dst_x, dst_y, |
||
156 | w, h, src_x, src_y); |
||
157 | }; |
||
158 | |||
6142 | serge | 159 | planar_t* pxCreatePlanar(int name, int format, |
160 | uint32_t width, uint32_t height, |
||
161 | uint32_t offset0, uint32_t pitch0, |
||
162 | uint32_t offset1, uint32_t pitch1, |
||
163 | uint32_t offset2, uint32_t pitch2) |
||
164 | { |
||
165 | if(driver->create_planar) |
||
166 | return driver->create_planar(name, format, width, height, |
||
167 | offset0, pitch0, offset1, pitch1, |
||
168 | offset2, pitch2); |
||
169 | else |
||
170 | return NULL; |
||
171 | }; |
||
172 | |||
173 | int pxDestroyPlanar(planar_t *planar) |
||
174 | { |
||
175 | return driver->destroy_planar(planar); |
||
176 | }; |
||
177 | |||
178 | int pxBlitPlanar(planar_t *planar, int dst_x, int dst_y, |
||
179 | uint32_t w, uint32_t h, int src_x, int src_y) |
||
180 | { |
||
181 | if(driver->blit_planar) |
||
182 | return driver->blit_planar(planar, dst_x, dst_y, |
||
183 | w, h, src_x, src_y); |
||
184 | else |
||
185 | return 0; |
||
186 | }; |
||
187 | |||
5371 | serge | 188 | int pxCreateClient(int x, int y, uint32_t width, uint32_t height) |
189 | { |
||
190 | return driver->create_client(x, y, width, height); |
||
191 | } |
||
192 | |||
193 | int pxResizeClient(int x, int y, uint32_t width, uint32_t height) |
||
194 | { |
||
195 | return driver->resize_client(x, y, width, height); |
||
196 | } |
||
197 | |||
6142 | serge | 198 | |
5371 | serge | 199 | static struct pix_driver sw_driver = |
200 | { |
||
201 | 0, |
||
202 | sw_create_bitmap, |
||
203 | sw_destroy_bitmap, |
||
204 | sw_lock_bitmap, |
||
205 | sw_resize_bitmap, |
||
206 | sw_blit, |
||
207 | sw_create_client, |
||
208 | sw_resize_client, |
||
6142 | serge | 209 | NULL, /* fini() */ |
210 | NULL, /* create_planar() */ |
||
211 | NULL, /* destroy_planar() */ |
||
212 | NULL /* blit_planar() */ |
||
5371 | serge | 213 | }; |
214 | |||
215 | |||
216 | uint32_t pxInit(int hw) |
||
217 | { |
||
218 | void *lib; |
||
219 | struct pix_driver *(*drventry)(uint32_t service); |
||
220 | |||
221 | uint32_t api_version; |
||
222 | ioctl_t io; |
||
223 | |||
6137 | serge | 224 | if(driver != NULL) |
225 | return driver->driver_caps; |
||
226 | |||
5371 | serge | 227 | driver = &sw_driver; |
228 | |||
229 | if(hw == 0) |
||
230 | return 0; |
||
231 | |||
232 | if (fd != 0) |
||
233 | return driver->driver_caps; |
||
234 | |||
235 | fd = get_service("DISPLAY"); |
||
236 | if (fd == 0) |
||
237 | goto fail; |
||
238 | |||
239 | io.handle = fd; |
||
240 | io.io_code = SRV_GETVERSION; |
||
241 | io.input = NULL; |
||
242 | io.inp_size = 0; |
||
243 | io.output = &api_version; |
||
244 | io.out_size = BUFFER_SIZE(1); |
||
245 | |||
246 | if (call_service(&io) != 0) |
||
247 | goto fail; |
||
248 | |||
249 | if ((DISPLAY_VERSION > (api_version & 0xFFFF)) || |
||
250 | (DISPLAY_VERSION < (api_version >> 16))) |
||
251 | goto fail; |
||
252 | |||
253 | lib = load_library("pixlib-gl.dll"); |
||
254 | if(lib == 0) |
||
255 | goto fail; |
||
256 | |||
257 | drventry = get_proc_address(lib, "DrvInit"); |
||
258 | |||
259 | if( drventry == NULL) |
||
260 | goto fail; |
||
261 | |||
262 | driver = drventry(fd); |
||
263 | if(driver == NULL) |
||
264 | { |
||
265 | driver = &sw_driver; |
||
266 | goto fail; |
||
267 | }; |
||
268 | |||
269 | if (driver->driver_caps) |
||
270 | printf("2D caps %s%s%s\n", |
||
271 | (driver->driver_caps & HW_BIT_BLIT) != 0 ? "HW_BIT_BLIT " : "", |
||
272 | (driver->driver_caps & HW_TEX_BLIT) != 0 ? "HW_TEX_BLIT " : "", |
||
273 | (driver->driver_caps & HW_VID_BLIT) != 0 ? "HW_VID_BLIT " : ""); |
||
274 | |||
275 | return driver->driver_caps; |
||
276 | |||
277 | fail: |
||
278 | printf("Warning! Hardware initialization failed.\n" |
||
279 | "fallback to software rendering.\n"); |
||
280 | fd = 0; |
||
281 | return 0; |
||
282 | }; |
||
283 | |||
284 | void pxFini() |
||
285 | { |
||
286 | if (driver->fini) |
||
287 | driver->fini(); |
||
288 | };>> |
||
289 |