blob: c90f560bc7873963fba3e479f5d3a344ec2af01d [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 {
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 Engestrom179e4422020-07-11 00:29:17 +020098 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +000099 _EGLSurface* (*create_pixmap_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacebc8b07a2014-01-28 16:45:07 -0800100 _EGLConfig *config,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800101 void *native_pixmap,
Chad Versacebc8b07a2014-01-28 16:45:07 -0800102 const EGLint *attrib_list);
103
Eric Engestrom43e2d802020-07-11 00:31:32 +0200104 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000105 _EGLSurface* (*create_pbuffer_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacebf200762014-01-28 17:03:03 -0800106 _EGLConfig *config,
107 const EGLint *attrib_list);
108
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000109 EGLBoolean (*destroy_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace958dd802014-01-28 17:03:03 -0800110 _EGLSurface *surface);
111
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000112 EGLBoolean (*swap_interval)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace8b9298a2014-01-28 12:34:19 -0800113 _EGLSurface *surf, EGLint interval);
Chad Versacead173bc2014-01-28 16:21:21 -0800114
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000115 _EGLImage* (*create_image)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versaceeef68a92014-01-28 17:03:03 -0800116 _EGLContext *ctx, EGLenum target,
117 EGLClientBuffer buffer,
118 const EGLint *attr_list);
119
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000120 EGLBoolean (*swap_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versacead173bc2014-01-28 16:21:21 -0800121 _EGLSurface *surf);
Chad Versaced03948a2014-01-28 16:26:44 -0800122
Eric Engestrom7d5a13e2020-07-11 00:36:08 +0200123 /* optional - falls back to .swap_buffers */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000124 EGLBoolean (*swap_buffers_with_damage)(_EGLDriver *drv, _EGLDisplay *disp,
Boyan Ding052b3d42015-06-13 15:36:27 +0800125 _EGLSurface *surface,
126 const EGLint *rects, EGLint n_rects);
Chad Versace3fdfbd22014-01-28 17:03:03 -0800127
Eric Engestrom1ba5075a2020-07-11 00:38:38 +0200128 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000129 EGLBoolean (*swap_buffers_region)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace75d398e2014-01-28 17:03:03 -0800130 _EGLSurface *surf, EGLint numRects,
131 const EGLint *rects);
132
Eric Engestrom2d5f12ae32020-07-11 00:39:41 +0200133 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000134 EGLBoolean (*post_sub_buffer)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace688a0e82014-01-28 17:03:03 -0800135 _EGLSurface *surf,
136 EGLint x, EGLint y,
137 EGLint width, EGLint height);
138
Eric Engestrom90000b02020-07-11 00:40:20 +0200139 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000140 EGLBoolean (*copy_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800141 _EGLSurface *surf, void *native_pixmap_target);
Chad Versacebc2cbc02014-01-28 17:03:03 -0800142
Eric Engestromc5fb1fb2020-07-11 00:40:57 +0200143 /* optional */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000144 EGLint (*query_buffer_age)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace3fdfbd22014-01-28 17:03:03 -0800145 _EGLSurface *surf);
Chad Versaceeadd5e02014-01-28 17:03:03 -0800146
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000147 EGLBoolean (*query_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Haixia Shia7c69932016-07-28 10:51:12 -0700148 _EGLSurface *surf, EGLint attribute,
149 EGLint *value);
150
Eric Engestrom2e3eb0c2020-07-11 00:41:35 +0200151 /* optional */
Chad Versaceeadd5e02014-01-28 17:03:03 -0800152 struct wl_buffer* (*create_wayland_buffer_from_image)(
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000153 _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img);
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700154
155 EGLBoolean (*get_sync_values)(_EGLDisplay *display, _EGLSurface *surface,
156 EGLuint64KHR *ust, EGLuint64KHR *msc,
157 EGLuint64KHR *sbc);
Boyan Dinga25df542015-07-21 23:43:59 +0800158
159 __DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
Thomas Hellstrom2db95482017-08-10 15:35:39 +0200160
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000161 void (*close_screen_notify)(_EGLDisplay *disp);
Chad Versaceed7c6942018-04-30 22:35:17 -0700162
163 /* Used in EGL_KHR_mutable_render_buffer to update the native window's
164 * shared buffer mode.
165 */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000166 bool (*set_shared_buffer_mode)(_EGLDisplay *disp, _EGLSurface *surf,
Chad Versaceed7c6942018-04-30 22:35:17 -0700167 bool mode);
Chad Versace90502b12014-01-28 11:41:46 -0800168};
169
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500170struct dri2_egl_display
171{
Chad Versace90502b12014-01-28 11:41:46 -0800172 const struct dri2_egl_display_vtbl *vtbl;
173
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500174 int dri2_major;
175 int dri2_minor;
176 __DRIscreen *dri_screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100177 bool own_dri_screen;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500178 const __DRIconfig **driver_configs;
179 void *driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000180 const __DRIcoreExtension *core;
Boyan Dingf35198b2015-07-21 23:44:00 +0800181 const __DRIimageDriverExtension *image_driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000182 const __DRIdri2Extension *dri2;
183 const __DRIswrastExtension *swrast;
184 const __DRI2flushExtension *flush;
Adam Jacksonc0be3aa2016-09-22 03:47:55 -0400185 const __DRI2flushControlExtension *flush_control;
Emil Velikov5f280d02014-02-12 20:13:15 +0000186 const __DRItexBufferExtension *tex_buffer;
187 const __DRIimageExtension *image;
188 const __DRIrobustnessExtension *robustness;
Grigori Goronzy49095192017-06-29 02:44:03 +0200189 const __DRInoErrorExtension *no_error;
Emil Velikov5f280d02014-02-12 20:13:15 +0000190 const __DRI2configQueryExtension *config;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200191 const __DRI2fenceExtension *fence;
Harish Krupoa4a8ebe2019-08-12 12:07:06 +0200192 const __DRI2bufferDamageExtension *buffer_damage;
Tapani Pälli6f5b5702017-12-28 10:51:11 +0200193 const __DRI2blobExtension *blob;
Marek Olšák4f57ccd2015-06-10 14:45:58 +0200194 const __DRI2rendererQueryExtension *rendererQuery;
Marek Olšákb6eda702016-03-03 15:59:48 +0100195 const __DRI2interopExtension *interop;
Veluri Mithun85edfc02019-01-23 22:45:42 +0530196 const __DRIconfigOptionsExtension *configOptions;
Chad Versaceed7c6942018-04-30 22:35:17 -0700197 const __DRImutableRenderBufferDriverExtension *mutable_render_buffer;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500198 int fd;
199
Nicolas Boichat9ee683f2016-07-22 11:27:41 +0800200 /* dri2_initialize/dri2_terminate increment/decrement this count, so does
201 * dri2_make_current (tracks if there are active contexts/surfaces). */
202 int ref_count;
203
Eric Engestrom60f98422017-06-19 00:16:21 +0100204 bool own_device;
205 bool invalidate_available;
Eric Anholt7e9bd2b2012-09-25 14:05:30 -0700206 int min_swap_interval;
207 int max_swap_interval;
208 int default_swap_interval;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200209#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200210 struct gbm_dri_device *gbm_dri;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200211#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200212
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500213 char *driver_name;
214
Emil Velikovf8719462016-08-24 23:32:27 +0100215 const __DRIextension **loader_extensions;
Eric Anholtf93533d2013-09-27 11:39:25 -0700216 const __DRIextension **driver_extensions;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400217
218#ifdef HAVE_X11_PLATFORM
219 xcb_connection_t *conn;
Emil Velikov7c6babb2016-11-21 13:46:51 +0000220 xcb_screen_t *screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100221 bool swap_available;
Boyan Dingf35198b2015-07-21 23:44:00 +0800222#ifdef HAVE_DRI3
Louis-Francis Ratté-Boulianne069fdd52017-07-07 02:54:26 -0400223 bool multibuffers_available;
224 int dri3_major_version;
225 int dri3_minor_version;
Louis-Francis Ratté-Boulianne3160cb82017-10-06 01:26:51 -0400226 int present_major_version;
227 int present_minor_version;
Boyan Dingf35198b2015-07-21 23:44:00 +0800228 struct loader_dri3_extensions loader_dri3_ext;
229#endif
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400230#endif
231
Benjamin Franzke93aea842011-02-04 12:39:40 +0100232#ifdef HAVE_WAYLAND_PLATFORM
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400233 struct wl_display *wl_dpy;
Jonas Ådahl36b99762017-01-13 23:05:10 +0800234 struct wl_display *wl_dpy_wrapper;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400235 struct wl_registry *wl_registry;
Benjamin Franzke6b369c42011-02-21 16:22:34 +0100236 struct wl_drm *wl_server_drm;
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400237 struct wl_drm *wl_drm;
Axel Davycdcfe482015-05-01 11:11:20 +0200238 struct wl_shm *wl_shm;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400239 struct wl_event_queue *wl_queue;
Daniel Stone02cc3592017-06-16 18:01:23 +0100240 struct zwp_linux_dmabuf_v1 *wl_dmabuf;
Daniel Stone47320942018-02-06 10:29:13 +0000241 struct u_vector *wl_modifiers;
Eric Engestrom60f98422017-06-19 00:16:21 +0100242 bool authenticated;
Eric Engestromfbf7c382018-11-27 12:27:45 +0000243 BITSET_DECLARE(formats, EGL_DRI2_MAX_FORMATS);
Kristian Høgsbergde315f72013-02-02 12:26:12 -0500244 uint32_t capabilities;
Frank Binnsd6f669b2016-06-17 18:41:22 +0100245 char *device_name;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100246#endif
Boyan Dingf35198b2015-07-21 23:44:00 +0800247
Tomasz Figa859d0b02016-11-10 16:55:52 +0900248#ifdef HAVE_ANDROID_PLATFORM
249 const gralloc_module_t *gralloc;
250#endif
251
Eric Engestrom60f98422017-06-19 00:16:21 +0100252 bool is_render_node;
Eric Engestrom4a1238a2017-06-19 00:16:51 +0100253 bool is_different_gpu;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500254};
255
256struct dri2_egl_context
257{
258 _EGLContext base;
259 __DRIcontext *dri_context;
260};
261
Benjamin Franzke93aea842011-02-04 12:39:40 +0100262#ifdef HAVE_WAYLAND_PLATFORM
263enum wayland_buffer_type {
264 WL_BUFFER_FRONT,
265 WL_BUFFER_BACK,
Benjamin Franzke0cb356d2011-05-06 19:13:29 +0200266 WL_BUFFER_THIRD,
Benjamin Franzke93aea842011-02-04 12:39:40 +0100267 WL_BUFFER_COUNT
268};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100269#endif
270
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500271struct dri2_egl_surface
272{
273 _EGLSurface base;
274 __DRIdrawable *dri_drawable;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500275 __DRIbuffer buffers[5];
Eric Engestrom60f98422017-06-19 00:16:21 +0100276 bool have_fake_front;
Haitao Fengf55d0272011-02-16 23:05:15 -0500277
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400278#ifdef HAVE_X11_PLATFORM
279 xcb_drawable_t drawable;
280 xcb_xfixes_region_t region;
Haitao Fengf55d0272011-02-16 23:05:15 -0500281 int depth;
282 int bytes_per_pixel;
283 xcb_gcontext_t gc;
284 xcb_gcontext_t swapgc;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400285#endif
Haitao Fengf55d0272011-02-16 23:05:15 -0500286
Benjamin Franzke93aea842011-02-04 12:39:40 +0100287#ifdef HAVE_WAYLAND_PLATFORM
288 struct wl_egl_window *wl_win;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100289 int dx;
290 int dy;
Daniel Stone03dd9a82017-05-05 14:49:09 +0100291 struct wl_event_queue *wl_queue;
292 struct wl_surface *wl_surface_wrapper;
293 struct wl_display *wl_dpy_wrapper;
294 struct wl_drm *wl_drm_wrapper;
Neil Roberts992a2db2013-11-15 13:50:50 +0000295 struct wl_callback *throttle_callback;
Emil Velikovebc68e32016-08-25 00:12:13 +0100296 int format;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100297#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900298
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200299#ifdef HAVE_DRM_PLATFORM
300 struct gbm_dri_surface *gbm_surf;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200301#endif
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500302
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900303 /* EGL-owned buffers */
304 __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
305
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500306#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500307 struct {
308#ifdef HAVE_WAYLAND_PLATFORM
309 struct wl_buffer *wl_buffer;
Juan A. Suarez Romero54a96222018-08-30 10:14:49 +0200310 bool wl_release;
Kristian Høgsberg664fe6d2013-02-02 07:40:51 -0500311 __DRIimage *dri_image;
Axel Davy4cd546d2015-05-01 01:16:24 +0200312 /* for is_different_gpu case. NULL else */
313 __DRIimage *linear_copy;
Axel Davycdcfe482015-05-01 11:11:20 +0200314 /* for swrast */
315 void *data;
316 int data_size;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500317#endif
318#ifdef HAVE_DRM_PLATFORM
319 struct gbm_bo *bo;
320#endif
Eric Engestrom60f98422017-06-19 00:16:21 +0100321 bool locked;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500322 int age;
Neil Roberts992a2db2013-11-15 13:50:50 +0000323 } color_buffers[4], *back, *current;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200324#endif
325
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900326#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu75cc24c2011-11-25 11:59:02 +0800327 struct ANativeWindow *window;
328 struct ANativeWindowBuffer *buffer;
Liu Zhiquanb6637532016-11-16 10:11:28 +0800329 __DRIimage *dri_image_back;
330 __DRIimage *dri_image_front;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900331
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800332 /* Used to record all the buffers created by ANativeWindow and their ages.
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700333 * Allocate number of color_buffers based on query to android bufferqueue
334 * and save color_buffers_count.
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800335 */
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700336 int color_buffers_count;
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800337 struct {
338 struct ANativeWindowBuffer *buffer;
339 int age;
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700340 } *color_buffers, *back;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900341#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500342
Emil Velikovd6edcce2019-05-16 18:01:40 +0100343 /* surfaceless and device */
344 __DRIimage *front;
345 unsigned int visual;
346
Zhongmin Wue013ce82017-09-15 18:32:42 +0100347 int out_fence_fd;
348 EGLBoolean enable_out_fence;
Mathias Fröhlichc7617d82019-12-13 17:09:56 +0100349
350 /* swrast device */
351 char *swrast_device_buffer;
Gurchetan Singh63c5d5c2016-05-16 16:34:07 -0700352};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100353
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500354struct dri2_egl_config
355{
356 _EGLConfig base;
Eric Engestromb81cfc72017-06-21 10:40:31 +0100357 const __DRIconfig *dri_config[2][2];
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500358};
359
360struct dri2_egl_image
361{
362 _EGLImage base;
363 __DRIimage *dri_image;
364};
365
Marek Olšák9a0bda22015-04-10 10:56:02 +0200366struct dri2_egl_sync {
367 _EGLSync base;
Dongwon Kim70299472016-04-04 17:14:10 -0700368 mtx_t mutex;
369 cnd_t cond;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200370 int refcount;
371 void *fence;
372};
373
Eric Engestrom04e8eaf2020-06-12 11:42:32 +0200374/* From driconf.h, user exposed so should be stable */
Neil Roberts992a2db2013-11-15 13:50:50 +0000375#define DRI_CONF_VBLANK_NEVER 0
376#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
377#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
378#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
379
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500380/* standard typecasts */
381_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
382_EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj)
Marek Olšák9a0bda22015-04-10 10:56:02 +0200383_EGL_DRIVER_TYPECAST(dri2_egl_sync, _EGLSync, obj)
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500384
385extern const __DRIimageLookupExtension image_lookup_extension;
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500386extern const __DRIuseInvalidateExtension use_invalidate;
Eric Anholt3b7b6ad2012-12-27 17:39:37 -0800387extern const __DRIbackgroundCallableExtension background_callable_extension;
Eric Anholt6a8d39dc2019-07-23 13:18:21 -0700388extern const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500389
390EGLBoolean
391dri2_load_driver(_EGLDisplay *disp);
392
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200393/* Helper for platforms not using dri2_create_screen */
394void
395dri2_setup_screen(_EGLDisplay *disp);
396
Emil Velikov47b06f52017-08-05 00:25:46 +0100397void
398dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval);
399
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500400EGLBoolean
Chia-I Wucf69eea2011-06-08 16:33:55 +0800401dri2_load_driver_swrast(_EGLDisplay *disp);
402
403EGLBoolean
Boyan Dingf35198b2015-07-21 23:44:00 +0800404dri2_load_driver_dri3(_EGLDisplay *disp);
405
406EGLBoolean
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500407dri2_create_screen(_EGLDisplay *disp);
408
Emil Velikov2c341f22017-05-11 16:20:04 +0100409EGLBoolean
410dri2_setup_extensions(_EGLDisplay *disp);
411
Boyan Dinga25df542015-07-21 23:43:59 +0800412__DRIdrawable *
413dri2_surface_get_dri_drawable(_EGLSurface *surf);
414
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200415__DRIimage *
416dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data);
417
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800418void
419dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
420 const __DRIconfig *config, int *shifts,
421 unsigned int *sizes);
422
Kevin Strasser482ed432019-01-24 16:55:33 -0800423void
424dri2_get_render_type_float(const __DRIcoreExtension *core,
425 const __DRIconfig *config,
426 bool *is_float);
427
Mathias Fröhlichd32c4582020-02-09 19:01:53 +0100428unsigned int
429dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy,
430 const __DRIconfig *config);
431
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500432struct dri2_egl_config *
433dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
Emil Velikovebc68e32016-08-25 00:12:13 +0100434 EGLint surface_type, const EGLint *attr_list,
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800435 const int *rgba_shifts, const unsigned int *rgba_sizes);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500436
Mathias Fröhlichf280c002020-02-16 11:13:43 +0100437EGLBoolean
438dri2_add_pbuffer_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp);
439
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500440_EGLImage *
441dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
Emil Velikovebc68e32016-08-25 00:12:13 +0100442 _EGLContext *ctx, EGLenum target,
443 EGLClientBuffer buffer, const EGLint *attr_list);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500444
Emil Velikov38ef6f52016-05-01 12:42:53 +0100445_EGLImage *
446dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
Emil Velikovebc68e32016-08-25 00:12:13 +0100447 EGLClientBuffer buffer, const EGLint *attr_list);
Emil Velikov38ef6f52016-05-01 12:42:53 +0100448
Emil Velikov55245fe2017-11-09 17:55:19 +0000449#ifdef HAVE_X11_PLATFORM
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500450EGLBoolean
451dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov938fcab2017-11-09 18:58:52 +0000452void
453dri2_teardown_x11(struct dri2_egl_display *dri2_dpy);
Mario Kleiner61a02722018-06-13 06:04:13 +0200454unsigned int
455dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth);
Emil Velikov55245fe2017-11-09 17:55:19 +0000456#else
457static inline EGLBoolean
458dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp)
459{
460 return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
461}
Emil Velikov938fcab2017-11-09 18:58:52 +0000462static inline void
463dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) {}
Mario Kleiner61a02722018-06-13 06:04:13 +0200464static inline unsigned int
465dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
466{
467 return 0;
468}
Emil Velikov55245fe2017-11-09 17:55:19 +0000469#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500470
Emil Velikov55245fe2017-11-09 17:55:19 +0000471#ifdef HAVE_DRM_PLATFORM
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500472EGLBoolean
473dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov40a01c92017-11-09 19:04:25 +0000474void
475dri2_teardown_drm(struct dri2_egl_display *dri2_dpy);
Emil Velikov55245fe2017-11-09 17:55:19 +0000476#else
477static inline EGLBoolean
478dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
479{
480 return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built");
481}
Emil Velikov40a01c92017-11-09 19:04:25 +0000482static inline void
483dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000484#endif
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500485
Emil Velikov55245fe2017-11-09 17:55:19 +0000486#ifdef HAVE_WAYLAND_PLATFORM
Benjamin Franzke93aea842011-02-04 12:39:40 +0100487EGLBoolean
488dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov8d745ab2017-11-09 19:13:09 +0000489void
490dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy);
Mario Kleiner820dfce2018-06-13 06:04:15 +0200491bool
492dri2_wl_is_format_supported(void* user_data, uint32_t format);
Emil Velikov55245fe2017-11-09 17:55:19 +0000493#else
494static inline EGLBoolean
495dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
496{
497 return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built");
498}
Emil Velikov8d745ab2017-11-09 19:13:09 +0000499static inline void
500dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000501#endif
Benjamin Franzke93aea842011-02-04 12:39:40 +0100502
Emil Velikov55245fe2017-11-09 17:55:19 +0000503#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900504EGLBoolean
505dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov55245fe2017-11-09 17:55:19 +0000506#else
507static inline EGLBoolean
508dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
509{
510 return _eglError(EGL_NOT_INITIALIZED, "Android platform not built");
511}
512#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900513
Haixia Shi6b8accb2015-06-12 10:10:58 -0700514EGLBoolean
515dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
516
Emil Velikovd6edcce2019-05-16 18:01:40 +0100517EGLBoolean
518dri2_initialize_device(_EGLDriver *drv, _EGLDisplay *disp);
519static inline void
520dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ }
521
Eric Anholt70e8ccc2014-12-21 11:51:33 -0800522void
523dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
524
Marek Olšákc2c2e9a2015-06-10 02:49:29 +0200525const __DRIconfig *
526dri2_get_dri_config(struct dri2_egl_config *conf, EGLint surface_type,
527 EGLenum colorspace);
528
Emil Velikov98f5d012016-08-25 13:15:43 +0100529static inline void
530dri2_set_WL_bind_wayland_display(_EGLDriver *drv, _EGLDisplay *disp)
531{
532#ifdef HAVE_WAYLAND_PLATFORM
533 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
534
535 (void) drv;
536
537 if (dri2_dpy->device_name && dri2_dpy->image) {
538 if (dri2_dpy->image->base.version >= 10 &&
539 dri2_dpy->image->getCapabilities != NULL) {
540 int capabilities;
541
542 capabilities =
543 dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
544 disp->Extensions.WL_bind_wayland_display =
545 (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
546 } else {
547 disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
548 }
549 }
550#endif
551}
552
Emil Velikov3e73c022017-05-11 17:13:33 +0100553void
554dri2_display_destroy(_EGLDisplay *disp);
555
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900556__DRIbuffer *
557dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
558 unsigned int att, unsigned int format);
559
560void
561dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
562
Zhongmin Wue013ce82017-09-15 18:32:42 +0100563EGLBoolean
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000564dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
Paulo Zanoni04ecda32019-05-01 15:42:26 -0700565 _EGLConfig *conf, const EGLint *attrib_list,
566 EGLBoolean enable_out_fence, void *native_surface);
Zhongmin Wue013ce82017-09-15 18:32:42 +0100567
568void
569dri2_fini_surface(_EGLSurface *surf);
570
Emil Velikov2282ec02019-05-16 18:01:38 +0100571EGLBoolean
572dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
573 const __DRIconfig *config,
Mathias Fröhlicha7ecf782019-06-07 07:12:42 +0200574 struct dri2_egl_surface *dri2_surf,
575 void *loaderPrivate);
Emil Velikov2282ec02019-05-16 18:01:38 +0100576
Eric Engestrom2de9e842018-08-16 15:22:46 +0100577static inline uint64_t
578combine_u32_into_u64(uint32_t hi, uint32_t lo)
579{
580 return (((uint64_t) hi) << 32) | (((uint64_t) lo) & 0xffffffff);
581}
582
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500583#endif /* EGL_DRI2_INCLUDED */