blob: d0e31138feb2c79a7118e838fc1dd9ff19fbe4b7 [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 Engestrom54fa5ec2019-02-02 11:38:45 +0000139 EGLBoolean (*copy_buffers)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace6d1f83e2014-01-07 14:54:51 -0800140 _EGLSurface *surf, void *native_pixmap_target);
Chad Versacebc2cbc02014-01-28 17:03:03 -0800141
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000142 EGLint (*query_buffer_age)(_EGLDriver *drv, _EGLDisplay *disp,
Chad Versace3fdfbd22014-01-28 17:03:03 -0800143 _EGLSurface *surf);
Chad Versaceeadd5e02014-01-28 17:03:03 -0800144
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000145 EGLBoolean (*query_surface)(_EGLDriver *drv, _EGLDisplay *disp,
Haixia Shia7c69932016-07-28 10:51:12 -0700146 _EGLSurface *surf, EGLint attribute,
147 EGLint *value);
148
Chad Versaceeadd5e02014-01-28 17:03:03 -0800149 struct wl_buffer* (*create_wayland_buffer_from_image)(
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000150 _EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img);
Sarah Sharpc524f3e2014-05-06 12:10:57 -0700151
152 EGLBoolean (*get_sync_values)(_EGLDisplay *display, _EGLSurface *surface,
153 EGLuint64KHR *ust, EGLuint64KHR *msc,
154 EGLuint64KHR *sbc);
Boyan Dinga25df542015-07-21 23:43:59 +0800155
156 __DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
Thomas Hellstrom2db95482017-08-10 15:35:39 +0200157
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000158 void (*close_screen_notify)(_EGLDisplay *disp);
Chad Versaceed7c6942018-04-30 22:35:17 -0700159
160 /* Used in EGL_KHR_mutable_render_buffer to update the native window's
161 * shared buffer mode.
162 */
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000163 bool (*set_shared_buffer_mode)(_EGLDisplay *disp, _EGLSurface *surf,
Chad Versaceed7c6942018-04-30 22:35:17 -0700164 bool mode);
Chad Versace90502b12014-01-28 11:41:46 -0800165};
166
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500167struct dri2_egl_display
168{
Chad Versace90502b12014-01-28 11:41:46 -0800169 const struct dri2_egl_display_vtbl *vtbl;
170
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500171 int dri2_major;
172 int dri2_minor;
173 __DRIscreen *dri_screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100174 bool own_dri_screen;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500175 const __DRIconfig **driver_configs;
176 void *driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000177 const __DRIcoreExtension *core;
Boyan Dingf35198b2015-07-21 23:44:00 +0800178 const __DRIimageDriverExtension *image_driver;
Emil Velikov5f280d02014-02-12 20:13:15 +0000179 const __DRIdri2Extension *dri2;
180 const __DRIswrastExtension *swrast;
181 const __DRI2flushExtension *flush;
Adam Jacksonc0be3aa2016-09-22 03:47:55 -0400182 const __DRI2flushControlExtension *flush_control;
Emil Velikov5f280d02014-02-12 20:13:15 +0000183 const __DRItexBufferExtension *tex_buffer;
184 const __DRIimageExtension *image;
185 const __DRIrobustnessExtension *robustness;
Grigori Goronzy49095192017-06-29 02:44:03 +0200186 const __DRInoErrorExtension *no_error;
Emil Velikov5f280d02014-02-12 20:13:15 +0000187 const __DRI2configQueryExtension *config;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200188 const __DRI2fenceExtension *fence;
Harish Krupoa4a8ebe2019-08-12 12:07:06 +0200189 const __DRI2bufferDamageExtension *buffer_damage;
Tapani Pälli6f5b5702017-12-28 10:51:11 +0200190 const __DRI2blobExtension *blob;
Marek Olšák4f57ccd2015-06-10 14:45:58 +0200191 const __DRI2rendererQueryExtension *rendererQuery;
Marek Olšákb6eda702016-03-03 15:59:48 +0100192 const __DRI2interopExtension *interop;
Veluri Mithun85edfc02019-01-23 22:45:42 +0530193 const __DRIconfigOptionsExtension *configOptions;
Chad Versaceed7c6942018-04-30 22:35:17 -0700194 const __DRImutableRenderBufferDriverExtension *mutable_render_buffer;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500195 int fd;
196
Nicolas Boichat9ee683f2016-07-22 11:27:41 +0800197 /* dri2_initialize/dri2_terminate increment/decrement this count, so does
198 * dri2_make_current (tracks if there are active contexts/surfaces). */
199 int ref_count;
200
Eric Engestrom60f98422017-06-19 00:16:21 +0100201 bool own_device;
202 bool invalidate_available;
Eric Anholt7e9bd2b2012-09-25 14:05:30 -0700203 int min_swap_interval;
204 int max_swap_interval;
205 int default_swap_interval;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200206#ifdef HAVE_DRM_PLATFORM
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200207 struct gbm_dri_device *gbm_dri;
Benjamin Franzkeb2d63752011-07-02 13:41:35 +0200208#endif
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200209
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500210 char *driver_name;
211
Emil Velikovf8719462016-08-24 23:32:27 +0100212 const __DRIextension **loader_extensions;
Eric Anholtf93533d2013-09-27 11:39:25 -0700213 const __DRIextension **driver_extensions;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400214
215#ifdef HAVE_X11_PLATFORM
216 xcb_connection_t *conn;
Emil Velikov7c6babb2016-11-21 13:46:51 +0000217 xcb_screen_t *screen;
Eric Engestrom60f98422017-06-19 00:16:21 +0100218 bool swap_available;
Boyan Dingf35198b2015-07-21 23:44:00 +0800219#ifdef HAVE_DRI3
Louis-Francis Ratté-Boulianne069fdd52017-07-07 02:54:26 -0400220 bool multibuffers_available;
221 int dri3_major_version;
222 int dri3_minor_version;
Louis-Francis Ratté-Boulianne3160cb82017-10-06 01:26:51 -0400223 int present_major_version;
224 int present_minor_version;
Boyan Dingf35198b2015-07-21 23:44:00 +0800225 struct loader_dri3_extensions loader_dri3_ext;
226#endif
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400227#endif
228
Benjamin Franzke93aea842011-02-04 12:39:40 +0100229#ifdef HAVE_WAYLAND_PLATFORM
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400230 struct wl_display *wl_dpy;
Jonas Ådahl36b99762017-01-13 23:05:10 +0800231 struct wl_display *wl_dpy_wrapper;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400232 struct wl_registry *wl_registry;
Benjamin Franzke6b369c42011-02-21 16:22:34 +0100233 struct wl_drm *wl_server_drm;
Kristian Høgsbergc0f8c992011-04-14 10:42:41 -0400234 struct wl_drm *wl_drm;
Axel Davycdcfe482015-05-01 11:11:20 +0200235 struct wl_shm *wl_shm;
Kristian Høgsberg0229e3a2012-10-10 22:10:42 -0400236 struct wl_event_queue *wl_queue;
Daniel Stone02cc3592017-06-16 18:01:23 +0100237 struct zwp_linux_dmabuf_v1 *wl_dmabuf;
Daniel Stone47320942018-02-06 10:29:13 +0000238 struct u_vector *wl_modifiers;
Eric Engestrom60f98422017-06-19 00:16:21 +0100239 bool authenticated;
Eric Engestromfbf7c382018-11-27 12:27:45 +0000240 BITSET_DECLARE(formats, EGL_DRI2_MAX_FORMATS);
Kristian Høgsbergde315f72013-02-02 12:26:12 -0500241 uint32_t capabilities;
Frank Binnsd6f669b2016-06-17 18:41:22 +0100242 char *device_name;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100243#endif
Boyan Dingf35198b2015-07-21 23:44:00 +0800244
Tomasz Figa859d0b02016-11-10 16:55:52 +0900245#ifdef HAVE_ANDROID_PLATFORM
246 const gralloc_module_t *gralloc;
247#endif
248
Eric Engestrom60f98422017-06-19 00:16:21 +0100249 bool is_render_node;
Eric Engestrom4a1238a2017-06-19 00:16:51 +0100250 bool is_different_gpu;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500251};
252
253struct dri2_egl_context
254{
255 _EGLContext base;
256 __DRIcontext *dri_context;
257};
258
Benjamin Franzke93aea842011-02-04 12:39:40 +0100259#ifdef HAVE_WAYLAND_PLATFORM
260enum wayland_buffer_type {
261 WL_BUFFER_FRONT,
262 WL_BUFFER_BACK,
Benjamin Franzke0cb356d2011-05-06 19:13:29 +0200263 WL_BUFFER_THIRD,
Benjamin Franzke93aea842011-02-04 12:39:40 +0100264 WL_BUFFER_COUNT
265};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100266#endif
267
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500268struct dri2_egl_surface
269{
270 _EGLSurface base;
271 __DRIdrawable *dri_drawable;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500272 __DRIbuffer buffers[5];
Eric Engestrom60f98422017-06-19 00:16:21 +0100273 bool have_fake_front;
Haitao Fengf55d0272011-02-16 23:05:15 -0500274
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400275#ifdef HAVE_X11_PLATFORM
276 xcb_drawable_t drawable;
277 xcb_xfixes_region_t region;
Haitao Fengf55d0272011-02-16 23:05:15 -0500278 int depth;
279 int bytes_per_pixel;
280 xcb_gcontext_t gc;
281 xcb_gcontext_t swapgc;
Kristian Høgsberg93aea632011-05-11 13:58:37 -0400282#endif
Haitao Fengf55d0272011-02-16 23:05:15 -0500283
Benjamin Franzke93aea842011-02-04 12:39:40 +0100284#ifdef HAVE_WAYLAND_PLATFORM
285 struct wl_egl_window *wl_win;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100286 int dx;
287 int dy;
Daniel Stone03dd9a82017-05-05 14:49:09 +0100288 struct wl_event_queue *wl_queue;
289 struct wl_surface *wl_surface_wrapper;
290 struct wl_display *wl_dpy_wrapper;
291 struct wl_drm *wl_drm_wrapper;
Neil Roberts992a2db2013-11-15 13:50:50 +0000292 struct wl_callback *throttle_callback;
Emil Velikovebc68e32016-08-25 00:12:13 +0100293 int format;
Benjamin Franzke93aea842011-02-04 12:39:40 +0100294#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900295
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200296#ifdef HAVE_DRM_PLATFORM
297 struct gbm_dri_surface *gbm_surf;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200298#endif
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500299
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900300 /* EGL-owned buffers */
301 __DRIbuffer *local_buffers[__DRI_BUFFER_COUNT];
302
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500303#if defined(HAVE_WAYLAND_PLATFORM) || defined(HAVE_DRM_PLATFORM)
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500304 struct {
305#ifdef HAVE_WAYLAND_PLATFORM
306 struct wl_buffer *wl_buffer;
Juan A. Suarez Romero54a96222018-08-30 10:14:49 +0200307 bool wl_release;
Kristian Høgsberg664fe6d2013-02-02 07:40:51 -0500308 __DRIimage *dri_image;
Axel Davy4cd546d2015-05-01 01:16:24 +0200309 /* for is_different_gpu case. NULL else */
310 __DRIimage *linear_copy;
Axel Davycdcfe482015-05-01 11:11:20 +0200311 /* for swrast */
312 void *data;
313 int data_size;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500314#endif
315#ifdef HAVE_DRM_PLATFORM
316 struct gbm_bo *bo;
317#endif
Eric Engestrom60f98422017-06-19 00:16:21 +0100318 bool locked;
Kristian Høgsberg90804e82012-12-13 23:30:45 -0500319 int age;
Neil Roberts992a2db2013-11-15 13:50:50 +0000320 } color_buffers[4], *back, *current;
Ander Conselvan de Oliveira4a976b62012-01-25 16:24:17 +0200321#endif
322
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900323#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu75cc24c2011-11-25 11:59:02 +0800324 struct ANativeWindow *window;
325 struct ANativeWindowBuffer *buffer;
Liu Zhiquanb6637532016-11-16 10:11:28 +0800326 __DRIimage *dri_image_back;
327 __DRIimage *dri_image_front;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900328
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800329 /* Used to record all the buffers created by ANativeWindow and their ages.
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700330 * Allocate number of color_buffers based on query to android bufferqueue
331 * and save color_buffers_count.
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800332 */
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700333 int color_buffers_count;
Xiaosong Wei2acc69d2017-02-08 10:46:02 +0800334 struct {
335 struct ANativeWindowBuffer *buffer;
336 int age;
Nataraj Deshpande0661c352019-07-19 08:44:13 -0700337 } *color_buffers, *back;
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900338#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500339
Emil Velikovd6edcce2019-05-16 18:01:40 +0100340 /* surfaceless and device */
341 __DRIimage *front;
342 unsigned int visual;
343
Zhongmin Wue013ce82017-09-15 18:32:42 +0100344 int out_fence_fd;
345 EGLBoolean enable_out_fence;
Mathias Fröhlichc7617d82019-12-13 17:09:56 +0100346
347 /* swrast device */
348 char *swrast_device_buffer;
Gurchetan Singh63c5d5c2016-05-16 16:34:07 -0700349};
Benjamin Franzke93aea842011-02-04 12:39:40 +0100350
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500351struct dri2_egl_config
352{
353 _EGLConfig base;
Eric Engestromb81cfc72017-06-21 10:40:31 +0100354 const __DRIconfig *dri_config[2][2];
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500355};
356
357struct dri2_egl_image
358{
359 _EGLImage base;
360 __DRIimage *dri_image;
361};
362
Marek Olšák9a0bda22015-04-10 10:56:02 +0200363struct dri2_egl_sync {
364 _EGLSync base;
Dongwon Kim70299472016-04-04 17:14:10 -0700365 mtx_t mutex;
366 cnd_t cond;
Marek Olšák9a0bda22015-04-10 10:56:02 +0200367 int refcount;
368 void *fence;
369};
370
Eric Engestrom04e8eaf2020-06-12 11:42:32 +0200371/* From driconf.h, user exposed so should be stable */
Neil Roberts992a2db2013-11-15 13:50:50 +0000372#define DRI_CONF_VBLANK_NEVER 0
373#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
374#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
375#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
376
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500377/* standard typecasts */
378_EGL_DRIVER_STANDARD_TYPECASTS(dri2_egl)
379_EGL_DRIVER_TYPECAST(dri2_egl_image, _EGLImage, obj)
Marek Olšák9a0bda22015-04-10 10:56:02 +0200380_EGL_DRIVER_TYPECAST(dri2_egl_sync, _EGLSync, obj)
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500381
382extern const __DRIimageLookupExtension image_lookup_extension;
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500383extern const __DRIuseInvalidateExtension use_invalidate;
Eric Anholt3b7b6ad2012-12-27 17:39:37 -0800384extern const __DRIbackgroundCallableExtension background_callable_extension;
Eric Anholt6a8d39dc2019-07-23 13:18:21 -0700385extern const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension;
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500386
387EGLBoolean
388dri2_load_driver(_EGLDisplay *disp);
389
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200390/* Helper for platforms not using dri2_create_screen */
391void
392dri2_setup_screen(_EGLDisplay *disp);
393
Emil Velikov47b06f52017-08-05 00:25:46 +0100394void
395dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval);
396
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500397EGLBoolean
Chia-I Wucf69eea2011-06-08 16:33:55 +0800398dri2_load_driver_swrast(_EGLDisplay *disp);
399
400EGLBoolean
Boyan Dingf35198b2015-07-21 23:44:00 +0800401dri2_load_driver_dri3(_EGLDisplay *disp);
402
403EGLBoolean
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500404dri2_create_screen(_EGLDisplay *disp);
405
Emil Velikov2c341f22017-05-11 16:20:04 +0100406EGLBoolean
407dri2_setup_extensions(_EGLDisplay *disp);
408
Boyan Dinga25df542015-07-21 23:43:59 +0800409__DRIdrawable *
410dri2_surface_get_dri_drawable(_EGLSurface *surf);
411
Benjamin Franzkee5fc4c82011-05-30 10:50:52 +0200412__DRIimage *
413dri2_lookup_egl_image(__DRIscreen *screen, void *image, void *data);
414
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800415void
416dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
417 const __DRIconfig *config, int *shifts,
418 unsigned int *sizes);
419
Kevin Strasser482ed432019-01-24 16:55:33 -0800420void
421dri2_get_render_type_float(const __DRIcoreExtension *core,
422 const __DRIconfig *config,
423 bool *is_float);
424
Mathias Fröhlichd32c4582020-02-09 19:01:53 +0100425unsigned int
426dri2_image_format_for_pbuffer_config(struct dri2_egl_display *dri2_dpy,
427 const __DRIconfig *config);
428
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500429struct dri2_egl_config *
430dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
Emil Velikovebc68e32016-08-25 00:12:13 +0100431 EGLint surface_type, const EGLint *attr_list,
Kevin Strasser7b4ed2b2019-01-24 16:32:48 -0800432 const int *rgba_shifts, const unsigned int *rgba_sizes);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500433
Mathias Fröhlichf280c002020-02-16 11:13:43 +0100434EGLBoolean
435dri2_add_pbuffer_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp);
436
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500437_EGLImage *
438dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
Emil Velikovebc68e32016-08-25 00:12:13 +0100439 _EGLContext *ctx, EGLenum target,
440 EGLClientBuffer buffer, const EGLint *attr_list);
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500441
Emil Velikov38ef6f52016-05-01 12:42:53 +0100442_EGLImage *
443dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
Emil Velikovebc68e32016-08-25 00:12:13 +0100444 EGLClientBuffer buffer, const EGLint *attr_list);
Emil Velikov38ef6f52016-05-01 12:42:53 +0100445
Emil Velikov55245fe2017-11-09 17:55:19 +0000446#ifdef HAVE_X11_PLATFORM
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500447EGLBoolean
448dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov938fcab2017-11-09 18:58:52 +0000449void
450dri2_teardown_x11(struct dri2_egl_display *dri2_dpy);
Mario Kleiner61a02722018-06-13 06:04:13 +0200451unsigned int
452dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth);
Emil Velikov55245fe2017-11-09 17:55:19 +0000453#else
454static inline EGLBoolean
455dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp)
456{
457 return _eglError(EGL_NOT_INITIALIZED, "X11 platform not built");
458}
Emil Velikov938fcab2017-11-09 18:58:52 +0000459static inline void
460dri2_teardown_x11(struct dri2_egl_display *dri2_dpy) {}
Mario Kleiner61a02722018-06-13 06:04:13 +0200461static inline unsigned int
462dri2_x11_get_red_mask_for_depth(struct dri2_egl_display *dri2_dpy, int depth)
463{
464 return 0;
465}
Emil Velikov55245fe2017-11-09 17:55:19 +0000466#endif
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500467
Emil Velikov55245fe2017-11-09 17:55:19 +0000468#ifdef HAVE_DRM_PLATFORM
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500469EGLBoolean
470dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov40a01c92017-11-09 19:04:25 +0000471void
472dri2_teardown_drm(struct dri2_egl_display *dri2_dpy);
Emil Velikov55245fe2017-11-09 17:55:19 +0000473#else
474static inline EGLBoolean
475dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
476{
477 return _eglError(EGL_NOT_INITIALIZED, "GBM/DRM platform not built");
478}
Emil Velikov40a01c92017-11-09 19:04:25 +0000479static inline void
480dri2_teardown_drm(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000481#endif
Kristian Høgsberg9dc5de52011-02-02 22:21:13 -0500482
Emil Velikov55245fe2017-11-09 17:55:19 +0000483#ifdef HAVE_WAYLAND_PLATFORM
Benjamin Franzke93aea842011-02-04 12:39:40 +0100484EGLBoolean
485dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov8d745ab2017-11-09 19:13:09 +0000486void
487dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy);
Mario Kleiner820dfce2018-06-13 06:04:15 +0200488bool
489dri2_wl_is_format_supported(void* user_data, uint32_t format);
Emil Velikov55245fe2017-11-09 17:55:19 +0000490#else
491static inline EGLBoolean
492dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
493{
494 return _eglError(EGL_NOT_INITIALIZED, "Wayland platform not built");
495}
Emil Velikov8d745ab2017-11-09 19:13:09 +0000496static inline void
497dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy) {}
Emil Velikov55245fe2017-11-09 17:55:19 +0000498#endif
Benjamin Franzke93aea842011-02-04 12:39:40 +0100499
Emil Velikov55245fe2017-11-09 17:55:19 +0000500#ifdef HAVE_ANDROID_PLATFORM
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900501EGLBoolean
502dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
Emil Velikov55245fe2017-11-09 17:55:19 +0000503#else
504static inline EGLBoolean
505dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp)
506{
507 return _eglError(EGL_NOT_INITIALIZED, "Android platform not built");
508}
509#endif
Chia-I Wu9779f6f2011-08-05 14:39:18 +0900510
Haixia Shi6b8accb2015-06-12 10:10:58 -0700511EGLBoolean
512dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp);
513
Emil Velikovd6edcce2019-05-16 18:01:40 +0100514EGLBoolean
515dri2_initialize_device(_EGLDriver *drv, _EGLDisplay *disp);
516static inline void
517dri2_teardown_device(struct dri2_egl_display *dri2_dpy) { /* noop */ }
518
Eric Anholt70e8ccc2014-12-21 11:51:33 -0800519void
520dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
521
Marek Olšákc2c2e9a2015-06-10 02:49:29 +0200522const __DRIconfig *
523dri2_get_dri_config(struct dri2_egl_config *conf, EGLint surface_type,
524 EGLenum colorspace);
525
Emil Velikov98f5d012016-08-25 13:15:43 +0100526static inline void
527dri2_set_WL_bind_wayland_display(_EGLDriver *drv, _EGLDisplay *disp)
528{
529#ifdef HAVE_WAYLAND_PLATFORM
530 struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
531
532 (void) drv;
533
534 if (dri2_dpy->device_name && dri2_dpy->image) {
535 if (dri2_dpy->image->base.version >= 10 &&
536 dri2_dpy->image->getCapabilities != NULL) {
537 int capabilities;
538
539 capabilities =
540 dri2_dpy->image->getCapabilities(dri2_dpy->dri_screen);
541 disp->Extensions.WL_bind_wayland_display =
542 (capabilities & __DRI_IMAGE_CAP_GLOBAL_NAMES) != 0;
543 } else {
544 disp->Extensions.WL_bind_wayland_display = EGL_TRUE;
545 }
546 }
547#endif
548}
549
Emil Velikov3e73c022017-05-11 17:13:33 +0100550void
551dri2_display_destroy(_EGLDisplay *disp);
552
Gwan-gyeong Mun640b6e62017-08-05 00:16:11 +0900553__DRIbuffer *
554dri2_egl_surface_alloc_local_buffer(struct dri2_egl_surface *dri2_surf,
555 unsigned int att, unsigned int format);
556
557void
558dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
559
Zhongmin Wue013ce82017-09-15 18:32:42 +0100560EGLBoolean
Eric Engestrom54fa5ec2019-02-02 11:38:45 +0000561dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
Paulo Zanoni04ecda32019-05-01 15:42:26 -0700562 _EGLConfig *conf, const EGLint *attrib_list,
563 EGLBoolean enable_out_fence, void *native_surface);
Zhongmin Wue013ce82017-09-15 18:32:42 +0100564
565void
566dri2_fini_surface(_EGLSurface *surf);
567
Emil Velikov2282ec02019-05-16 18:01:38 +0100568EGLBoolean
569dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
570 const __DRIconfig *config,
Mathias Fröhlicha7ecf782019-06-07 07:12:42 +0200571 struct dri2_egl_surface *dri2_surf,
572 void *loaderPrivate);
Emil Velikov2282ec02019-05-16 18:01:38 +0100573
Eric Engestrom2de9e842018-08-16 15:22:46 +0100574static inline uint64_t
575combine_u32_into_u64(uint32_t hi, uint32_t lo)
576{
577 return (((uint64_t) hi) << 32) | (((uint64_t) lo) & 0xffffffff);
578}
579
Kristian Høgsberg2889d962011-02-02 22:10:40 -0500580#endif /* EGL_DRI2_INCLUDED */