Rev 5371 | Rev 6115 | Go to most recent revision | 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 | |||
5375 | serge | 50 | // printf("create bitmap: %p %dx%d buffer: %p\n", |
51 | // bitmap, bitmap->width, bitmap->height, bitmap->buffer); |
||
5371 | serge | 52 | |
53 | return bitmap; |
||
54 | |||
55 | err_1: |
||
56 | free(bitmap); |
||
57 | err_0: |
||
58 | return NULL; |
||
59 | }; |
||
60 | |||
61 | static int sw_destroy_bitmap(bitmap_t * bitmap) |
||
62 | { |
||
63 | user_free(bitmap->buffer); |
||
64 | free(bitmap); |
||
65 | return 0; |
||
66 | }; |
||
67 | |||
68 | static void *sw_lock_bitmap(bitmap_t *bitmap, uint32_t *pitch) |
||
69 | { |
||
70 | *pitch = bitmap->pitch; |
||
71 | |||
72 | return bitmap->buffer; |
||
73 | }; |
||
74 | |||
75 | static int sw_resize_bitmap(bitmap_t * bitmap, uint32_t width, uint32_t height) |
||
76 | { |
||
77 | uint32_t size; |
||
78 | uint32_t pitch; |
||
79 | |||
80 | pitch = ALIGN(width * 4, 16); |
||
81 | size = ALIGN(pitch * height, 4096); |
||
82 | |||
83 | if (size > bitmap->size) |
||
84 | { |
||
85 | bitmap->buffer = user_realloc(bitmap->buffer, size); /* grow buffer */ |
||
86 | if (bitmap->buffer == NULL) |
||
87 | return -1; |
||
88 | |||
89 | bitmap->size = size; |
||
90 | } |
||
91 | else if (size < bitmap->size) |
||
92 | user_unmap(bitmap->buffer, size, bitmap->size - size); /* unmap unused pages */ |
||
93 | |||
94 | bitmap->width = width; |
||
95 | bitmap->height = height; |
||
96 | bitmap->pitch = pitch; |
||
97 | |||
98 | return 0; |
||
99 | }; |
||
100 | |||
101 | static int sw_blit(bitmap_t * bitmap, int dst_x, int dst_y, |
||
102 | uint32_t w, uint32_t h, int src_x, int src_y) |
||
103 | { |
||
104 | struct blit_call bc; |
||
105 | int ret; |
||
106 | |||
107 | bc.dstx = dst_x; |
||
108 | bc.dsty = dst_y; |
||
109 | bc.w = w; |
||
110 | bc.h = h; |
||
111 | bc.srcx = src_x; |
||
112 | bc.srcy = src_y; |
||
113 | bc.srcw = bitmap->width; |
||
114 | bc.srch = bitmap->height; |
||
115 | bc.stride = bitmap->pitch; |
||
116 | bc.bitmap = bitmap->buffer; |
||
117 | |||
118 | __asm__ __volatile__( |
||
119 | "int $0x40":"=a"(ret):"a"(73), "b"(0x00), |
||
120 | "c"(&bc):"memory"); |
||
121 | |||
122 | return ret; |
||
123 | }; |
||
124 | |||
125 | static int sw_create_client(int x, int y, uint32_t width, uint32_t height) |
||
126 | { |
||
127 | return 0; |
||
128 | }; |
||
129 | |||
130 | static int sw_resize_client(int x, int y, uint32_t width, uint32_t height) |
||
131 | { |
||
132 | return 0; |
||
133 | }; |
||
134 | |||
135 | bitmap_t *pxCreateBitmap(uint32_t width, uint32_t height) |
||
136 | { |
||
137 | return driver->create_bitmap(width, height); |
||
138 | }; |
||
139 | |||
140 | int pxDestroyBitmap(bitmap_t *bitmap) |
||
141 | { |
||
142 | return driver->destroy_bitmap(bitmap); |
||
143 | }; |
||
144 | |||
145 | void *pxLockBitmap(bitmap_t *bitmap, uint32_t *pitch) |
||
146 | { |
||
147 | return driver->lock_bitmap(bitmap, pitch); |
||
148 | }; |
||
149 | |||
150 | int pxResizeBitmap(bitmap_t *bitmap, uint32_t width, uint32_t height) |
||
151 | { |
||
152 | return driver->resize_bitmap(bitmap, width, height); |
||
153 | }; |
||
154 | |||
155 | int pxBlitBitmap(bitmap_t *bitmap, int dst_x, int dst_y, |
||
156 | uint32_t w, uint32_t h, int src_x, int src_y) |
||
157 | { |
||
158 | return driver->blit_bitmap(bitmap, dst_x, dst_y, |
||
159 | w, h, src_x, src_y); |
||
160 | }; |
||
161 | |||
162 | int pxCreateClient(int x, int y, uint32_t width, uint32_t height) |
||
163 | { |
||
164 | return driver->create_client(x, y, width, height); |
||
165 | } |
||
166 | |||
167 | int pxResizeClient(int x, int y, uint32_t width, uint32_t height) |
||
168 | { |
||
169 | return driver->resize_client(x, y, width, height); |
||
170 | } |
||
171 | |||
172 | static struct pix_driver sw_driver = |
||
173 | { |
||
174 | 0, |
||
175 | sw_create_bitmap, |
||
176 | sw_destroy_bitmap, |
||
177 | sw_lock_bitmap, |
||
178 | sw_resize_bitmap, |
||
179 | sw_blit, |
||
180 | sw_create_client, |
||
181 | sw_resize_client, |
||
182 | NULL |
||
183 | }; |
||
184 | |||
185 | |||
186 | uint32_t pxInit(int hw) |
||
187 | { |
||
188 | void *lib; |
||
189 | struct pix_driver *(*drventry)(uint32_t service); |
||
190 | |||
191 | uint32_t api_version; |
||
192 | ioctl_t io; |
||
193 | |||
194 | driver = &sw_driver; |
||
195 | |||
196 | if(hw == 0) |
||
197 | return 0; |
||
198 | |||
199 | if (fd != 0) |
||
200 | return driver->driver_caps; |
||
201 | |||
202 | fd = get_service("DISPLAY"); |
||
203 | if (fd == 0) |
||
204 | goto fail; |
||
205 | |||
206 | io.handle = fd; |
||
207 | io.io_code = SRV_GETVERSION; |
||
208 | io.input = NULL; |
||
209 | io.inp_size = 0; |
||
210 | io.output = &api_version; |
||
211 | io.out_size = BUFFER_SIZE(1); |
||
212 | |||
213 | if (call_service(&io) != 0) |
||
214 | goto fail; |
||
215 | |||
216 | if ((DISPLAY_VERSION > (api_version & 0xFFFF)) || |
||
217 | (DISPLAY_VERSION < (api_version >> 16))) |
||
218 | goto fail; |
||
219 | |||
220 | lib = load_library("pixlib-gl.dll"); |
||
221 | if(lib == 0) |
||
222 | goto fail; |
||
223 | |||
224 | drventry = get_proc_address(lib, "DrvInit"); |
||
225 | |||
226 | if( drventry == NULL) |
||
227 | goto fail; |
||
228 | |||
229 | driver = drventry(fd); |
||
230 | if(driver == NULL) |
||
231 | { |
||
232 | driver = &sw_driver; |
||
233 | goto fail; |
||
234 | }; |
||
235 | |||
236 | if (driver->driver_caps) |
||
237 | printf("2D caps %s%s%s\n", |
||
238 | (driver->driver_caps & HW_BIT_BLIT) != 0 ? "HW_BIT_BLIT " : "", |
||
239 | (driver->driver_caps & HW_TEX_BLIT) != 0 ? "HW_TEX_BLIT " : "", |
||
240 | (driver->driver_caps & HW_VID_BLIT) != 0 ? "HW_VID_BLIT " : ""); |
||
241 | |||
242 | return driver->driver_caps; |
||
243 | |||
244 | fail: |
||
245 | printf("Warning! Hardware initialization failed.\n" |
||
246 | "fallback to software rendering.\n"); |
||
247 | fd = 0; |
||
248 | return 0; |
||
249 | }; |
||
250 | |||
251 | void pxFini() |
||
252 | { |
||
253 | if (driver->fini) |
||
254 | driver->fini(); |
||
255 | };>> |
||
256 |