blob: 2a8307ab3217709aca29186829b82c6d92130989 [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
Eric Engestrom60f98422017-06-19 00:16:21 +010031#include <stdbool.h>
Emil Velikovbf0e4d22015-02-28 17:12:40 +000032#include <stdint.h>
33
Kristian Høgsberg93aea632011-05-11 13:58:37 -040034#ifdef HAVE_X11_PLATFORM
Kristian Høgsberg2889d962011-02-02 22:10:40 -050035#include <xcb/xcb.h>
36#include <xcb/dri2.h>
37#include <xcb/xfixes.h>
38#include <X11/Xlib-xcb.h>
Boyan Dingf35198b2015-07-21 23:44:00 +080039
40#ifdef HAVE_DRI3
41#include "loader_dri3_helper.h"
42#endif
Kristian Høgsberg93aea632011-05-11 13:58:37 -040043#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -050044
Benjamin Franzke93aea842011-02-04 12:39:40 +010045#ifdef HAVE_WAYLAND_PLATFORM
Emil Velikov9fa1d822018-03-14 17:31:27 +000046/* forward declarations to avoid pulling wayland headers everywhere */
47struct wl_egl_window;
48struct wl_event_queue;
49struct wl_callback;
50struct wl_display;
51struct wl_drm;
52struct wl_registry;
53struct wl_shm;
54struct wl_surface;
Daniel Stone02cc3592017-06-16 18:01:23 +010055struct zwp_linux_dmabuf_v1;
Benjamin Franzke93aea842011-02-04 12:39:40 +010056#endif
57
Kristian Høgsberg2889d962011-02-02 22:10:40 -050058#include <GL/gl.h>
59#include <GL/internal/dri_interface.h>
60
Benjamin Franzkeb2d63752011-07-02 13:41:35 +020061#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +020062#include <gbm_driint.h>
Benjamin Franzkeb2d63752011-07-02 13:41:35 +020063#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +020064
Chia-I Wu9779f6f2011-08-05 14:39:18 +090065#ifdef HAVE_ANDROID_PLATFORM
66#define LOG_TAG "EGL-DRI2"
Chia-I Wu75cc24c2011-11-25 11:59:02 +080067
Rob Herring0e1ff222017-03-21 13:51:19 -050068#include <system/window.h>
Chia-I Wu75cc24c2011-11-25 11:59:02 +080069#include <hardware/gralloc.h>
Chia-I Wu75cc24c2011-11-25 11:59:02 +080070#endif /* HAVE_ANDROID_PLATFORM */
71
Kristian Høgsberg2889d962011-02-02 22:10:40 -050072#include "eglconfig.h"
73#include "eglcontext.h"
Emil Velikov00992702018-09-04 11:20:03 +010074#include "egldevice.h"
Kristian Høgsberg2889d962011-02-02 22:10:40 -050075#include "egldisplay.h"
76#include "egldriver.h"
77#include "eglcurrent.h"
78#include "egllog.h"
79#include "eglsurface.h"
80#include "eglimage.h"
Marek Olšák9a0bda22015-04-10 10:56:02 +020081#include "eglsync.h"
Kristian Høgsberg2889d962011-02-02 22:10:40 -050082
Daniel Stone02cc3592017-06-16 18:01:23 +010083#include "util/u_vector.h"
Eric Engestromfbf7c382018-11-27 12:27:45 +000084#include "util/bitset.h"
85
86#define EGL_DRI2_MAX_FORMATS 8
Daniel Stone02cc3592017-06-16 18:01:23 +010087
Chad Versaceeadd5e02014-01-28 17:03:03 -080088struct wl_buffer;
89
Chad Versace90502b12014-01-28 11:41:46 -080090struct dri2_egl_display_vtbl {
91 int (*authenticate)(_EGLDisplay *disp, uint32_t id);
Chad Versace8b9298a2014-01-28 12:34:19 -080092
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000093 _EGLSurface* (*create_window_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace0a0c8812014-01-28 16:39:09 -080094 _EGLConfig *config,
Chad Versace6d1f83e2014-01-07 14:54:51 -080095 void *native_window,
Chad Versace0a0c8812014-01-28 16:39:09 -080096 const EGLint *attrib_list);
97
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000098 _EGLSurface* (*create_pixmap_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacebc8b07a2014-01-28 16:45:07 -080099 _EGLConfig *config,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800100 void *native_pixmap,
Chad Versacebc8b07a2014-01-28 16:45:07 -0800101 const EGLint *attrib_list);
102
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000103 _EGLSurface* (*create_pbuffer_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacebf200762014-01-28 17:03:03 -0800104 _EGLConfig *config,
105 const EGLint *attrib_list);
106
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000107 EGLBoolean (*destroy_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace958dd802014-01-28 17:03:03 -0800108 _EGLSurface *surface);
109
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000110 EGLBoolean (*swap_interval)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace8b9298a2014-01-28 12:34:19 -0800111 _EGLSurface *surf, EGLint interval);
Chad Versacead173bc2014-01-28 16:21:21 -0800112
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000113 _EGLImage* (*create_image)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versaceeef68a92014-01-28 17:03:03 -0800114 _EGLContext *ctx, EGLenum target,
115 EGLClientBuffer buffer,
116 const EGLint *attr_list);
117
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000118 EGLBoolean (*swap_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacead173bc2014-01-28 16:21:21 -0800119 _EGLSurface *surf);
Chad Versaced03948a2014-01-28 16:26:44 -0800120
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000121 EGLBoolean (*swap_buffers_with_damage)(_EGLDriver *drv, _EGLDisplay *disp,
Boyan Ding052b3d42015-06-13 15:36:27 +0800122 _EGLSurface *surface,
123 const EGLint *rects, EGLint n_rects);
Chad Versace3fdfbd22014-01-28 17:03:03 -0800124
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000125 EGLBoolean (*swap_buffers_region)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace75d398e2014-01-28 17:03:03 -0800126 _EGLSurface *surf, EGLint numRects,
127 const EGLint *rects);
128
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000129 EGLBoolean (*post_sub_buffer)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace688a0e82014-01-28 17:03:03 -0800130 _EGLSurface *surf,
131 EGLint x, EGLint y,
132 EGLint width, EGLint height);
133
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000134 EGLBoolean (*copy_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800135 _EGLSurface *surf, void *native_pixmap_target);
Chad Versacebc2cbc02014-01-28 17:03:03 -0800136
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000137 EGLint (*query_buffer_age)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace3fdfbd22014-01-28 17:03:03 -0800138 _EGLSurface *surf);
Chad Versaceeadd5e02014-01-28 17:03:03 -0800139
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000140 EGLBoolean (*query_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Haixia Shia7c69932016-07-28 10:51:12 -0700141 _EGLSurface *surf, EGLint attribute,
142 EGLint *value);
143
Chad Versaceeadd5e02014-01-28 17:03:03 -0800144 struct wl_buffer* (*create_wayland_buffer_from_image)(
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000145 _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img);
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700146
147 EGLBoolean (*get_sync_values)(_EGLDisplay *display, _EGLSurface *surface,
148 EGLuint64KHR *ust, EGLuint64KHR *msc,
149 EGLuint64KHR *sbc);
Boyan Dinga25df542015-07-21 23:43:59 +0800150
151 __DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
Thomas Hellstrom2db95482017-08-10 15:35:39 +0200152
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000153 void (*close_screen_notify)(_EGLDisplay *disp);
Chad Versaceed7c6942018-04-30 22:35:17 -0700154
155 /* Used in EGL_KHR_mutable_render_buffer to update the native window's
156 * shared buffer mode.
157 */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000158 bool (*set_shared_buffer_mode)(_EGLDisplay *disp, _EGLSurface *surf,
Chad Versaceed7c6942018-04-30 22:35:17 -0700159 bool mode);
Chad Versace90502b12014-01-28 11:41:46 -0800160};
161
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500162struct dri2_egl_display
163{
Chad Versace90502b12014-01-28 11:41:46 -0800164 const struct dri2_egl_display_vtbl *vtbl;
165
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500166 int dri2_major;
167 int dri2_minor;
168 __DRIscreen *dri_screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100169 bool own_dri_screen;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500170 const __DRIconfig **driver_configs;
171 void *driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000172 const __DRIcoreExtension *core;
Boyan Dingf35198b2015-07-21 23:44:00 +0800173 const __DRIimageDriverExtension *image_driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000174 const __DRIdri2Extension *dri2;
175 const __DRIswrastExtension *swrast;
176 const __DRI2flushExtension *flush;
Adam Jacksonc0be3aa2016-09-22 03:47:55 -0400177 const __DRI2flushControlExtension *flush_control;
Emil Velikov5f280d02014-02-12 20:13:15 +0000178 const __DRItexBufferExtension *tex_buffer;
179 const __DRIimageExtension *image;
180 const __DRIrobustnessExtension *robustness;
Grigori Goronzy49095192017-06-29 02:44:03 +0200181 const __DRInoErrorExtension *no_error;
Emil Velikov5f280d02014-02-12 20:13:15 +0000182 const __DRI2configQueryExtension *config;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200183 const __DRI2fenceExtension *fence;
Harish Krupoa4a8ebe2019-08-12 12:07:06 +0200184 const __DRI2bufferDamageExtension *buffer_damage;
Tapani Pälli6f5b5702017-12-28 10:51:11 +0200185 const __DRI2blobExtension *blob;
Marek Olšák4f57ccd2015-06-10 14:45:58 +0200186 const __DRI2rendererQueryExtension *rendererQuery;
Marek Olšákb6eda702016-03-03 15:59:48 +0100187 const __DRI2interopExtension *interop;
Veluri Mithun85edfc02019-01-23 22:45:42 +0530188 const __DRIconfigOptionsExtension *configOptions;
Chad Versaceed7c6942018-04-30 22:35:17 -0700189 const __DRImutableRenderBufferDriverExtension *mutable_render_buffer;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500190 int fd;
191
Nicolas Boichat9ee683f2016-07-22 11:27:41 +0800192 /* dri2_initialize/dri2_terminate increment/decrement this count, so does
193 * dri2_make_current (tracks if there are active contexts/surfaces). */
194 int ref_count;
195
Eric Engestrom60f98422017-06-19 00:16:21 +0100196 bool own_device;
197 bool invalidate_available;
Eric Anholt7e9bd2b2012-09-25 14:05:30 -0700198 int min_swap_interval;
199 int max_swap_interval;
200 int default_swap_interval;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200201#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200202 struct gbm_dri_device *gbm_dri;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200203#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200204
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500205 char *driver_name;
206
Emil Velikovf8719462016-08-24 23:32:27 +0100207 const __DRIextension **loader_extensions;
Eric Anholtf93533d2013-09-27 11:39:25 -0700208 const __DRIextension **driver_extensions;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400209
210#ifdef HAVE_X11_PLATFORM
211 xcb_connection_t *conn;
Emil Velikov7c6babb2016-11-21 13:46:51 +0000212 xcb_screen_t *screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100213 bool swap_available;
Boyan Dingf35198b2015-07-21 23:44:00 +0800214#ifdef HAVE_DRI3
Louis-Francis Ratté-Boulianne069fdd52017-07-07 02:54:26 -0400215 bool multibuffers_available;
216 int dri3_major_version;
217 int dri3_minor_version;
Louis-Francis Ratté-Boulianne3160cb82017-10-06 01:26:51 -0400218 int present_major_version;
219 int present_minor_version;
Boyan Dingf35198b2015-07-21 23:44:00 +0800220 struct loader_dri3_extensions loader_dri3_ext;
221#endif
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400222#endif
223
Benjamin Franzke93aea842011-02-04 12:39:40 +0100224#ifdef HAVE_WAYLAND_PLATFORM
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400225 struct wl_display *wl_dpy;
Jonas Ådahl36b99762017-01-13 23:05:10 +0800226 struct wl_display *wl_dpy_wrapper;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400227 struct wl_registry *wl_registry;
Benjamin Franzke6b369c42011-02-21 16:22:34 +0100228 struct wl_drm *wl_server_drm;
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400229 struct wl_drm *wl_drm;
Axel Davycdcfe482015-05-01 11:11:20 +0200230 struct wl_shm *wl_shm;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400231 struct wl_event_queue *wl_queue;
Daniel Stone02cc3592017-06-16 18:01:23 +0100232 struct zwp_linux_dmabuf_v1 *wl_dmabuf;
Daniel Stone47320942018-02-06 10:29:13 +0000233 struct u_vector *wl_modifiers;
Eric Engestrom60f98422017-06-19 00:16:21 +0100234 bool authenticated;
Eric Engestromfbf7c382018-11-27 12:27:45 +0000235 BITSET_DECLARE(formats, EGL_DRI2_MAX_FORMATS);
Kristian Høgsbergde315f72013-02-02 12:26:12 -0500236 uint32_t capabilities;
Frank Binnsd6f669b2016-06-17 18:41:22 +0100237 char *device_name;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100238#endif
Boyan Dingf35198b2015-07-21 23:44:00 +0800239
Tomasz Figa859d0b02016-11-10 16:55:52 +0900240#ifdef HAVE_ANDROID_PLATFORM
241 const gralloc_module_t *gralloc;
242#endif
243
Eric Engestrom60f98422017-06-19 00:16:21 +0100244 bool is_render_node;
Eric Engestrom4a1238a2017-06-19 00:16:51 +0100245 bool is_different_gpu;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500246};
247
248struct dri2_egl_context
249{
250 _EGLContext base;
251 __DRIcontext *dri_context;
252};
253
Benjamin Franzke93aea842011-02-04 12:39:40 +0100254#ifdef HAVE_WAYLAND_PLATFORM
255enum wayland_buffer_type {
256 WL_BUFFER_FRONT,
257 WL_BUFFER_BACK,
Benjamin Franzke0cb356d2011-05-06 19:13:29 +0200258 WL_BUFFER_THIRD,
Benjamin Franzke93aea842011-02-04 12:39:40 +0100259 WL_BUFFER_COUNT
260};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100261#endif
262
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500263struct dri2_egl_surface
264{
265 _EGLSurface base;
266 __DRIdrawable *dri_drawable;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500267 __DRIbuffer buffers[5];
Eric Engestrom60f98422017-06-19 00:16:21 +0100268 bool have_fake_front;
Haitao Fengf55d0272011-02-16 23:05:15 -0500269
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400270#ifdef HAVE_X11_PLATFORM
271 xcb_drawable_t drawable;
272 xcb_xfixes_region_t region;
Haitao Fengf55d0272011-02-16 23:05:15 -0500273 int depth;
274 int bytes_per_pixel;
275 xcb_gcontext_t gc;
276 xcb_gcontext_t swapgc;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400277#endif
Haitao Fengf55d0272011-02-16 23:05:15 -0500278
Benjamin Franzke93aea842011-02-04 12:39:40 +0100279#ifdef HAVE_WAYLAND_PLATFORM
280 struct wl_egl_window *wl_win;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100281 int dx;
282 int dy;
Daniel Stone03dd9a82017-05-05 14:49:09 +0100283 struct wl_event_queue *wl_queue;
284 struct wl_surface *wl_surface_wrapper;
285 struct wl_display *wl_dpy_wrapper;
286 struct wl_drm *wl_drm_wrapper;
Neil Roberts992a2db2013-11-15 13:50:50 +0000287 struct wl_callback *throttle_callback;
Emil Velikovebc68e32016-08-25 00:12:13 +0100288 int format;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100289#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900290
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200291#ifdef HAVE_DRM_PLATFORM
292 struct gbm_dri_surface *gbm_surf;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200293#endif
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500294
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900295 /* EGL-owned buffers */
296 __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
297
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500298#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500299 struct {
300#ifdef HAVE_WAYLAND_PLATFORM
301 struct wl_buffer *wl_buffer;
Juan A. Suarez Romero54a96222018-08-30 10:14:49 +0200302 bool wl_release;
Kristian Høgsberg664fe6d2013-02-02 07:40:51 -0500303 __DRIimage *dri_image;
Axel Davy4cd546d2015-05-01 01:16:24 +0200304 /* for is_different_gpu case. NULL else */
305 __DRIimage *linear_copy;
Axel Davycdcfe482015-05-01 11:11:20 +0200306 /* for swrast */
307 void *data;
308 int data_size;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500309#endif
310#ifdef HAVE_DRM_PLATFORM
311 struct gbm_bo *bo;
312#endif
Eric Engestrom60f98422017-06-19 00:16:21 +0100313 bool locked;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500314 int age;
Neil Roberts992a2db2013-11-15 13:50:50 +0000315 } color_buffers[4], *back, *current;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200316#endif
317
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900318#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu75cc24c2011-11-25 11:59:02 +0800319 struct ANativeWindow *window;
320 struct ANativeWindowBuffer *buffer;
Liu Zhiquanb6637532016-11-16 10:11:28 +0800321 __DRIimage *dri_image_back;
322 __DRIimage *dri_image_front;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900323
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800324 /* Used to record all the buffers created by ANativeWindow and their ages.
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700325 * Allocate number of color_buffers based on query to android bufferqueue
326 * and save color_buffers_count.
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800327 */
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700328 int color_buffers_count;
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800329 struct {
330 struct ANativeWindowBuffer *buffer;
331 int age;
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700332 } *color_buffers, *back;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900333#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500334
Emil Velikovd6edcce2019-05-16 18:01:40 +0100335 /* surfaceless and device */
336 __DRIimage *front;
337 unsigned int visual;
338
Zhongmin Wue013ce82017-09-15 18:32:42 +0100339 int out_fence_fd;
340 EGLBoolean enable_out_fence;
Gurchetan Singh63c5d5c2016-05-16 16:34:07 -0700341};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100342
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500343struct dri2_egl_config
344{
345 _EGLConfig base;
Eric Engestromb81cfc72017-06-21 10:40:31 +0100346 const __DRIconfig *dri_config[2][2];
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500347};
348
349struct dri2_egl_image
350{
351 _EGLImage base;
352 __DRIimage *dri_image;
353};
354
Marek Olšák9a0bda22015-04-10 10:56:02 +0200355struct dri2_egl_sync {
356 _EGLSync base;
Dongwon Kim70299472016-04-04 17:14:10 -0700357 mtx_t mutex;
358 cnd_t cond;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200359 int refcount;
360 void *fence;
361};
362
Neil Roberts992a2db2013-11-15 13:50:50 +0000363/* From xmlpool/options.h, user exposed so should be stable */
364#define DRI_CONF_VBLANK_NEVER 0
365#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
366#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
367#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
368
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500369/* standard typecasts */
370_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
371_EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj)
Marek Olšák9a0bda22015-04-10 10:56:02 +0200372_EGL_DRIVER_TYPECAST(dri2_egl_sync, _EGLSync, obj)
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500373
374extern const __DRIimageLookupExtension image_lookup_extension;
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500375extern const __DRIuseInvalidateExtension use_invalidate;
Eric Anholt3b7b6ad2012-12-27 17:39:37 -0800376extern const __DRIbackgroundCallableExtension background_callable_extension;
Eric Anholt6a8d39dc2019-07-23 13:18:21 -0700377extern const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500378
379EGLBoolean
380dri2_load_driver(_EGLDisplay *disp);
381
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200382/* Helper for platforms not using dri2_create_screen */
383void
384dri2_setup_screen(_EGLDisplay *disp);
385
Emil Velikov47b06f52017-08-05 00:25:46 +0100386void
387dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval);
388
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500389EGLBoolean
Chia-I Wucf69eea2011-06-08 16:33:55 +0800390dri2_load_driver_swrast(_EGLDisplay *disp);
391
392EGLBoolean
Boyan Dingf35198b2015-07-21 23:44:00 +0800393dri2_load_driver_dri3(_EGLDisplay *disp);
394
395EGLBoolean
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500396dri2_create_screen(_EGLDisplay *disp);
397
Emil Velikov2c341f22017-05-11 16:20:04 +0100398EGLBoolean
399dri2_setup_extensions(_EGLDisplay *disp);
400
Boyan Dinga25df542015-07-21 23:43:59 +0800401__DRIdrawable *
402dri2_surface_get_dri_drawable(_EGLSurface *surf);
403
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200404__DRIimage *
405dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data);
406
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800407void
408dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
409 const __DRIconfig *config, int *shifts,
410 unsigned int *sizes);
411
Kevin Strasser482ed432019-01-24 16:55:33 -0800412void
413dri2_get_render_type_float(const __DRIcoreExtension *core,
414 const __DRIconfig *config,
415 bool *is_float);
416
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500417struct dri2_egl_config *
418dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
Emil Velikovebc68e32016-08-25 00:12:13 +0100419 EGLint surface_type, const EGLint *attr_list,
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800420 const int *rgba_shifts, const unsigned int *rgba_sizes);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500421
422_EGLImage *
423dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
Emil Velikovebc68e32016-08-25 00:12:13 +0100424 _EGLContext *ctx, EGLenum target,
425 EGLClientBuffer buffer, const EGLint *attr_list);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500426
Emil Velikov38ef6f52016-05-01 12:42:53 +0100427_EGLImage *
428dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
Emil Velikovebc68e32016-08-25 00:12:13 +0100429 EGLClientBuffer buffer, const EGLint *attr_list);
Emil Velikov38ef6f52016-05-01 12:42:53 +0100430
Emil Velikov55245fe2017-11-09 17:55:19 +0000431#ifdef HAVE_X11_PLATFORM
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500432EGLBoolean
433dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov938fcab2017-11-09 18:58:52 +0000434void
435dri2_teardown_x11(struct dri2_egl_display *dri2_dpy);
Mario Kleiner61a02722018-06-13 06:04:13 +0200436unsigned int
437dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth);
Emil Velikov55245fe2017-11-09 17:55:19 +0000438#else
439static inline EGLBoolean
440dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp)
441{
442 return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
443}
Emil Velikov938fcab2017-11-09 18:58:52 +0000444static inline void
445dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) {}
Mario Kleiner61a02722018-06-13 06:04:13 +0200446static inline unsigned int
447dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
448{
449 return 0;
450}
Emil Velikov55245fe2017-11-09 17:55:19 +0000451#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500452
Emil Velikov55245fe2017-11-09 17:55:19 +0000453#ifdef HAVE_DRM_PLATFORM
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500454EGLBoolean
455dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov40a01c92017-11-09 19:04:25 +0000456void
457dri2_teardown_drm(struct dri2_egl_display *dri2_dpy);
Emil Velikov55245fe2017-11-09 17:55:19 +0000458#else
459static inline EGLBoolean
460dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
461{
462 return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built");
463}
Emil Velikov40a01c92017-11-09 19:04:25 +0000464static inline void
465dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000466#endif
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500467
Emil Velikov55245fe2017-11-09 17:55:19 +0000468#ifdef HAVE_WAYLAND_PLATFORM
Benjamin Franzke93aea842011-02-04 12:39:40 +0100469EGLBoolean
470dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov8d745ab2017-11-09 19:13:09 +0000471void
472dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy);
Mario Kleiner820dfce2018-06-13 06:04:15 +0200473bool
474dri2_wl_is_format_supported(void* user_data, uint32_t format);
Emil Velikov55245fe2017-11-09 17:55:19 +0000475#else
476static inline EGLBoolean
477dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
478{
479 return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built");
480}
Emil Velikov8d745ab2017-11-09 19:13:09 +0000481static inline void
482dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000483#endif
Benjamin Franzke93aea842011-02-04 12:39:40 +0100484
Emil Velikov55245fe2017-11-09 17:55:19 +0000485#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900486EGLBoolean
487dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov55245fe2017-11-09 17:55:19 +0000488#else
489static inline EGLBoolean
490dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
491{
492 return _eglError(EGL_NOT_INITIALIZED, "Android platform not built");
493}
494#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900495
Emil Velikov55245fe2017-11-09 17:55:19 +0000496#ifdef HAVE_SURFACELESS_PLATFORM
Haixia Shi6b8accb2015-06-12 10:10:58 -0700497EGLBoolean
498dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov55245fe2017-11-09 17:55:19 +0000499#else
500static inline EGLBoolean
501dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)
502{
503 return _eglError(EGL_NOT_INITIALIZED, "Surfaceless platform not built");
504}
505#endif
Haixia Shi6b8accb2015-06-12 10:10:58 -0700506
Emil Velikovd6edcce2019-05-16 18:01:40 +0100507EGLBoolean
508dri2_initialize_device(_EGLDriver *drv, _EGLDisplay *disp);
509static inline void
510dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ }
511
Eric Anholt70e8ccc2014-12-21 11:51:33 -0800512void
513dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
514
Marek Olšákc2c2e9a2015-06-10 02:49:29 +0200515const __DRIconfig *
516dri2_get_dri_config(struct dri2_egl_config *conf, EGLint surface_type,
517 EGLenum colorspace);
518
Emil Velikov98f5d012016-08-25 13:15:43 +0100519static inline void
520dri2_set_WL_bind_wayland_display(_EGLDriver *drv, _EGLDisplay *disp)
521{
522#ifdef HAVE_WAYLAND_PLATFORM
523 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
524
525 (void) drv;
526
527 if (dri2_dpy->device_name && dri2_dpy->image) {
528 if (dri2_dpy->image->base.version >= 10 &&
529 dri2_dpy->image->getCapabilities != NULL) {
530 int capabilities;
531
532 capabilities =
533 dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
534 disp->Extensions.WL_bind_wayland_display =
535 (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
536 } else {
537 disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
538 }
539 }
540#endif
541}
542
Emil Velikov3e73c022017-05-11 17:13:33 +0100543void
544dri2_display_destroy(_EGLDisplay *disp);
545
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900546__DRIbuffer *
547dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
548 unsigned int att, unsigned int format);
549
550void
551dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
552
Zhongmin Wue013ce82017-09-15 18:32:42 +0100553EGLBoolean
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000554dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
Paulo Zanoni04ecda32019-05-01 15:42:26 -0700555 _EGLConfig *conf, const EGLint *attrib_list,
556 EGLBoolean enable_out_fence, void *native_surface);
Zhongmin Wue013ce82017-09-15 18:32:42 +0100557
558void
559dri2_fini_surface(_EGLSurface *surf);
560
Emil Velikov2282ec02019-05-16 18:01:38 +0100561EGLBoolean
562dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
563 const __DRIconfig *config,
Mathias Fröhlicha7ecf782019-06-07 07:12:42 +0200564 struct dri2_egl_surface *dri2_surf,
565 void *loaderPrivate);
Emil Velikov2282ec02019-05-16 18:01:38 +0100566
Eric Engestrom2de9e842018-08-16 15:22:46 +0100567static inline uint64_t
568combine_u32_into_u64(uint32_t hi, uint32_t lo)
569{
570 return (((uint64_t) hi) << 32) | (((uint64_t) lo) & 0xffffffff);
571}
572
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500573#endif /* EGL_DRI2_INCLUDED */