Rev 5375 | Go to most recent revision | Details | 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 | printf("create bitmap: %p %dx%d buffer: %p\n", |
||
51 | bitmap, bitmap->width, bitmap->height, bitmap->buffer); |
||
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 | printf("resize client\n"); |
||
170 | return driver->resize_client(x, y, width, height); |
||
171 | } |
||
172 | |||
173 | static struct pix_driver sw_driver = |
||
174 | { |
||
175 | 0, |
||
176 | sw_create_bitmap, |
||
177 | sw_destroy_bitmap, |
||
178 | sw_lock_bitmap, |
||
179 | sw_resize_bitmap, |
||
180 | sw_blit, |
||
181 | sw_create_client, |
||
182 | sw_resize_client, |
||
183 | NULL |
||
184 | }; |
||
185 | |||
186 | |||
187 | uint32_t pxInit(int hw) |
||
188 | { |
||
189 | void *lib; |
||
190 | struct pix_driver *(*drventry)(uint32_t service); |
||
191 | |||
192 | uint32_t api_version; |
||
193 | ioctl_t io; |
||
194 | |||
195 | driver = &sw_driver; |
||
196 | |||
197 | if(hw == 0) |
||
198 | return 0; |
||
199 | |||
200 | if (fd != 0) |
||
201 | return driver->driver_caps; |
||
202 | |||
203 | fd = get_service("DISPLAY"); |
||
204 | if (fd == 0) |
||
205 | goto fail; |
||
206 | |||
207 | io.handle = fd; |
||
208 | io.io_code = SRV_GETVERSION; |
||
209 | io.input = NULL; |
||
210 | io.inp_size = 0; |
||
211 | io.output = &api_version; |
||
212 | io.out_size = BUFFER_SIZE(1); |
||
213 | |||
214 | if (call_service(&io) != 0) |
||
215 | goto fail; |
||
216 | |||
217 | if ((DISPLAY_VERSION > (api_version & 0xFFFF)) || |
||
218 | (DISPLAY_VERSION < (api_version >> 16))) |
||
219 | goto fail; |
||
220 | |||
221 | lib = load_library("pixlib-gl.dll"); |
||
222 | if(lib == 0) |
||
223 | goto fail; |
||
224 | |||
225 | drventry = get_proc_address(lib, "DrvInit"); |
||
226 | |||
227 | if( drventry == NULL) |
||
228 | goto fail; |
||
229 | |||
230 | driver = drventry(fd); |
||
231 | if(driver == NULL) |
||
232 | { |
||
233 | driver = &sw_driver; |
||
234 | goto fail; |
||
235 | }; |
||
236 | |||
237 | if (driver->driver_caps) |
||
238 | printf("2D caps %s%s%s\n", |
||
239 | (driver->driver_caps & HW_BIT_BLIT) != 0 ? "HW_BIT_BLIT " : "", |
||
240 | (driver->driver_caps & HW_TEX_BLIT) != 0 ? "HW_TEX_BLIT " : "", |
||
241 | (driver->driver_caps & HW_VID_BLIT) != 0 ? "HW_VID_BLIT " : ""); |
||
242 | |||
243 | return driver->driver_caps; |
||
244 | |||
245 | fail: |
||
246 | printf("Warning! Hardware initialization failed.\n" |
||
247 | "fallback to software rendering.\n"); |
||
248 | fd = 0; |
||
249 | return 0; |
||
250 | }; |
||
251 | |||
252 | void pxFini() |
||
253 | { |
||
254 | if (driver->fini) |
||
255 | driver->fini(); |
||
256 | };>> |
||
257 |