Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5563 | serge | 1 | /* |
2 | * Copyright © 2011 Intel Corporation |
||
3 | * |
||
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
5 | * copy of this software and associated documentation files (the "Software"), |
||
6 | * to deal in the Software without restriction, including without limitation |
||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
8 | * and/or sell copies of the Software, and to permit persons to whom the |
||
9 | * Software is furnished to do so, subject to the following conditions: |
||
10 | * |
||
11 | * The above copyright notice and this permission notice (including the next |
||
12 | * paragraph) shall be included in all copies or substantial portions of the |
||
13 | * Software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
||
19 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||
20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||
22 | * DEALINGS IN THE SOFTWARE. |
||
23 | * |
||
24 | * Authors: |
||
25 | * Kristian Høgsberg |
||
26 | */ |
||
27 | |||
28 | #include |
||
29 | #include |
||
30 | #include |
||
31 | #include |
||
32 | //#include |
||
33 | #include |
||
34 | #include |
||
35 | #include |
||
36 | #include |
||
37 | #include |
||
38 | #include |
||
39 | |||
40 | #define EGL_EGLEXT_PROTOTYPES |
||
41 | #include |
||
42 | #include |
||
43 | |||
44 | #include "egl_dri2.h" |
||
45 | |||
46 | int (*blit_bitmap_from_handle)(bitmap_t *bitmap, uint32_t handle); |
||
47 | void (*blit_set_bo_handle)(bitmap_t *bitmap, int handle); |
||
48 | int (*blit_blit_tex)(bitmap_t *bitmap, int scale, int vsync, int dst_x, int dst_y, |
||
49 | int w, int h, int src_x, int src_y); |
||
50 | |||
51 | static struct gbm_bo * |
||
52 | lock_front_buffer(struct gbm_surface *_surf) |
||
53 | { |
||
54 | struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf; |
||
55 | struct dri2_egl_surface *dri2_surf = surf->dri_private; |
||
56 | struct gbm_bo *bo; |
||
57 | |||
58 | if (dri2_surf->current == NULL) { |
||
59 | _eglError(EGL_BAD_SURFACE, "no front buffer"); |
||
60 | return NULL; |
||
61 | } |
||
62 | |||
63 | bo = dri2_surf->current->bo; |
||
64 | dri2_surf->current->locked = 1; |
||
65 | dri2_surf->current = NULL; |
||
66 | |||
67 | return bo; |
||
68 | } |
||
69 | |||
70 | static void |
||
71 | release_buffer(struct gbm_surface *_surf, struct gbm_bo *bo) |
||
72 | { |
||
73 | struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf; |
||
74 | struct dri2_egl_surface *dri2_surf = surf->dri_private; |
||
75 | int i; |
||
76 | |||
77 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
||
78 | if (dri2_surf->color_buffers[i].bo == bo) { |
||
79 | dri2_surf->color_buffers[i].locked = 0; |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | |||
84 | static int |
||
85 | has_free_buffers(struct gbm_surface *_surf) |
||
86 | { |
||
87 | struct gbm_dri_surface *surf = (struct gbm_dri_surface *) _surf; |
||
88 | struct dri2_egl_surface *dri2_surf = surf->dri_private; |
||
89 | int i; |
||
90 | |||
91 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) |
||
92 | if (!dri2_surf->color_buffers[i].locked) |
||
93 | return 1; |
||
94 | |||
95 | return 0; |
||
96 | } |
||
97 | |||
98 | static _EGLSurface * |
||
99 | dri2_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, |
||
100 | _EGLConfig *conf, EGLNativeWindowType window, |
||
101 | const EGLint *attrib_list) |
||
102 | { |
||
103 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
||
104 | struct dri2_egl_config *dri2_conf = dri2_egl_config(conf); |
||
105 | struct dri2_egl_surface *dri2_surf; |
||
106 | struct gbm_dri_surface *surf; |
||
107 | struct gbm_bo *bo; |
||
108 | _EGLImage *img; |
||
109 | EGLint attr[10]; |
||
110 | |||
111 | (void) drv; |
||
112 | |||
113 | dri2_surf = calloc(1, sizeof *dri2_surf); |
||
114 | if (!dri2_surf) { |
||
115 | _eglError(EGL_BAD_ALLOC, "dri2_create_surface"); |
||
116 | return NULL; |
||
117 | } |
||
118 | |||
119 | if (!_eglInitSurface(&dri2_surf->base, disp, type, conf, attrib_list)) |
||
120 | goto cleanup_surf; |
||
121 | |||
122 | switch (type) { |
||
123 | case EGL_WINDOW_BIT: |
||
124 | if (!window) |
||
125 | return NULL; |
||
126 | surf = gbm_dri_surface((struct gbm_surface *) window); |
||
127 | dri2_surf->gbm_surf = surf; |
||
128 | dri2_surf->base.Width = surf->base.width; |
||
129 | dri2_surf->base.Height = surf->base.height; |
||
130 | surf->dri_private = dri2_surf; |
||
131 | break; |
||
132 | default: |
||
133 | goto cleanup_surf; |
||
134 | } |
||
135 | |||
136 | attr[0] = EGL_WIDTH; |
||
137 | attr[1] = surf->base.width; |
||
138 | attr[2] = EGL_HEIGHT; |
||
139 | attr[3] = surf->base.height; |
||
140 | attr[4] = EGL_DRM_BUFFER_FORMAT_MESA; |
||
141 | attr[5] = EGL_DRM_BUFFER_FORMAT_ARGB32_MESA; |
||
142 | attr[6] = EGL_DRM_BUFFER_USE_MESA; |
||
143 | attr[7] = EGL_DRM_BUFFER_USE_SHARE_MESA; |
||
144 | attr[8] = EGL_NONE; |
||
145 | |||
146 | img = drv->API.CreateDRMImageMESA(drv, disp, attr); |
||
147 | dri2_surf->egl_front = img; |
||
148 | dri2_surf->khr_front = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; |
||
149 | |||
150 | bo = gbm_bo_import(&dri2_dpy->gbm_dri->base.base, |
||
151 | GBM_BO_IMPORT_EGL_IMAGE, dri2_surf->khr_front, 0); |
||
152 | if( bo == NULL){ |
||
153 | _eglError(EGL_BAD_ALLOC, "gbm_bo_create front buffer"); |
||
154 | goto cleanup_surf; |
||
155 | } |
||
156 | dri2_surf->color_buffers[1].bo = bo; |
||
157 | |||
158 | img = drv->API.CreateDRMImageMESA(drv, disp, attr); |
||
159 | dri2_surf->egl_back = img; |
||
160 | dri2_surf->khr_back = (img) ? _eglLinkImage(img) : EGL_NO_IMAGE_KHR; |
||
161 | |||
162 | bo = gbm_bo_import(&dri2_dpy->gbm_dri->base.base, |
||
163 | GBM_BO_IMPORT_EGL_IMAGE, dri2_surf->khr_back, 0); |
||
164 | if( bo == NULL){ |
||
165 | _eglError(EGL_BAD_ALLOC, "gbm_bo_create back buffer"); |
||
166 | goto cleanup_surf; |
||
167 | } |
||
168 | dri2_surf->color_buffers[2].bo = bo; |
||
169 | |||
170 | |||
171 | dri2_surf->dri_drawable = |
||
172 | (*dri2_dpy->dri2->createNewDrawable) (dri2_dpy->dri_screen, |
||
173 | dri2_conf->dri_double_config, |
||
174 | dri2_surf->gbm_surf); |
||
175 | |||
176 | if (dri2_surf->dri_drawable == NULL) { |
||
177 | _eglError(EGL_BAD_ALLOC, "dri2->createNewDrawable"); |
||
178 | goto cleanup_surf; |
||
179 | } |
||
180 | |||
181 | return &dri2_surf->base; |
||
182 | |||
183 | cleanup_surf: |
||
184 | free(dri2_surf); |
||
185 | |||
186 | return NULL; |
||
187 | } |
||
188 | |||
189 | static EGLImageKHR |
||
190 | dri2_get_fb_image(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw, EGLint type) |
||
191 | { |
||
192 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
||
193 | |||
194 | return (type == EGL_DRM_BUFFER_FRONT) ? dri2_surf->khr_front:dri2_surf->khr_back; |
||
195 | } |
||
196 | |||
197 | |||
198 | static _EGLSurface * |
||
199 | dri2_create_window_surface(_EGLDriver *drv, _EGLDisplay *disp, |
||
200 | _EGLConfig *conf, EGLNativeWindowType window, |
||
201 | const EGLint *attrib_list) |
||
202 | { |
||
203 | return dri2_create_surface(drv, disp, EGL_WINDOW_BIT, conf, |
||
204 | window, attrib_list); |
||
205 | } |
||
206 | |||
207 | static EGLBoolean |
||
208 | dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) |
||
209 | { |
||
210 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
||
211 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); |
||
212 | int i; |
||
213 | |||
214 | if (!_eglPutSurface(surf)) |
||
215 | return EGL_TRUE; |
||
216 | |||
217 | (*dri2_dpy->core->destroyDrawable)(dri2_surf->dri_drawable); |
||
218 | |||
219 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) { |
||
220 | if (dri2_surf->color_buffers[i].bo) |
||
221 | gbm_bo_destroy(dri2_surf->color_buffers[i].bo); |
||
222 | } |
||
223 | |||
224 | for (i = 0; i < __DRI_BUFFER_COUNT; i++) { |
||
225 | if (dri2_surf->dri_buffers[i]) |
||
226 | dri2_dpy->dri2->releaseBuffer(dri2_dpy->dri_screen, |
||
227 | dri2_surf->dri_buffers[i]); |
||
228 | } |
||
229 | |||
230 | free(surf); |
||
231 | |||
232 | return EGL_TRUE; |
||
233 | } |
||
234 | |||
235 | static int |
||
236 | get_back_bo(struct dri2_egl_surface *dri2_surf, __DRIbuffer *buffer) |
||
237 | { |
||
238 | struct dri2_egl_display *dri2_dpy = |
||
239 | dri2_egl_display(dri2_surf->base.Resource.Display); |
||
240 | struct gbm_dri_bo *bo; |
||
241 | struct gbm_dri_surface *surf = dri2_surf->gbm_surf; |
||
242 | int i, name, pitch; |
||
243 | |||
244 | if (dri2_surf->back == NULL) |
||
245 | { |
||
246 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) |
||
247 | { |
||
248 | if(dri2_surf->color_buffers[i].locked) |
||
249 | { |
||
250 | dri2_surf->color_buffers[i].locked = 0; |
||
251 | continue; |
||
252 | } |
||
253 | dri2_surf->back = &dri2_surf->color_buffers[i]; |
||
254 | } |
||
255 | } |
||
256 | |||
257 | if (dri2_surf->back == NULL) |
||
258 | return -1; |
||
259 | if (dri2_surf->back->bo == NULL) |
||
260 | dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_dri->base.base, |
||
261 | surf->base.width, surf->base.height, |
||
262 | surf->base.format, surf->base.flags); |
||
263 | if (dri2_surf->back->bo == NULL) |
||
264 | return -1; |
||
265 | |||
266 | bo = (struct gbm_dri_bo *) dri2_surf->back->bo; |
||
267 | |||
268 | dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_NAME, &name); |
||
269 | dri2_dpy->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE, &pitch); |
||
270 | |||
271 | buffer->attachment = __DRI_BUFFER_BACK_LEFT; |
||
272 | buffer->name = name; |
||
273 | buffer->pitch = pitch; |
||
274 | buffer->cpp = 4; |
||
275 | buffer->flags = 0; |
||
276 | |||
277 | dri2_surf->back->locked = 1; |
||
278 | |||
279 | return 0; |
||
280 | } |
||
281 | |||
282 | static int |
||
283 | get_aux_bo(struct dri2_egl_surface *dri2_surf, |
||
284 | unsigned int attachment, unsigned int format, __DRIbuffer *buffer) |
||
285 | { |
||
286 | struct dri2_egl_display *dri2_dpy = |
||
287 | dri2_egl_display(dri2_surf->base.Resource.Display); |
||
288 | __DRIbuffer *b = dri2_surf->dri_buffers[attachment]; |
||
289 | |||
290 | if (b == NULL) { |
||
291 | b = dri2_dpy->dri2->allocateBuffer(dri2_dpy->dri_screen, |
||
292 | attachment, format, |
||
293 | dri2_surf->base.Width, |
||
294 | dri2_surf->base.Height); |
||
295 | dri2_surf->dri_buffers[attachment] = b; |
||
296 | } |
||
297 | if (b == NULL) |
||
298 | return -1; |
||
299 | |||
300 | memcpy(buffer, b, sizeof *buffer); |
||
301 | |||
302 | return 0; |
||
303 | } |
||
304 | |||
305 | static __DRIbuffer * |
||
306 | dri2_get_buffers_with_format(__DRIdrawable *driDrawable, |
||
307 | int *width, int *height, |
||
308 | unsigned int *attachments, int count, |
||
309 | int *out_count, void *loaderPrivate) |
||
310 | { |
||
311 | struct dri2_egl_surface *dri2_surf = loaderPrivate; |
||
312 | int i, j; |
||
313 | |||
314 | dri2_surf->buffer_count = 0; |
||
315 | for (i = 0, j = 0; i < 2 * count; i += 2, j++) { |
||
316 | assert(attachments[i] < __DRI_BUFFER_COUNT); |
||
317 | assert(dri2_surf->buffer_count < 5); |
||
318 | |||
319 | switch (attachments[i]) { |
||
320 | case __DRI_BUFFER_BACK_LEFT: |
||
321 | if (get_back_bo(dri2_surf, &dri2_surf->buffers[j]) < 0) { |
||
322 | _eglError(EGL_BAD_ALLOC, "failed to allocate color buffer"); |
||
323 | return NULL; |
||
324 | } |
||
325 | break; |
||
326 | default: |
||
327 | if (get_aux_bo(dri2_surf, attachments[i], attachments[i + 1], |
||
328 | &dri2_surf->buffers[j]) < 0) { |
||
329 | _eglError(EGL_BAD_ALLOC, "failed to allocate aux buffer"); |
||
330 | return NULL; |
||
331 | } |
||
332 | break; |
||
333 | } |
||
334 | } |
||
335 | |||
336 | *out_count = j; |
||
337 | if (j == 0) |
||
338 | return NULL; |
||
339 | |||
340 | *width = dri2_surf->base.Width; |
||
341 | *height = dri2_surf->base.Height; |
||
342 | |||
343 | return dri2_surf->buffers; |
||
344 | } |
||
345 | |||
346 | static __DRIbuffer * |
||
347 | dri2_get_buffers(__DRIdrawable * driDrawable, |
||
348 | int *width, int *height, |
||
349 | unsigned int *attachments, int count, |
||
350 | int *out_count, void *loaderPrivate) |
||
351 | { |
||
352 | unsigned int *attachments_with_format; |
||
353 | __DRIbuffer *buffer; |
||
354 | const unsigned int format = 32; |
||
355 | int i; |
||
356 | |||
357 | attachments_with_format = calloc(count * 2, sizeof(unsigned int)); |
||
358 | if (!attachments_with_format) { |
||
359 | *out_count = 0; |
||
360 | return NULL; |
||
361 | } |
||
362 | |||
363 | for (i = 0; i < count; ++i) { |
||
364 | attachments_with_format[2*i] = attachments[i]; |
||
365 | attachments_with_format[2*i + 1] = format; |
||
366 | } |
||
367 | |||
368 | buffer = |
||
369 | dri2_get_buffers_with_format(driDrawable, |
||
370 | width, height, |
||
371 | attachments_with_format, count, |
||
372 | out_count, loaderPrivate); |
||
373 | |||
374 | free(attachments_with_format); |
||
375 | |||
376 | return buffer; |
||
377 | } |
||
378 | |||
379 | static void |
||
380 | dri2_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate) |
||
381 | { |
||
382 | (void) driDrawable; |
||
383 | (void) loaderPrivate; |
||
384 | } |
||
385 | |||
386 | static EGLBoolean |
||
387 | dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
||
388 | { |
||
389 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
||
390 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw); |
||
391 | __DRIbuffer buffer; |
||
392 | static bitmap_t bm; |
||
393 | |||
394 | int i; |
||
395 | |||
396 | if (dri2_surf->base.Type == EGL_WINDOW_BIT) { |
||
397 | if (dri2_surf->current) |
||
398 | _eglError(EGL_BAD_SURFACE, "dri2_swap_buffers"); |
||
399 | for (i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) |
||
400 | if (dri2_surf->color_buffers[i].age > 0) |
||
401 | dri2_surf->color_buffers[i].age++; |
||
402 | |||
403 | #if 0 |
||
404 | |||
405 | if ( (dri2_surf->back != NULL) && |
||
406 | (dri2_surf->back->bo != NULL)) |
||
407 | { |
||
408 | struct gbm_dri_bo *bo; |
||
409 | bo = (struct gbm_dri_bo *)dri2_surf->back->bo; |
||
410 | |||
411 | if(bm.width == 0) |
||
412 | { |
||
413 | // printf("%s bo: %p handle: %d width: %d height: %d pitch %d format %x\n", |
||
414 | // __FUNCTION__, bo, bo->base.base.handle.s32, bo->base.base.width, |
||
415 | // bo->base.base.height, (int)bo->base.base.stride, |
||
416 | // bo->base.base.format); |
||
417 | |||
418 | bm.width = bo->base.base.width; |
||
419 | bm.height = bo->base.base.height; |
||
420 | bm.pitch = (int)bo->base.base.stride; |
||
421 | bm.max_width = bo->base.base.width; |
||
422 | bm.max_height = bo->base.base.height; |
||
423 | bm.flags = HW_TEX_BLIT; |
||
424 | |||
425 | if( blit_bitmap_from_handle(&bm, bo->base.base.handle.s32)) |
||
426 | { |
||
427 | printf("sna_bitmap_from_handle failed\n"); |
||
428 | } |
||
429 | } |
||
430 | if( bm.handle != 0) |
||
431 | { |
||
432 | // printf("%s bo: %p handle: %d width: %d height: %d pitch %d format %x\n", |
||
433 | // __FUNCTION__, bo, bo->base.base.handle.s32, bo->base.base.width, |
||
434 | // bo->base.base.height, (int)bo->base.base.stride, |
||
435 | // bo->base.base.format); |
||
436 | |||
437 | blit_set_bo_handle(&bm, bo->base.base.handle.s32); |
||
438 | blit_blit_tex(&bm, 0, 0, 5, 20, bm.width, bm.height, 0, 0); |
||
439 | } |
||
440 | } |
||
441 | #endif |
||
442 | |||
443 | dri2_surf->current = dri2_surf->back; |
||
444 | dri2_surf->current->age = 1; |
||
445 | dri2_surf->back = NULL; |
||
446 | } |
||
447 | |||
448 | (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable); |
||
449 | (*dri2_dpy->flush->invalidate)(dri2_surf->dri_drawable); |
||
450 | |||
451 | return EGL_TRUE; |
||
452 | } |
||
453 | |||
454 | static EGLint |
||
455 | dri2_query_buffer_age(_EGLDriver *drv, |
||
456 | _EGLDisplay *disp, _EGLSurface *surface) |
||
457 | { |
||
458 | struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surface); |
||
459 | __DRIbuffer buffer; |
||
460 | |||
461 | if (get_back_bo(dri2_surf, &buffer) < 0) { |
||
462 | _eglError(EGL_BAD_ALLOC, "dri2_query_buffer_age"); |
||
463 | return 0; |
||
464 | } |
||
465 | |||
466 | return dri2_surf->back->age; |
||
467 | } |
||
468 | |||
469 | static _EGLImage * |
||
470 | dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, |
||
471 | EGLClientBuffer buffer, const EGLint *attr_list) |
||
472 | { |
||
473 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
||
474 | struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *) buffer); |
||
475 | struct dri2_egl_image *dri2_img; |
||
476 | |||
477 | dri2_img = malloc(sizeof *dri2_img); |
||
478 | if (!dri2_img) { |
||
479 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap"); |
||
480 | return NULL; |
||
481 | } |
||
482 | |||
483 | if (!_eglInitImage(&dri2_img->base, disp)) { |
||
484 | free(dri2_img); |
||
485 | return NULL; |
||
486 | } |
||
487 | |||
488 | dri2_img->dri_image = dri2_dpy->image->dupImage(dri_bo->image, dri2_img); |
||
489 | if (dri2_img->dri_image == NULL) { |
||
490 | free(dri2_img); |
||
491 | _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap"); |
||
492 | return NULL; |
||
493 | } |
||
494 | |||
495 | return &dri2_img->base; |
||
496 | } |
||
497 | |||
498 | static _EGLImage * |
||
499 | dri2_drm_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, |
||
500 | _EGLContext *ctx, EGLenum target, |
||
501 | EGLClientBuffer buffer, const EGLint *attr_list) |
||
502 | { |
||
503 | (void) drv; |
||
504 | |||
505 | switch (target) { |
||
506 | case EGL_NATIVE_PIXMAP_KHR: |
||
507 | return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list); |
||
508 | default: |
||
509 | return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list); |
||
510 | } |
||
511 | } |
||
512 | |||
513 | #if 0 |
||
514 | static int |
||
515 | dri2_drm_authenticate(_EGLDisplay *disp, uint32_t id) |
||
516 | { |
||
517 | struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
||
518 | |||
519 | return drmAuthMagic(dri2_dpy->fd, id); |
||
520 | } |
||
521 | #endif |
||
522 | |||
523 | EGLBoolean |
||
524 | dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) |
||
525 | { |
||
526 | struct dri2_egl_display *dri2_dpy; |
||
527 | struct gbm_device *gbm; |
||
528 | void *lib; |
||
529 | |||
530 | int fd = -1; |
||
531 | int i; |
||
532 | |||
533 | dri2_dpy = calloc(1, sizeof *dri2_dpy); |
||
534 | if (!dri2_dpy) |
||
535 | return _eglError(EGL_BAD_ALLOC, "eglInitialize"); |
||
536 | |||
537 | disp->DriverData = (void *) dri2_dpy; |
||
538 | |||
539 | gbm = disp->PlatformDisplay; |
||
540 | if (gbm == NULL) { |
||
541 | fd = get_service("DISPLAY"); |
||
542 | dri2_dpy->own_device = 1; |
||
543 | gbm = gbm_create_device(fd); |
||
544 | if (gbm == NULL) |
||
545 | return EGL_FALSE; |
||
546 | } |
||
547 | |||
548 | if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) { |
||
549 | free(dri2_dpy); |
||
550 | return EGL_FALSE; |
||
551 | } |
||
552 | |||
553 | dri2_dpy->gbm_dri = gbm_dri_device(gbm); |
||
554 | if (dri2_dpy->gbm_dri->base.type != GBM_DRM_DRIVER_TYPE_DRI) { |
||
555 | free(dri2_dpy); |
||
556 | return EGL_FALSE; |
||
557 | } |
||
558 | |||
559 | #if 0 |
||
560 | lib = load_library("intel-sna.drv"); |
||
561 | if(lib) |
||
562 | { |
||
563 | blit_bitmap_from_handle = get_proc_address(lib,"sna_bitmap_from_handle"); |
||
564 | blit_set_bo_handle = get_proc_address(lib,"sna_set_bo_handle"); |
||
565 | blit_blit_tex = get_proc_address(lib,"sna_blit_tex"); |
||
566 | } |
||
567 | else |
||
568 | { |
||
569 | lib = load_library("intel-uxa.drv"); |
||
570 | if(lib) |
||
571 | { |
||
572 | blit_bitmap_from_handle = get_proc_address(lib,"uxa_bitmap_from_handle"); |
||
573 | blit_set_bo_handle = get_proc_address(lib,"uxa_set_bo_handle"); |
||
574 | blit_blit_tex = get_proc_address(lib,"uxa_blit_tex"); |
||
575 | } |
||
576 | else return EGL_FALSE; |
||
577 | } |
||
578 | #endif |
||
579 | |||
580 | dri2_dpy->fd = fd; |
||
581 | dri2_dpy->device_name = strdup("drm device"); //dri2_get_device_name_for_fd(dri2_dpy->fd); |
||
582 | dri2_dpy->driver_name = dri2_dpy->gbm_dri->base.driver_name; |
||
583 | |||
584 | dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen; |
||
585 | dri2_dpy->core = dri2_dpy->gbm_dri->core; |
||
586 | dri2_dpy->dri2 = dri2_dpy->gbm_dri->dri2; |
||
587 | dri2_dpy->image = dri2_dpy->gbm_dri->image; |
||
588 | dri2_dpy->flush = dri2_dpy->gbm_dri->flush; |
||
589 | dri2_dpy->driver_configs = dri2_dpy->gbm_dri->driver_configs; |
||
590 | |||
591 | dri2_dpy->gbm_dri->lookup_image = dri2_lookup_egl_image; |
||
592 | dri2_dpy->gbm_dri->lookup_user_data = disp; |
||
593 | |||
594 | dri2_dpy->gbm_dri->get_buffers = dri2_get_buffers; |
||
595 | dri2_dpy->gbm_dri->flush_front_buffer = dri2_flush_front_buffer; |
||
596 | dri2_dpy->gbm_dri->get_buffers_with_format = dri2_get_buffers_with_format; |
||
597 | |||
598 | dri2_dpy->gbm_dri->base.base.surface_lock_front_buffer = lock_front_buffer; |
||
599 | dri2_dpy->gbm_dri->base.base.surface_release_buffer = release_buffer; |
||
600 | dri2_dpy->gbm_dri->base.base.surface_has_free_buffers = has_free_buffers; |
||
601 | |||
602 | dri2_setup_screen(disp); |
||
603 | |||
604 | for (i = 0; dri2_dpy->driver_configs[i]; i++) |
||
605 | dri2_add_config(disp, dri2_dpy->driver_configs[i], |
||
606 | i + 1, 0, EGL_WINDOW_BIT, NULL, NULL); |
||
607 | |||
608 | drv->API.CreateWindowSurface = dri2_create_window_surface; |
||
609 | drv->API.DestroySurface = dri2_destroy_surface; |
||
610 | drv->API.SwapBuffers = dri2_swap_buffers; |
||
611 | drv->API.CreateImageKHR = dri2_drm_create_image_khr; |
||
612 | drv->API.QueryBufferAge = dri2_query_buffer_age; |
||
613 | drv->API.GetImageFB = dri2_get_fb_image; |
||
614 | |||
615 | disp->Extensions.EXT_buffer_age = EGL_TRUE; |
||
616 | |||
617 | #ifdef HAVE_WAYLAND_PLATFORM |
||
618 | disp->Extensions.WL_bind_wayland_display = EGL_TRUE; |
||
619 | #endif |
||
620 | // dri2_dpy->authenticate = dri2_drm_authenticate; |
||
621 | |||
622 | /* we're supporting EGL 1.4 */ |
||
623 | disp->VersionMajor = 1; |
||
624 | disp->VersionMinor = 4; |
||
625 | |||
626 | return EGL_TRUE; |
||
627 | }>>>>>>>>>>>>> |