2 * Mesa 3-D graphics library
4 * Copyright (c) 2014 The Chromium OS Authors.
5 * Copyright © 2011 Intel Corporation
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
31 #include <sys/types.h>
37 #include "egl_dri2_fallbacks.h"
40 static struct dri2_egl_display_vtbl dri2_surfaceless_display_vtbl
= {
41 .create_pixmap_surface
= dri2_fallback_create_pixmap_surface
,
42 .create_image
= dri2_create_image_khr
,
43 .swap_interval
= dri2_fallback_swap_interval
,
44 .swap_buffers_with_damage
= dri2_fallback_swap_buffers_with_damage
,
45 .swap_buffers_region
= dri2_fallback_swap_buffers_region
,
46 .post_sub_buffer
= dri2_fallback_post_sub_buffer
,
47 .copy_buffers
= dri2_fallback_copy_buffers
,
48 .query_buffer_age
= dri2_fallback_query_buffer_age
,
49 .create_wayland_buffer_from_image
= dri2_fallback_create_wayland_buffer_from_image
,
50 .get_sync_values
= dri2_fallback_get_sync_values
,
54 surfaceless_flush_front_buffer(__DRIdrawable
*driDrawable
, void *loaderPrivate
)
59 surfaceless_get_buffers_with_format(__DRIdrawable
* driDrawable
,
60 int *width
, int *height
,
61 unsigned int *attachments
, int count
,
62 int *out_count
, void *loaderPrivate
)
64 struct dri2_egl_surface
*dri2_surf
= loaderPrivate
;
66 dri2_surf
->buffer_count
= 1;
68 *width
= dri2_surf
->base
.Width
;
70 *height
= dri2_surf
->base
.Height
;
71 *out_count
= dri2_surf
->buffer_count
;;
72 return dri2_surf
->buffers
;
75 #define DRM_RENDER_DEV_NAME "%s/renderD%d"
78 dri2_initialize_surfaceless(_EGLDriver
*drv
, _EGLDisplay
*disp
)
80 struct dri2_egl_display
*dri2_dpy
;
83 int driver_loaded
= 0;
85 loader_set_logger(_eglLog
);
87 dri2_dpy
= calloc(1, sizeof *dri2_dpy
);
89 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
91 disp
->DriverData
= (void *) dri2_dpy
;
95 for (i
= 0; i
< limit
; ++i
) {
97 if (asprintf(&card_path
, DRM_RENDER_DEV_NAME
, DRM_DIR_NAME
, base
+ i
) < 0)
100 dri2_dpy
->fd
= loader_open_device(card_path
);
103 if (dri2_dpy
->fd
< 0)
106 dri2_dpy
->driver_name
= loader_get_driver_for_fd(dri2_dpy
->fd
, 0);
107 if (dri2_dpy
->driver_name
) {
108 if (dri2_load_driver(disp
)) {
112 free(dri2_dpy
->driver_name
);
117 if (!driver_loaded
) {
118 err
= "DRI2: failed to load driver";
119 goto cleanup_display
;
122 dri2_dpy
->dri2_loader_extension
.base
.name
= __DRI_DRI2_LOADER
;
123 dri2_dpy
->dri2_loader_extension
.base
.version
= 3;
124 dri2_dpy
->dri2_loader_extension
.getBuffers
= NULL
;
125 dri2_dpy
->dri2_loader_extension
.flushFrontBuffer
=
126 surfaceless_flush_front_buffer
;
127 dri2_dpy
->dri2_loader_extension
.getBuffersWithFormat
=
128 surfaceless_get_buffers_with_format
;
130 dri2_dpy
->extensions
[0] = &dri2_dpy
->dri2_loader_extension
.base
;
131 dri2_dpy
->extensions
[1] = &image_lookup_extension
.base
;
132 dri2_dpy
->extensions
[2] = &use_invalidate
.base
;
133 dri2_dpy
->extensions
[3] = NULL
;
135 if (!dri2_create_screen(disp
)) {
136 err
= "DRI2: failed to create screen";
140 for (i
= 0; dri2_dpy
->driver_configs
[i
]; i
++) {
141 dri2_add_config(disp
, dri2_dpy
->driver_configs
[i
],
142 i
+ 1, EGL_WINDOW_BIT
, NULL
, NULL
);
145 disp
->Extensions
.KHR_image_base
= EGL_TRUE
;
147 /* Fill vtbl last to prevent accidentally calling virtual function during
150 dri2_dpy
->vtbl
= &dri2_surfaceless_display_vtbl
;
155 dlclose(dri2_dpy
->driver
);
156 free(dri2_dpy
->driver_name
);
161 return _eglError(EGL_NOT_INITIALIZED
, err
);