Skip to content

Commit

Permalink
re-add termux support
Browse files Browse the repository at this point in the history
X11 patches
  • Loading branch information
SolDev69 committed Aug 29, 2024
1 parent 4d935b4 commit 164a94e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 74 deletions.
3 changes: 3 additions & 0 deletions src/egl/drivers/dri2/egl_dri2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,9 @@ dri2_setup_device(_EGLDisplay *disp, EGLBoolean software)
/* If we're not software, we need a DRM node FD */
assert(software || dri2_dpy->fd_render_gpu >= 0);

if (disp->Options.Kgsl)
software = true;

/* fd_render_gpu is what we got from WSI, so might actually be a lie and
* not a render node... */
if (software) {
Expand Down
5 changes: 5 additions & 0 deletions src/egl/drivers/dri2/platform_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ dri2_initialize_drm(_EGLDisplay *disp)

dri2_dpy->fd_display_gpu =
loader_open_device(drm->nodes[DRM_NODE_PRIMARY]);
} else if (disp->Options.Kgsl) {
dri2_dpy->fd_render_gpu = dri2_dpy->fd_display_gpu =
loader_open_device("/dev/kgsl-3d0");
} else {
char buf[64];
int n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, 0);
Expand All @@ -632,6 +635,8 @@ dri2_initialize_drm(_EGLDisplay *disp)
if (!dri2_dpy->gbm_dri->software) {
dri2_dpy->fd_render_gpu =
get_fd_render_gpu_drm(dri2_dpy->gbm_dri, dri2_dpy->fd_display_gpu);
if (dri2_dpy->fd_render_gpu < 0 && disp->Options.Kgsl)
dri2_dpy->fd_render_gpu = dri2_dpy->fd_display_gpu;
if (dri2_dpy->fd_render_gpu < 0) {
err = "DRI2: failed to get compatible render device";
goto cleanup;
Expand Down
15 changes: 15 additions & 0 deletions src/egl/drivers/dri2/platform_surfaceless.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ dri2_initialize_surfaceless(_EGLDisplay *disp)
driver_loaded = surfaceless_probe_device_sw(disp);
}


if (!driver_loaded && disp->Options.Kgsl) {
dri2_dpy->fd_render_gpu = loader_open_device("/dev/kgsl-3d0");
dri2_dpy->driver_name = strdup("kgsl");
driver_loaded = dri2_load_driver(disp);
if (driver_loaded) {
dri2_dpy->loader_extensions = image_loader_extensions;
} else {
free(dri2_dpy->driver_name);
dri2_dpy->driver_name = NULL;
close(dri2_dpy->fd_render_gpu);
dri2_dpy->fd_render_gpu = -1;
}
}

if (!driver_loaded) {
err = "DRI2: failed to load driver";
goto cleanup;
Expand Down
8 changes: 6 additions & 2 deletions src/egl/drivers/dri2/platform_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -2194,8 +2194,12 @@ dri2_initialize_wayland_drm(_EGLDisplay *disp)
if (roundtrip(dri2_dpy) < 0)
goto cleanup;

if (!dri2_initialize_wayland_drm_extensions(dri2_dpy))
goto cleanup;
if (!dri2_initialize_wayland_drm_extensions(dri2_dpy)) {
if (disp->Options.Kgsl)
dri2_dpy->fd_render_gpu = loader_open_device("/dev/kgsl-3d0");
else
goto cleanup;
}

loader_get_user_preferred_fd(&dri2_dpy->fd_render_gpu,
&dri2_dpy->fd_display_gpu);
Expand Down
1 change: 1 addition & 0 deletions src/egl/main/eglapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)

const char *env = getenv("MESA_LOADER_DRIVER_OVERRIDE");
disp->Options.Zink = env && !strcmp(env, "zink");
disp->Options.Kgsl = env && !strcmp(env, "kgsl");

const char *gallium_hud_env = getenv("GALLIUM_HUD");
disp->Options.GalliumHudWarn =
Expand Down
1 change: 1 addition & 0 deletions src/egl/main/egldisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct _egl_display {

/* options that affect how the driver initializes the display */
struct {
EGLBoolean Kgsl; /**< Use kgsl only */
EGLBoolean Zink; /**< Use kopper only */
EGLBoolean ForceSoftware; /**< Use software path only */
EGLBoolean GalliumHudWarn; /**< Using hud, warn when querying buffer age */
Expand Down
4 changes: 4 additions & 0 deletions src/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ loader_get_linux_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
bool
loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
{
const char *env = getenv("MESA_LOADER_DRIVER_OVERRIDE");
if (env && !strcmp(env, "kgsl"))
return false;

#ifdef __linux__
/* Implementation without causing full enumeration of DRM devices. */
if (loader_get_linux_pci_id_for_fd(fd, vendor_id, chip_id))
Expand Down
80 changes: 8 additions & 72 deletions src/loader/loader_dri3_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
#include <unistd.h>
#include <string.h>

#include <X11/xshmfence.h>
#include <xcb/xcb.h>
#include <xcb/dri3.h>
#include <xcb/present.h>
#include <xcb/xfixes.h>

#include <X11/Xlib-xcb.h>

#include "loader.h"
#include "loader_dri_helper.h"
#include "loader_dri3_helper.h"
#include "util/macros.h"
Expand Down Expand Up @@ -239,13 +238,11 @@ loader_dri3_blit_image(struct loader_dri3_drawable *draw,
static inline void
dri3_fence_reset(xcb_connection_t *c, struct loader_dri3_buffer *buffer)
{
xshmfence_reset(buffer->shm_fence);
}

static inline void
dri3_fence_set(struct loader_dri3_buffer *buffer)
{
xshmfence_trigger(buffer->shm_fence);
}

static inline void
Expand All @@ -259,7 +256,6 @@ dri3_fence_await(xcb_connection_t *c, struct loader_dri3_drawable *draw,
struct loader_dri3_buffer *buffer)
{
xcb_flush(c);
xshmfence_await(buffer->shm_fence);
if (draw) {
mtx_lock(&draw->mtx);
dri3_flush_present_events(draw);
Expand Down Expand Up @@ -335,8 +331,6 @@ dri3_free_render_buffer(struct loader_dri3_drawable *draw,

if (buffer->own_pixmap)
xcb_free_pixmap(draw->conn, buffer->pixmap);
xcb_sync_destroy_fence(draw->conn, buffer->sync_fence);
xshmfence_unmap_shm(buffer->shm_fence);
draw->ext->image->destroyImage(buffer->image);
if (buffer->linear_buffer)
draw->ext->image->destroyImage(buffer->linear_buffer);
Expand Down Expand Up @@ -1141,26 +1135,9 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw,
back->busy = 1;
back->last_swap = draw->send_sbc;

if (!draw->region) {
draw->region = xcb_generate_id(draw->conn);
xcb_xfixes_create_region(draw->conn, draw->region, 0, NULL);
}

xcb_xfixes_region_t region = 0;
xcb_rectangle_t xcb_rects[64];

if (n_rects > 0 && n_rects <= ARRAY_SIZE(xcb_rects)) {
for (int i = 0; i < n_rects; i++) {
const int *rect = &rects[i * 4];
xcb_rects[i].x = rect[0];
xcb_rects[i].y = draw->height - rect[1] - rect[3];
xcb_rects[i].width = rect[2];
xcb_rects[i].height = rect[3];
}

region = draw->region;
xcb_xfixes_set_region(draw->conn, region, n_rects, xcb_rects);
}

xcb_present_pixmap(draw->conn,
draw->drawable,
Expand Down Expand Up @@ -1291,6 +1268,11 @@ loader_dri3_open(xcb_connection_t *conn,
xcb_xfixes_query_version_reply_t *fixes_reply;
int fd;


const char *env = getenv("MESA_LOADER_DRIVER_OVERRIDE");
if (env && !strcmp(env, "kgsl"))
return loader_open_device("/dev/kgsl-3d0");

cookie = xcb_dri3_open(conn,
root,
provider);
Expand Down Expand Up @@ -1428,27 +1410,13 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
struct loader_dri3_buffer *buffer;
__DRIimage *pixmap_buffer = NULL, *linear_buffer_display_gpu = NULL;
xcb_pixmap_t pixmap;
xcb_sync_fence_t sync_fence;
struct xshmfence *shm_fence;
int buffer_fds[4], fence_fd;
int buffer_fds[4];
int num_planes = 0;
uint64_t *modifiers = NULL;
uint32_t count = 0;
int i, mod;
int ret;

/* Create an xshmfence object and
* prepare to send that to the X server
*/

fence_fd = xshmfence_alloc_shm();
if (fence_fd < 0)
return NULL;

shm_fence = xshmfence_map_shm(fence_fd);
if (shm_fence == NULL)
goto no_shm_fence;

/* Allocate the image from the driver
*/
buffer = calloc(1, sizeof *buffer);
Expand Down Expand Up @@ -1659,7 +1627,7 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
buffer->strides[2], buffer->offsets[2],
buffer->strides[3], buffer->offsets[3],
depth, buffer->cpp * 8,
buffer->modifier,
buffer->modifier ? buffer->modifier : 1274,
buffer_fds);
} else
#endif
Expand All @@ -1673,16 +1641,8 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
buffer_fds[0]);
}

xcb_dri3_fence_from_fd(draw->conn,
pixmap,
(sync_fence = xcb_generate_id(draw->conn)),
false,
fence_fd);

buffer->pixmap = pixmap;
buffer->own_pixmap = true;
buffer->sync_fence = sync_fence;
buffer->shm_fence = shm_fence;
buffer->width = width;
buffer->height = height;

Expand All @@ -1704,9 +1664,6 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
no_image:
free(buffer);
no_buffer:
xshmfence_unmap_shm(shm_fence);
no_shm_fence:
close(fence_fd);
return NULL;
}

Expand Down Expand Up @@ -1933,11 +1890,8 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
int buf_id = loader_dri3_pixmap_buf_id(buffer_type);
struct loader_dri3_buffer *buffer = draw->buffers[buf_id];
xcb_drawable_t pixmap;
xcb_sync_fence_t sync_fence;
struct xshmfence *shm_fence;
int width;
int height;
int fence_fd;
__DRIscreen *cur_screen;

if (buffer)
Expand All @@ -1949,14 +1903,6 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
if (!buffer)
goto no_buffer;

fence_fd = xshmfence_alloc_shm();
if (fence_fd < 0)
goto no_fence;
shm_fence = xshmfence_map_shm(fence_fd);
if (shm_fence == NULL) {
close (fence_fd);
goto no_fence;
}

/* Get the currently-bound screen or revert to using the drawable's screen if
* no contexts are currently bound. The latter case is at least necessary for
Expand All @@ -1967,11 +1913,6 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
cur_screen = draw->dri_screen_render_gpu;
}

xcb_dri3_fence_from_fd(draw->conn,
pixmap,
(sync_fence = xcb_generate_id(draw->conn)),
false,
fence_fd);
#ifdef HAVE_DRI3_MODIFIERS
if (draw->multiplanes_available &&
draw->ext->image->base.version >= 15 &&
Expand Down Expand Up @@ -2017,17 +1958,12 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
buffer->own_pixmap = false;
buffer->width = width;
buffer->height = height;
buffer->shm_fence = shm_fence;
buffer->sync_fence = sync_fence;

dri3_set_render_buffer(draw, buf_id, buffer);

return buffer;

no_image:
xcb_sync_destroy_fence(draw->conn, sync_fence);
xshmfence_unmap_shm(shm_fence);
no_fence:
free(buffer);
no_buffer:
return NULL;
Expand Down

0 comments on commit 164a94e

Please sign in to comment.