blob: c3c9fc0166c621efadd05ca68a4ce3765b11eb1a [file] [log] [blame]
Kristian Høgsberg2889d962011-02-02 22:10:40 -05001/*
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 <krh@bitplanet.net>
26 */
27
28#ifndef EGL_DRI2_INCLUDED
29#define EGL_DRI2_INCLUDED
30
Emil Velikovbf0e4d22015-02-28 17:12:40 +000031#include <stdint.h>
32
Kristian Høgsberg93aea632011-05-11 13:58:37 -040033#ifdef HAVE_X11_PLATFORM
Kristian Høgsberg2889d962011-02-02 22:10:40 -050034#include <xcb/xcb.h>
35#include <xcb/dri2.h>
36#include <xcb/xfixes.h>
37#include <X11/Xlib-xcb.h>
Kristian Høgsberg93aea632011-05-11 13:58:37 -040038#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -050039
Benjamin Franzke93aea842011-02-04 12:39:40 +010040#ifdef HAVE_WAYLAND_PLATFORM
41#include <wayland-client.h>
42#include "wayland-egl-priv.h"
43#endif
44
Kristian Høgsberg2889d962011-02-02 22:10:40 -050045#include <GL/gl.h>
46#include <GL/internal/dri_interface.h>
47
Benjamin Franzkeb2d63752011-07-02 13:41:35 +020048#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +020049#include <gbm_driint.h>
Benjamin Franzkeb2d63752011-07-02 13:41:35 +020050#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +020051
Chia-I Wu9779f6f2011-08-05 14:39:18 +090052#ifdef HAVE_ANDROID_PLATFORM
53#define LOG_TAG "EGL-DRI2"
Chia-I Wu75cc24c2011-11-25 11:59:02 +080054
55#if ANDROID_VERSION >= 0x0400
56# include <system/window.h>
57#else
58# define android_native_buffer_t ANativeWindowBuffer
59# include <ui/egl/android_natives.h>
60# include <ui/android_native_buffer.h>
Chia-I Wu9779f6f2011-08-05 14:39:18 +090061#endif
62
Chia-I Wu75cc24c2011-11-25 11:59:02 +080063#include <hardware/gralloc.h>
64#include <gralloc_drm_handle.h>
65#include <cutils/log.h>
66
67#endif /* HAVE_ANDROID_PLATFORM */
68
Kristian Høgsberg2889d962011-02-02 22:10:40 -050069#include "eglconfig.h"
70#include "eglcontext.h"
71#include "egldisplay.h"
72#include "egldriver.h"
73#include "eglcurrent.h"
74#include "egllog.h"
75#include "eglsurface.h"
76#include "eglimage.h"
Marek Olšák9a0bda22015-04-10 10:56:02 +020077#include "eglsync.h"
Kristian Høgsberg2889d962011-02-02 22:10:40 -050078
79#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
80
Chad Versaceeadd5e02014-01-28 17:03:03 -080081struct wl_buffer;
82
Kristian Høgsberg2889d962011-02-02 22:10:40 -050083struct dri2_egl_driver
84{
85 _EGLDriver base;
86
87 void *handle;
88 _EGLProc (*get_proc_address)(const char *procname);
89 void (*glFlush)(void);
90};
91
Chad Versace90502b12014-01-28 11:41:46 -080092struct dri2_egl_display_vtbl {
93 int (*authenticate)(_EGLDisplay *disp, uint32_t id);
Chad Versace8b9298a2014-01-28 12:34:19 -080094
Chad Versace0a0c8812014-01-28 16:39:09 -080095 _EGLSurface* (*create_window_surface)(_EGLDriver *drv, _EGLDisplay *dpy,
96 _EGLConfig *config,
Chad Versace6d1f83e2014-01-07 14:54:51 -080097 void *native_window,
Chad Versace0a0c8812014-01-28 16:39:09 -080098 const EGLint *attrib_list);
99
Chad Versacebc8b07a2014-01-28 16:45:07 -0800100 _EGLSurface* (*create_pixmap_surface)(_EGLDriver *drv, _EGLDisplay *dpy,
101 _EGLConfig *config,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800102 void *native_pixmap,
Chad Versacebc8b07a2014-01-28 16:45:07 -0800103 const EGLint *attrib_list);
104
Chad Versacebf200762014-01-28 17:03:03 -0800105 _EGLSurface* (*create_pbuffer_surface)(_EGLDriver *drv, _EGLDisplay *dpy,
106 _EGLConfig *config,
107 const EGLint *attrib_list);
108
Chad Versace958dd802014-01-28 17:03:03 -0800109 EGLBoolean (*destroy_surface)(_EGLDriver *drv, _EGLDisplay *dpy,
110 _EGLSurface *surface);
111
Chad Versace8b9298a2014-01-28 12:34:19 -0800112 EGLBoolean (*swap_interval)(_EGLDriver *drv, _EGLDisplay *dpy,
113 _EGLSurface *surf, EGLint interval);
Chad Versacead173bc2014-01-28 16:21:21 -0800114
Chad Versaceeef68a92014-01-28 17:03:03 -0800115 _EGLImage* (*create_image)(_EGLDriver *drv, _EGLDisplay *dpy,
116 _EGLContext *ctx, EGLenum target,
117 EGLClientBuffer buffer,
118 const EGLint *attr_list);
119
Chad Versacead173bc2014-01-28 16:21:21 -0800120 EGLBoolean (*swap_buffers)(_EGLDriver *drv, _EGLDisplay *dpy,
121 _EGLSurface *surf);
Chad Versaced03948a2014-01-28 16:26:44 -0800122
Boyan Ding052b3d42015-06-13 15:36:27 +0800123 EGLBoolean (*swap_buffers_with_damage)(_EGLDriver *drv, _EGLDisplay *dpy,
124 _EGLSurface *surface,
125 const EGLint *rects, EGLint n_rects);
Chad Versace3fdfbd22014-01-28 17:03:03 -0800126
Chad Versace75d398e2014-01-28 17:03:03 -0800127 EGLBoolean (*swap_buffers_region)(_EGLDriver *drv, _EGLDisplay *dpy,
128 _EGLSurface *surf, EGLint numRects,
129 const EGLint *rects);
130
Chad Versace688a0e82014-01-28 17:03:03 -0800131 EGLBoolean (*post_sub_buffer)(_EGLDriver *drv, _EGLDisplay *dpy,
132 _EGLSurface *surf,
133 EGLint x, EGLint y,
134 EGLint width, EGLint height);
135
Chad Versacebc2cbc02014-01-28 17:03:03 -0800136 EGLBoolean (*copy_buffers)(_EGLDriver *drv, _EGLDisplay *dpy,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800137 _EGLSurface *surf, void *native_pixmap_target);
Chad Versacebc2cbc02014-01-28 17:03:03 -0800138
Chad Versace3fdfbd22014-01-28 17:03:03 -0800139 EGLint (*query_buffer_age)(_EGLDriver *drv, _EGLDisplay *dpy,
140 _EGLSurface *surf);
Chad Versaceeadd5e02014-01-28 17:03:03 -0800141
142 struct wl_buffer* (*create_wayland_buffer_from_image)(
143 _EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img);
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700144
145 EGLBoolean (*get_sync_values)(_EGLDisplay *display, _EGLSurface *surface,
146 EGLuint64KHR *ust, EGLuint64KHR *msc,
147 EGLuint64KHR *sbc);
Boyan Dinga25df542015-07-21 23:43:59 +0800148
149 __DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
Chad Versace90502b12014-01-28 11:41:46 -0800150};
151
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500152struct dri2_egl_display
153{
Chad Versace90502b12014-01-28 11:41:46 -0800154 const struct dri2_egl_display_vtbl *vtbl;
155
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500156 int dri2_major;
157 int dri2_minor;
158 __DRIscreen *dri_screen;
Benjamin Franzke992680c2011-06-27 10:23:34 +0200159 int own_dri_screen;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500160 const __DRIconfig **driver_configs;
161 void *driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000162 const __DRIcoreExtension *core;
163 const __DRIdri2Extension *dri2;
164 const __DRIswrastExtension *swrast;
165 const __DRI2flushExtension *flush;
166 const __DRItexBufferExtension *tex_buffer;
167 const __DRIimageExtension *image;
168 const __DRIrobustnessExtension *robustness;
169 const __DRI2configQueryExtension *config;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200170 const __DRI2fenceExtension *fence;
Marek Olšák4f57ccd2015-06-10 14:45:58 +0200171 const __DRI2rendererQueryExtension *rendererQuery;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500172 int fd;
173
Benjamin Franzke2a584532011-12-13 14:43:48 +0100174 int own_device;
Fredrik Höglund655f2c12011-12-20 17:17:02 +0100175 int swap_available;
Fredrik Höglund352c8892011-12-20 17:38:45 +0100176 int invalidate_available;
Eric Anholt7e9bd2b2012-09-25 14:05:30 -0700177 int min_swap_interval;
178 int max_swap_interval;
179 int default_swap_interval;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200180#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200181 struct gbm_dri_device *gbm_dri;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200182#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200183
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500184 char *device_name;
185 char *driver_name;
186
Haitao Fengf55d0272011-02-16 23:05:15 -0500187 __DRIdri2LoaderExtension dri2_loader_extension;
188 __DRIswrastLoaderExtension swrast_loader_extension;
Kristian Høgsberg68bb26be2013-11-08 22:10:36 -0800189 const __DRIextension *extensions[5];
Eric Anholtf93533d2013-09-27 11:39:25 -0700190 const __DRIextension **driver_extensions;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400191
192#ifdef HAVE_X11_PLATFORM
193 xcb_connection_t *conn;
Marek Olšák0b56e232014-08-20 00:33:34 +0200194 int screen;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400195#endif
196
Benjamin Franzke93aea842011-02-04 12:39:40 +0100197#ifdef HAVE_WAYLAND_PLATFORM
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400198 struct wl_display *wl_dpy;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400199 struct wl_registry *wl_registry;
Benjamin Franzke6b369c42011-02-21 16:22:34 +0100200 struct wl_drm *wl_server_drm;
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400201 struct wl_drm *wl_drm;
Axel Davycdcfe482015-05-01 11:11:20 +0200202 struct wl_shm *wl_shm;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400203 struct wl_event_queue *wl_queue;
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400204 int authenticated;
Kristian Høgsberg7b1d94e2011-08-31 16:45:04 -0400205 int formats;
Kristian Høgsbergde315f72013-02-02 12:26:12 -0500206 uint32_t capabilities;
Axel Davyfb0960a2015-05-01 01:30:10 +0200207 int is_render_node;
Axel Davy4cd546d2015-05-01 01:16:24 +0200208 int is_different_gpu;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100209#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500210};
211
212struct dri2_egl_context
213{
214 _EGLContext base;
215 __DRIcontext *dri_context;
216};
217
Benjamin Franzke93aea842011-02-04 12:39:40 +0100218#ifdef HAVE_WAYLAND_PLATFORM
219enum wayland_buffer_type {
220 WL_BUFFER_FRONT,
221 WL_BUFFER_BACK,
Benjamin Franzke0cb356d2011-05-06 19:13:29 +0200222 WL_BUFFER_THIRD,
Benjamin Franzke93aea842011-02-04 12:39:40 +0100223 WL_BUFFER_COUNT
224};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100225#endif
226
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500227struct dri2_egl_surface
228{
229 _EGLSurface base;
230 __DRIdrawable *dri_drawable;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500231 __DRIbuffer buffers[5];
232 int buffer_count;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500233 int have_fake_front;
Haitao Fengf55d0272011-02-16 23:05:15 -0500234
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400235#ifdef HAVE_X11_PLATFORM
236 xcb_drawable_t drawable;
237 xcb_xfixes_region_t region;
Haitao Fengf55d0272011-02-16 23:05:15 -0500238 int depth;
239 int bytes_per_pixel;
240 xcb_gcontext_t gc;
241 xcb_gcontext_t swapgc;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400242#endif
Haitao Fengf55d0272011-02-16 23:05:15 -0500243
Benjamin Franzke93aea842011-02-04 12:39:40 +0100244#ifdef HAVE_WAYLAND_PLATFORM
245 struct wl_egl_window *wl_win;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100246 int dx;
247 int dy;
Neil Roberts992a2db2013-11-15 13:50:50 +0000248 struct wl_callback *throttle_callback;
Kristian Høgsberg7b1d94e2011-08-31 16:45:04 -0400249 int format;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100250#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900251
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200252#ifdef HAVE_DRM_PLATFORM
253 struct gbm_dri_surface *gbm_surf;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200254#endif
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500255
256#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
257 __DRIbuffer *dri_buffers[__DRI_BUFFER_COUNT];
258 struct {
259#ifdef HAVE_WAYLAND_PLATFORM
260 struct wl_buffer *wl_buffer;
Kristian Høgsberg664fe6d2013-02-02 07:40:51 -0500261 __DRIimage *dri_image;
Axel Davy4cd546d2015-05-01 01:16:24 +0200262 /* for is_different_gpu case. NULL else */
263 __DRIimage *linear_copy;
Axel Davycdcfe482015-05-01 11:11:20 +0200264 /* for swrast */
265 void *data;
266 int data_size;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500267#endif
268#ifdef HAVE_DRM_PLATFORM
269 struct gbm_bo *bo;
270#endif
271 int locked;
272 int age;
Neil Roberts992a2db2013-11-15 13:50:50 +0000273 } color_buffers[4], *back, *current;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200274#endif
275
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900276#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu75cc24c2011-11-25 11:59:02 +0800277 struct ANativeWindow *window;
278 struct ANativeWindowBuffer *buffer;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900279
280 /* EGL-owned buffers */
281 __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
282#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500283};
284
Benjamin Franzke93aea842011-02-04 12:39:40 +0100285
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500286struct dri2_egl_config
287{
288 _EGLConfig base;
Emil Velikov858f2f22015-09-13 12:25:27 +0100289 const __DRIconfig *dri_single_config[2];
290 const __DRIconfig *dri_double_config[2];
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500291};
292
293struct dri2_egl_image
294{
295 _EGLImage base;
296 __DRIimage *dri_image;
297};
298
Marek Olšák9a0bda22015-04-10 10:56:02 +0200299struct dri2_egl_sync {
300 _EGLSync base;
301 int refcount;
302 void *fence;
303};
304
Neil Roberts992a2db2013-11-15 13:50:50 +0000305/* From xmlpool/options.h, user exposed so should be stable */
306#define DRI_CONF_VBLANK_NEVER 0
307#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
308#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
309#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
310
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500311/* standard typecasts */
312_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
313_EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj)
Marek Olšák9a0bda22015-04-10 10:56:02 +0200314_EGL_DRIVER_TYPECAST(dri2_egl_sync, _EGLSync, obj)
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500315
316extern const __DRIimageLookupExtension image_lookup_extension;
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500317extern const __DRIuseInvalidateExtension use_invalidate;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500318
319EGLBoolean
320dri2_load_driver(_EGLDisplay *disp);
321
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200322/* Helper for platforms not using dri2_create_screen */
323void
324dri2_setup_screen(_EGLDisplay *disp);
325
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500326EGLBoolean
Chia-I Wucf69eea2011-06-08 16:33:55 +0800327dri2_load_driver_swrast(_EGLDisplay *disp);
328
329EGLBoolean
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500330dri2_create_screen(_EGLDisplay *disp);
331
Boyan Dinga25df542015-07-21 23:43:59 +0800332__DRIdrawable *
333dri2_surface_get_dri_drawable(_EGLSurface *surf);
334
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200335__DRIimage *
336dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data);
337
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500338struct dri2_egl_config *
339dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
Kristian Høgsberg44e584a2013-09-14 23:13:22 -0700340 EGLint surface_type, const EGLint *attr_list,
Chia-I Wu58911b82011-08-05 14:36:14 +0900341 const unsigned int *rgba_masks);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500342
343_EGLImage *
344dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
345 _EGLContext *ctx, EGLenum target,
346 EGLClientBuffer buffer, const EGLint *attr_list);
347
348EGLBoolean
349dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp);
350
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500351EGLBoolean
352dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp);
353
Benjamin Franzke93aea842011-02-04 12:39:40 +0100354EGLBoolean
355dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
356
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900357EGLBoolean
358dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
359
Haixia Shi6b8accb2015-06-12 10:10:58 -0700360EGLBoolean
361dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
362
Eric Anholt70e8ccc2014-12-21 11:51:33 -0800363void
364dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
365
Marek Olšákc2c2e9a2015-06-10 02:49:29 +0200366const __DRIconfig *
367dri2_get_dri_config(struct dri2_egl_config *conf, EGLint surface_type,
368 EGLenum colorspace);
369
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500370#endif /* EGL_DRI2_INCLUDED */