blob: ac703cea1d8350d2697c93e76042e6b85ff29f44 [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
Adam Jacksone74c9472019-08-30 15:35:22 -040086#define EGL_DRI2_MAX_FORMATS 10
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 {
Eric Engestrome0ef5a52020-07-13 11:08:53 +020091 /* mandatory on Wayland, unused otherwise */
Chad Versace90502b12014-01-28 11:41:46 -080092 int (*authenticate)(_EGLDisplay *disp, uint32_t id);
Chad Versace8b9298a2014-01-28 12:34:19 -080093
Eric Engestrome0ef5a52020-07-13 11:08:53 +020094 /* mandatory */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000095 _EGLSurface* (*create_window_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace0a0c8812014-01-28 16:39:09 -080096 _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
Eric Engestrom179e4422020-07-11 00:29:17 +0200100 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000101 _EGLSurface* (*create_pixmap_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacebc8b07a2014-01-28 16:45:07 -0800102 _EGLConfig *config,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800103 void *native_pixmap,
Chad Versacebc8b07a2014-01-28 16:45:07 -0800104 const EGLint *attrib_list);
105
Eric Engestrom43e2d802020-07-11 00:31:32 +0200106 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000107 _EGLSurface* (*create_pbuffer_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacebf200762014-01-28 17:03:03 -0800108 _EGLConfig *config,
109 const EGLint *attrib_list);
110
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200111 /* mandatory */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000112 EGLBoolean (*destroy_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace958dd802014-01-28 17:03:03 -0800113 _EGLSurface *surface);
114
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200115 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000116 EGLBoolean (*swap_interval)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace8b9298a2014-01-28 12:34:19 -0800117 _EGLSurface *surf, EGLint interval);
Chad Versacead173bc2014-01-28 16:21:21 -0800118
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200119 /* mandatory */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000120 _EGLImage* (*create_image)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versaceeef68a92014-01-28 17:03:03 -0800121 _EGLContext *ctx, EGLenum target,
122 EGLClientBuffer buffer,
123 const EGLint *attr_list);
124
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200125 /* mandatory */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000126 EGLBoolean (*swap_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacead173bc2014-01-28 16:21:21 -0800127 _EGLSurface *surf);
Chad Versaced03948a2014-01-28 16:26:44 -0800128
Eric Engestrom7d5a13e2020-07-11 00:36:08 +0200129 /* optional - falls back to .swap_buffers */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000130 EGLBoolean (*swap_buffers_with_damage)(_EGLDriver *drv, _EGLDisplay *disp,
Boyan Ding052b3d42015-06-13 15:36:27 +0800131 _EGLSurface *surface,
132 const EGLint *rects, EGLint n_rects);
Chad Versace3fdfbd22014-01-28 17:03:03 -0800133
Eric Engestrom1ba5075a2020-07-11 00:38:38 +0200134 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000135 EGLBoolean (*swap_buffers_region)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace75d398e2014-01-28 17:03:03 -0800136 _EGLSurface *surf, EGLint numRects,
137 const EGLint *rects);
138
Eric Engestrom2d5f12ae32020-07-11 00:39:41 +0200139 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000140 EGLBoolean (*post_sub_buffer)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace688a0e82014-01-28 17:03:03 -0800141 _EGLSurface *surf,
142 EGLint x, EGLint y,
143 EGLint width, EGLint height);
144
Eric Engestrom90000b02020-07-11 00:40:20 +0200145 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000146 EGLBoolean (*copy_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800147 _EGLSurface *surf, void *native_pixmap_target);
Chad Versacebc2cbc02014-01-28 17:03:03 -0800148
Eric Engestromc5fb1fb2020-07-11 00:40:57 +0200149 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000150 EGLint (*query_buffer_age)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace3fdfbd22014-01-28 17:03:03 -0800151 _EGLSurface *surf);
Chad Versaceeadd5e02014-01-28 17:03:03 -0800152
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200153 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000154 EGLBoolean (*query_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Haixia Shia7c69932016-07-28 10:51:12 -0700155 _EGLSurface *surf, EGLint attribute,
156 EGLint *value);
157
Eric Engestrom2e3eb0c2020-07-11 00:41:35 +0200158 /* optional */
Chad Versaceeadd5e02014-01-28 17:03:03 -0800159 struct wl_buffer* (*create_wayland_buffer_from_image)(
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000160 _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img);
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700161
Eric Engestrombc38fe82020-07-11 00:42:08 +0200162 /* optional */
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700163 EGLBoolean (*get_sync_values)(_EGLDisplay *display, _EGLSurface *surface,
164 EGLuint64KHR *ust, EGLuint64KHR *msc,
165 EGLuint64KHR *sbc);
Boyan Dinga25df542015-07-21 23:43:59 +0800166
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200167 /* mandatory */
Boyan Dinga25df542015-07-21 23:43:59 +0800168 __DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
Thomas Hellstrom2db95482017-08-10 15:35:39 +0200169
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200170 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000171 void (*close_screen_notify)(_EGLDisplay *disp);
Chad Versaceed7c6942018-04-30 22:35:17 -0700172
173 /* Used in EGL_KHR_mutable_render_buffer to update the native window's
174 * shared buffer mode.
Eric Engestrome0ef5a52020-07-13 11:08:53 +0200175 * optional
Chad Versaceed7c6942018-04-30 22:35:17 -0700176 */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000177 bool (*set_shared_buffer_mode)(_EGLDisplay *disp, _EGLSurface *surf,
Chad Versaceed7c6942018-04-30 22:35:17 -0700178 bool mode);
Chad Versace90502b12014-01-28 11:41:46 -0800179};
180
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500181struct dri2_egl_display
182{
Chad Versace90502b12014-01-28 11:41:46 -0800183 const struct dri2_egl_display_vtbl *vtbl;
184
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500185 int dri2_major;
186 int dri2_minor;
187 __DRIscreen *dri_screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100188 bool own_dri_screen;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500189 const __DRIconfig **driver_configs;
190 void *driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000191 const __DRIcoreExtension *core;
Boyan Dingf35198b2015-07-21 23:44:00 +0800192 const __DRIimageDriverExtension *image_driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000193 const __DRIdri2Extension *dri2;
194 const __DRIswrastExtension *swrast;
195 const __DRI2flushExtension *flush;
Adam Jacksonc0be3aa2016-09-22 03:47:55 -0400196 const __DRI2flushControlExtension *flush_control;
Emil Velikov5f280d02014-02-12 20:13:15 +0000197 const __DRItexBufferExtension *tex_buffer;
198 const __DRIimageExtension *image;
199 const __DRIrobustnessExtension *robustness;
Grigori Goronzy49095192017-06-29 02:44:03 +0200200 const __DRInoErrorExtension *no_error;
Emil Velikov5f280d02014-02-12 20:13:15 +0000201 const __DRI2configQueryExtension *config;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200202 const __DRI2fenceExtension *fence;
Harish Krupoa4a8ebe2019-08-12 12:07:06 +0200203 const __DRI2bufferDamageExtension *buffer_damage;
Tapani Pälli6f5b5702017-12-28 10:51:11 +0200204 const __DRI2blobExtension *blob;
Marek Olšák4f57ccd2015-06-10 14:45:58 +0200205 const __DRI2rendererQueryExtension *rendererQuery;
Marek Olšákb6eda702016-03-03 15:59:48 +0100206 const __DRI2interopExtension *interop;
Veluri Mithun85edfc02019-01-23 22:45:42 +0530207 const __DRIconfigOptionsExtension *configOptions;
Chad Versaceed7c6942018-04-30 22:35:17 -0700208 const __DRImutableRenderBufferDriverExtension *mutable_render_buffer;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500209 int fd;
210
Nicolas Boichat9ee683f2016-07-22 11:27:41 +0800211 /* dri2_initialize/dri2_terminate increment/decrement this count, so does
212 * dri2_make_current (tracks if there are active contexts/surfaces). */
213 int ref_count;
214
Eric Engestrom60f98422017-06-19 00:16:21 +0100215 bool own_device;
216 bool invalidate_available;
Eric Anholt7e9bd2b2012-09-25 14:05:30 -0700217 int min_swap_interval;
218 int max_swap_interval;
219 int default_swap_interval;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200220#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200221 struct gbm_dri_device *gbm_dri;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200222#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200223
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500224 char *driver_name;
225
Emil Velikovf8719462016-08-24 23:32:27 +0100226 const __DRIextension **loader_extensions;
Eric Anholtf93533d2013-09-27 11:39:25 -0700227 const __DRIextension **driver_extensions;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400228
229#ifdef HAVE_X11_PLATFORM
230 xcb_connection_t *conn;
Emil Velikov7c6babb2016-11-21 13:46:51 +0000231 xcb_screen_t *screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100232 bool swap_available;
Boyan Dingf35198b2015-07-21 23:44:00 +0800233#ifdef HAVE_DRI3
Louis-Francis Ratté-Boulianne069fdd52017-07-07 02:54:26 -0400234 bool multibuffers_available;
235 int dri3_major_version;
236 int dri3_minor_version;
Louis-Francis Ratté-Boulianne3160cb82017-10-06 01:26:51 -0400237 int present_major_version;
238 int present_minor_version;
Boyan Dingf35198b2015-07-21 23:44:00 +0800239 struct loader_dri3_extensions loader_dri3_ext;
240#endif
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400241#endif
242
Benjamin Franzke93aea842011-02-04 12:39:40 +0100243#ifdef HAVE_WAYLAND_PLATFORM
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400244 struct wl_display *wl_dpy;
Jonas Ådahl36b99762017-01-13 23:05:10 +0800245 struct wl_display *wl_dpy_wrapper;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400246 struct wl_registry *wl_registry;
Benjamin Franzke6b369c42011-02-21 16:22:34 +0100247 struct wl_drm *wl_server_drm;
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400248 struct wl_drm *wl_drm;
Axel Davycdcfe482015-05-01 11:11:20 +0200249 struct wl_shm *wl_shm;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400250 struct wl_event_queue *wl_queue;
Daniel Stone02cc3592017-06-16 18:01:23 +0100251 struct zwp_linux_dmabuf_v1 *wl_dmabuf;
Daniel Stone47320942018-02-06 10:29:13 +0000252 struct u_vector *wl_modifiers;
Eric Engestrom60f98422017-06-19 00:16:21 +0100253 bool authenticated;
Eric Engestromfbf7c382018-11-27 12:27:45 +0000254 BITSET_DECLARE(formats, EGL_DRI2_MAX_FORMATS);
Kristian Høgsbergde315f72013-02-02 12:26:12 -0500255 uint32_t capabilities;
Frank Binnsd6f669b2016-06-17 18:41:22 +0100256 char *device_name;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100257#endif
Boyan Dingf35198b2015-07-21 23:44:00 +0800258
Tomasz Figa859d0b02016-11-10 16:55:52 +0900259#ifdef HAVE_ANDROID_PLATFORM
260 const gralloc_module_t *gralloc;
261#endif
262
Eric Engestrom60f98422017-06-19 00:16:21 +0100263 bool is_render_node;
Eric Engestrom4a1238a2017-06-19 00:16:51 +0100264 bool is_different_gpu;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500265};
266
267struct dri2_egl_context
268{
269 _EGLContext base;
270 __DRIcontext *dri_context;
271};
272
Benjamin Franzke93aea842011-02-04 12:39:40 +0100273#ifdef HAVE_WAYLAND_PLATFORM
274enum wayland_buffer_type {
275 WL_BUFFER_FRONT,
276 WL_BUFFER_BACK,
Benjamin Franzke0cb356d2011-05-06 19:13:29 +0200277 WL_BUFFER_THIRD,
Benjamin Franzke93aea842011-02-04 12:39:40 +0100278 WL_BUFFER_COUNT
279};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100280#endif
281
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500282struct dri2_egl_surface
283{
284 _EGLSurface base;
285 __DRIdrawable *dri_drawable;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500286 __DRIbuffer buffers[5];
Eric Engestrom60f98422017-06-19 00:16:21 +0100287 bool have_fake_front;
Haitao Fengf55d0272011-02-16 23:05:15 -0500288
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400289#ifdef HAVE_X11_PLATFORM
290 xcb_drawable_t drawable;
291 xcb_xfixes_region_t region;
Haitao Fengf55d0272011-02-16 23:05:15 -0500292 int depth;
293 int bytes_per_pixel;
294 xcb_gcontext_t gc;
295 xcb_gcontext_t swapgc;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400296#endif
Haitao Fengf55d0272011-02-16 23:05:15 -0500297
Benjamin Franzke93aea842011-02-04 12:39:40 +0100298#ifdef HAVE_WAYLAND_PLATFORM
299 struct wl_egl_window *wl_win;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100300 int dx;
301 int dy;
Daniel Stone03dd9a82017-05-05 14:49:09 +0100302 struct wl_event_queue *wl_queue;
303 struct wl_surface *wl_surface_wrapper;
304 struct wl_display *wl_dpy_wrapper;
305 struct wl_drm *wl_drm_wrapper;
Neil Roberts992a2db2013-11-15 13:50:50 +0000306 struct wl_callback *throttle_callback;
Emil Velikovebc68e32016-08-25 00:12:13 +0100307 int format;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100308#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900309
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200310#ifdef HAVE_DRM_PLATFORM
311 struct gbm_dri_surface *gbm_surf;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200312#endif
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500313
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900314 /* EGL-owned buffers */
315 __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
316
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500317#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500318 struct {
319#ifdef HAVE_WAYLAND_PLATFORM
320 struct wl_buffer *wl_buffer;
Juan A. Suarez Romero54a96222018-08-30 10:14:49 +0200321 bool wl_release;
Kristian Høgsberg664fe6d2013-02-02 07:40:51 -0500322 __DRIimage *dri_image;
Axel Davy4cd546d2015-05-01 01:16:24 +0200323 /* for is_different_gpu case. NULL else */
324 __DRIimage *linear_copy;
Axel Davycdcfe482015-05-01 11:11:20 +0200325 /* for swrast */
326 void *data;
327 int data_size;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500328#endif
329#ifdef HAVE_DRM_PLATFORM
330 struct gbm_bo *bo;
331#endif
Eric Engestrom60f98422017-06-19 00:16:21 +0100332 bool locked;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500333 int age;
Neil Roberts992a2db2013-11-15 13:50:50 +0000334 } color_buffers[4], *back, *current;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200335#endif
336
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900337#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu75cc24c2011-11-25 11:59:02 +0800338 struct ANativeWindow *window;
339 struct ANativeWindowBuffer *buffer;
Liu Zhiquanb6637532016-11-16 10:11:28 +0800340 __DRIimage *dri_image_back;
341 __DRIimage *dri_image_front;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900342
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800343 /* Used to record all the buffers created by ANativeWindow and their ages.
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700344 * Allocate number of color_buffers based on query to android bufferqueue
345 * and save color_buffers_count.
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800346 */
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700347 int color_buffers_count;
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800348 struct {
349 struct ANativeWindowBuffer *buffer;
350 int age;
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700351 } *color_buffers, *back;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900352#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500353
Emil Velikovd6edcce2019-05-16 18:01:40 +0100354 /* surfaceless and device */
355 __DRIimage *front;
356 unsigned int visual;
357
Zhongmin Wue013ce82017-09-15 18:32:42 +0100358 int out_fence_fd;
359 EGLBoolean enable_out_fence;
Mathias Fröhlichc7617d82019-12-13 17:09:56 +0100360
361 /* swrast device */
362 char *swrast_device_buffer;
Gurchetan Singh63c5d5c2016-05-16 16:34:07 -0700363};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100364
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500365struct dri2_egl_config
366{
367 _EGLConfig base;
Eric Engestromb81cfc72017-06-21 10:40:31 +0100368 const __DRIconfig *dri_config[2][2];
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500369};
370
371struct dri2_egl_image
372{
373 _EGLImage base;
374 __DRIimage *dri_image;
375};
376
Marek Olšák9a0bda22015-04-10 10:56:02 +0200377struct dri2_egl_sync {
378 _EGLSync base;
Dongwon Kim70299472016-04-04 17:14:10 -0700379 mtx_t mutex;
380 cnd_t cond;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200381 int refcount;
382 void *fence;
383};
384
Eric Engestrom04e8eaf2020-06-12 11:42:32 +0200385/* From driconf.h, user exposed so should be stable */
Neil Roberts992a2db2013-11-15 13:50:50 +0000386#define DRI_CONF_VBLANK_NEVER 0
387#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
388#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
389#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
390
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500391/* standard typecasts */
392_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
393_EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj)
Marek Olšák9a0bda22015-04-10 10:56:02 +0200394_EGL_DRIVER_TYPECAST(dri2_egl_sync, _EGLSync, obj)
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500395
396extern const __DRIimageLookupExtension image_lookup_extension;
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500397extern const __DRIuseInvalidateExtension use_invalidate;
Eric Anholt3b7b6ad2012-12-27 17:39:37 -0800398extern const __DRIbackgroundCallableExtension background_callable_extension;
Eric Anholt6a8d39dc2019-07-23 13:18:21 -0700399extern const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500400
401EGLBoolean
402dri2_load_driver(_EGLDisplay *disp);
403
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200404/* Helper for platforms not using dri2_create_screen */
405void
406dri2_setup_screen(_EGLDisplay *disp);
407
Emil Velikov47b06f52017-08-05 00:25:46 +0100408void
409dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval);
410
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500411EGLBoolean
Chia-I Wucf69eea2011-06-08 16:33:55 +0800412dri2_load_driver_swrast(_EGLDisplay *disp);
413
414EGLBoolean
Boyan Dingf35198b2015-07-21 23:44:00 +0800415dri2_load_driver_dri3(_EGLDisplay *disp);
416
417EGLBoolean
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500418dri2_create_screen(_EGLDisplay *disp);
419
Emil Velikov2c341f22017-05-11 16:20:04 +0100420EGLBoolean
421dri2_setup_extensions(_EGLDisplay *disp);
422
Boyan Dinga25df542015-07-21 23:43:59 +0800423__DRIdrawable *
424dri2_surface_get_dri_drawable(_EGLSurface *surf);
425
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200426__DRIimage *
427dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data);
428
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800429void
430dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
431 const __DRIconfig *config, int *shifts,
432 unsigned int *sizes);
433
Kevin Strasser482ed432019-01-24 16:55:33 -0800434void
435dri2_get_render_type_float(const __DRIcoreExtension *core,
436 const __DRIconfig *config,
437 bool *is_float);
438
Mathias Fröhlichd32c4582020-02-09 19:01:53 +0100439unsigned int
440dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy,
441 const __DRIconfig *config);
442
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500443struct dri2_egl_config *
444dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
Emil Velikovebc68e32016-08-25 00:12:13 +0100445 EGLint surface_type, const EGLint *attr_list,
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800446 const int *rgba_shifts, const unsigned int *rgba_sizes);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500447
Mathias Fröhlichf280c002020-02-16 11:13:43 +0100448EGLBoolean
449dri2_add_pbuffer_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp);
450
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500451_EGLImage *
452dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
Emil Velikovebc68e32016-08-25 00:12:13 +0100453 _EGLContext *ctx, EGLenum target,
454 EGLClientBuffer buffer, const EGLint *attr_list);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500455
Emil Velikov38ef6f52016-05-01 12:42:53 +0100456_EGLImage *
457dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
Emil Velikovebc68e32016-08-25 00:12:13 +0100458 EGLClientBuffer buffer, const EGLint *attr_list);
Emil Velikov38ef6f52016-05-01 12:42:53 +0100459
Emil Velikov55245fe2017-11-09 17:55:19 +0000460#ifdef HAVE_X11_PLATFORM
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500461EGLBoolean
462dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov938fcab2017-11-09 18:58:52 +0000463void
464dri2_teardown_x11(struct dri2_egl_display *dri2_dpy);
Mario Kleiner61a02722018-06-13 06:04:13 +0200465unsigned int
466dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth);
Emil Velikov55245fe2017-11-09 17:55:19 +0000467#else
468static inline EGLBoolean
469dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp)
470{
471 return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
472}
Emil Velikov938fcab2017-11-09 18:58:52 +0000473static inline void
474dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) {}
Mario Kleiner61a02722018-06-13 06:04:13 +0200475static inline unsigned int
476dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
477{
478 return 0;
479}
Emil Velikov55245fe2017-11-09 17:55:19 +0000480#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500481
Emil Velikov55245fe2017-11-09 17:55:19 +0000482#ifdef HAVE_DRM_PLATFORM
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500483EGLBoolean
484dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov40a01c92017-11-09 19:04:25 +0000485void
486dri2_teardown_drm(struct dri2_egl_display *dri2_dpy);
Emil Velikov55245fe2017-11-09 17:55:19 +0000487#else
488static inline EGLBoolean
489dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
490{
491 return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built");
492}
Emil Velikov40a01c92017-11-09 19:04:25 +0000493static inline void
494dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000495#endif
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500496
Emil Velikov55245fe2017-11-09 17:55:19 +0000497#ifdef HAVE_WAYLAND_PLATFORM
Benjamin Franzke93aea842011-02-04 12:39:40 +0100498EGLBoolean
499dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov8d745ab2017-11-09 19:13:09 +0000500void
501dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy);
Mario Kleiner820dfce2018-06-13 06:04:15 +0200502bool
503dri2_wl_is_format_supported(void* user_data, uint32_t format);
Emil Velikov55245fe2017-11-09 17:55:19 +0000504#else
505static inline EGLBoolean
506dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
507{
508 return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built");
509}
Emil Velikov8d745ab2017-11-09 19:13:09 +0000510static inline void
511dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000512#endif
Benjamin Franzke93aea842011-02-04 12:39:40 +0100513
Emil Velikov55245fe2017-11-09 17:55:19 +0000514#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900515EGLBoolean
516dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov55245fe2017-11-09 17:55:19 +0000517#else
518static inline EGLBoolean
519dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
520{
521 return _eglError(EGL_NOT_INITIALIZED, "Android platform not built");
522}
523#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900524
Haixia Shi6b8accb2015-06-12 10:10:58 -0700525EGLBoolean
526dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
527
Emil Velikovd6edcce2019-05-16 18:01:40 +0100528EGLBoolean
529dri2_initialize_device(_EGLDriver *drv, _EGLDisplay *disp);
530static inline void
531dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ }
532
Eric Anholt70e8ccc2014-12-21 11:51:33 -0800533void
534dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
535
Marek Olšákc2c2e9a2015-06-10 02:49:29 +0200536const __DRIconfig *
537dri2_get_dri_config(struct dri2_egl_config *conf, EGLint surface_type,
538 EGLenum colorspace);
539
Emil Velikov98f5d012016-08-25 13:15:43 +0100540static inline void
541dri2_set_WL_bind_wayland_display(_EGLDriver *drv, _EGLDisplay *disp)
542{
543#ifdef HAVE_WAYLAND_PLATFORM
544 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
545
546 (void) drv;
547
548 if (dri2_dpy->device_name && dri2_dpy->image) {
549 if (dri2_dpy->image->base.version >= 10 &&
550 dri2_dpy->image->getCapabilities != NULL) {
551 int capabilities;
552
553 capabilities =
554 dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
555 disp->Extensions.WL_bind_wayland_display =
556 (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
557 } else {
558 disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
559 }
560 }
561#endif
562}
563
Emil Velikov3e73c022017-05-11 17:13:33 +0100564void
565dri2_display_destroy(_EGLDisplay *disp);
566
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900567__DRIbuffer *
568dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
569 unsigned int att, unsigned int format);
570
571void
572dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
573
Zhongmin Wue013ce82017-09-15 18:32:42 +0100574EGLBoolean
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000575dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
Paulo Zanoni04ecda32019-05-01 15:42:26 -0700576 _EGLConfig *conf, const EGLint *attrib_list,
577 EGLBoolean enable_out_fence, void *native_surface);
Zhongmin Wue013ce82017-09-15 18:32:42 +0100578
579void
580dri2_fini_surface(_EGLSurface *surf);
581
Emil Velikov2282ec02019-05-16 18:01:38 +0100582EGLBoolean
583dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
584 const __DRIconfig *config,
Mathias Fröhlicha7ecf782019-06-07 07:12:42 +0200585 struct dri2_egl_surface *dri2_surf,
586 void *loaderPrivate);
Emil Velikov2282ec02019-05-16 18:01:38 +0100587
Eric Engestrom2de9e842018-08-16 15:22:46 +0100588static inline uint64_t
589combine_u32_into_u64(uint32_t hi, uint32_t lo)
590{
591 return (((uint64_t) hi) << 32) | (((uint64_t) lo) & 0xffffffff);
592}
593
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500594#endif /* EGL_DRI2_INCLUDED */