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