frontend/dri: move callbacks from the VTable into dri_screen, dri_drawable

This just moves the callbacks and renames the functions.
Some functions had to be moved up because they are initialized there.
Remove some obsolete comments.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19741>
This commit is contained in:
Marek Olšák 2022-11-15 16:13:49 -05:00 committed by Marge Bot
parent f34d607d2f
commit 7d5b1cd02c
8 changed files with 96 additions and 115 deletions

View file

@ -2275,6 +2275,23 @@ dri2_init_screen_extensions(struct dri_screen *screen,
assert(!*nExt); assert(!*nExt);
} }
static struct dri_drawable *
dri2_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
boolean isPixmap, void *loaderPrivate)
{
struct dri_drawable *drawable = dri_create_drawable(screen, visual, isPixmap,
loaderPrivate);
if (!drawable)
return NULL;
drawable->allocate_textures = dri2_allocate_textures;
drawable->flush_frontbuffer = dri2_flush_frontbuffer;
drawable->update_tex_buffer = dri2_update_tex_buffer;
drawable->flush_swapbuffers = dri2_flush_swapbuffers;
return drawable;
}
/** /**
* This is the driver specific part of the createNewScreen entry point. * This is the driver specific part of the createNewScreen entry point.
* *
@ -2320,6 +2337,10 @@ dri2_init_screen(struct dri_screen *screen)
screen->lookup_egl_image_validated = dri2_lookup_egl_image_validated; screen->lookup_egl_image_validated = dri2_lookup_egl_image_validated;
} }
screen->create_drawable = dri2_create_drawable;
screen->allocate_buffer = dri2_allocate_buffer;
screen->release_buffer = dri2_release_buffer;
return configs; return configs;
destroy_screen: destroy_screen:
@ -2386,35 +2407,14 @@ release_pipe:
return NULL; return NULL;
} }
static struct dri_drawable *
dri2_create_buffer(struct dri_screen *screen, const struct gl_config *visual,
boolean isPixmap, void *loaderPrivate)
{
struct dri_drawable *drawable = dri_create_buffer(screen, visual, isPixmap,
loaderPrivate);
if (!drawable)
return NULL;
drawable->allocate_textures = dri2_allocate_textures;
drawable->flush_frontbuffer = dri2_flush_frontbuffer;
drawable->update_tex_buffer = dri2_update_tex_buffer;
drawable->flush_swapbuffers = dri2_flush_swapbuffers;
return drawable;
}
/** /**
* DRI driver virtual function table. * DRI driver virtual function table.
* *
* DRI versions differ in their implementation of init_screen and swap_buffers. * DRI versions differ in their implementation of init_screen and swap_buffers.
*/ */
static const struct __DRIDriverVtableExtensionRec galliumdrm_vtable = { static const struct __DRIBackendVtableExtensionRec galliumdrm_vtable = {
.base = { __DRI_DRIVER_VTABLE, 1 }, .base = { __DRI_BACKEND_VTABLE, 1 },
.InitScreen = dri2_init_screen, .InitScreen = dri2_init_screen,
.CreateBuffer = dri2_create_buffer,
.AllocateBuffer = dri2_allocate_buffer,
.ReleaseBuffer = dri2_release_buffer,
}; };
/* This is the table of extensions that the loader will dlsym() for. */ /* This is the table of extensions that the loader will dlsym() for. */
@ -2434,13 +2434,9 @@ const __DRIextension *galliumdrm_driver_extensions[] = {
* hook. The latter is used to explicitly initialise the kms_swrast driver * hook. The latter is used to explicitly initialise the kms_swrast driver
* rather than selecting the approapriate driver as suggested by the loader. * rather than selecting the approapriate driver as suggested by the loader.
*/ */
static const struct __DRIDriverVtableExtensionRec dri_swrast_kms_vtable = { static const struct __DRIBackendVtableExtensionRec dri_swrast_kms_vtable = {
.base = { __DRI_DRIVER_VTABLE, 1 }, .base = { __DRI_BACKEND_VTABLE, 1 },
.InitScreen = dri_swrast_kms_init_screen, .InitScreen = dri_swrast_kms_init_screen,
.CreateBuffer = dri2_create_buffer,
.AllocateBuffer = dri2_allocate_buffer,
.ReleaseBuffer = dri2_release_buffer,
}; };
const __DRIextension *dri_swrast_kms_driver_extensions[] = { const __DRIextension *dri_swrast_kms_driver_extensions[] = {

View file

@ -143,8 +143,8 @@ dri_st_framebuffer_flush_swapbuffers(struct st_context_iface *stctx,
* This is called when we need to set up GL rendering to a new X window. * This is called when we need to set up GL rendering to a new X window.
*/ */
struct dri_drawable * struct dri_drawable *
dri_create_buffer(struct dri_screen *screen, const struct gl_config *visual, dri_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
bool isPixmap, void *loaderPrivate) bool isPixmap, void *loaderPrivate)
{ {
struct dri_drawable *drawable = NULL; struct dri_drawable *drawable = NULL;
@ -184,7 +184,7 @@ fail:
} }
static void static void
dri_destroy_buffer(struct dri_drawable *drawable) dri_destroy_drawable(struct dri_drawable *drawable)
{ {
struct dri_screen *screen = drawable->screen; struct dri_screen *screen = drawable->screen;
int i; int i;
@ -212,7 +212,7 @@ dri_put_drawable(struct dri_drawable *drawable)
if (drawable->refcount) if (drawable->refcount)
return; return;
dri_destroy_buffer(drawable); dri_destroy_drawable(drawable);
} }
} }

View file

@ -112,6 +112,8 @@ struct dri_drawable
struct pipe_resource *res); struct pipe_resource *res);
void (*flush_swapbuffers)(struct dri_context *ctx, void (*flush_swapbuffers)(struct dri_context *ctx,
struct dri_drawable *drawable); struct dri_drawable *drawable);
void (*swap_buffers)(struct dri_drawable *drawable);
}; };
/* Typecast the opaque pointer to our own type. */ /* Typecast the opaque pointer to our own type. */
@ -138,8 +140,8 @@ dri_get_drawable(struct dri_drawable *drawable)
* dri_drawable.c * dri_drawable.c
*/ */
struct dri_drawable * struct dri_drawable *
dri_create_buffer(struct dri_screen *screen, const struct gl_config *visual, dri_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
bool isPixmap, void *loaderPrivate); bool isPixmap, void *loaderPrivate);
void void
dri_put_drawable(struct dri_drawable *drawable); dri_put_drawable(struct dri_drawable *drawable);

View file

@ -53,9 +53,6 @@ struct dri_screen
struct st_manager base; struct st_manager base;
/* dri */ /* dri */
/* Backend-specific entrypoints (dri, swrast, kopper) */
const struct __DRIDriverVtableExtensionRec *driver;
/* Current screen's number */ /* Current screen's number */
int myNum; int myNum;
@ -140,6 +137,18 @@ struct dri_screen
bool has_dmabuf; bool has_dmabuf;
bool has_modifiers; bool has_modifiers;
bool is_sw; bool is_sw;
struct dri_drawable *(*create_drawable)(struct dri_screen *screen,
const struct gl_config *glVis,
GLboolean pixmapBuffer,
void *loaderPrivate);
__DRIbuffer *(*allocate_buffer)(struct dri_screen *screen,
unsigned int attachment,
unsigned int format,
int width, int height);
void (*release_buffer)(__DRIbuffer *buffer);
}; };
/** cast wrapper */ /** cast wrapper */

View file

@ -110,6 +110,7 @@ driCreateNewScreen2(int scrn, int fd,
{ {
static const __DRIextension *emptyExtensionList[] = { NULL }; static const __DRIextension *emptyExtensionList[] = { NULL };
struct dri_screen *screen; struct dri_screen *screen;
const struct __DRIBackendVtableExtensionRec *backend = NULL;
screen = CALLOC_STRUCT(dri_screen); screen = CALLOC_STRUCT(dri_screen);
if (!screen) if (!screen)
@ -117,9 +118,8 @@ driCreateNewScreen2(int scrn, int fd,
assert(driver_extensions); assert(driver_extensions);
for (int i = 0; driver_extensions[i]; i++) { for (int i = 0; driver_extensions[i]; i++) {
if (strcmp(driver_extensions[i]->name, __DRI_DRIVER_VTABLE) == 0) { if (strcmp(driver_extensions[i]->name, __DRI_BACKEND_VTABLE) == 0) {
screen->driver = backend = (__DRIBackendVtableExtension *)driver_extensions[i];
(__DRIDriverVtableExtension *)driver_extensions[i];
} }
} }
@ -142,7 +142,7 @@ driCreateNewScreen2(int scrn, int fd,
driParseConfigFiles(&screen->optionCache, &screen->optionInfo, screen->myNum, driParseConfigFiles(&screen->optionCache, &screen->optionInfo, screen->myNum,
"dri2", NULL, NULL, NULL, 0, NULL, 0); "dri2", NULL, NULL, NULL, 0, NULL, 0);
*driver_configs = screen->driver->InitScreen(screen); *driver_configs = backend->InitScreen(screen);
if (*driver_configs == NULL) { if (*driver_configs == NULL) {
free(screen); free(screen);
return NULL; return NULL;
@ -745,7 +745,7 @@ driCreateNewDrawable(__DRIscreen *psp,
struct dri_screen *screen = dri_screen(psp); struct dri_screen *screen = dri_screen(psp);
struct dri_drawable *drawable = struct dri_drawable *drawable =
screen->driver->CreateBuffer(screen, &config->modes, GL_FALSE, data); screen->create_drawable(screen, &config->modes, GL_FALSE, data);
return opaque_dri_drawable(drawable); return opaque_dri_drawable(drawable);
} }
@ -763,8 +763,7 @@ dri2AllocateBuffer(__DRIscreen *psp,
{ {
struct dri_screen *screen = dri_screen(psp); struct dri_screen *screen = dri_screen(psp);
return screen->driver->AllocateBuffer(screen, attachment, format, return screen->allocate_buffer(screen, attachment, format, width, height);
width, height);
} }
static void static void
@ -772,7 +771,7 @@ dri2ReleaseBuffer(__DRIscreen *psp, __DRIbuffer *buffer)
{ {
struct dri_screen *screen = dri_screen(psp); struct dri_screen *screen = dri_screen(psp);
screen->driver->ReleaseBuffer(buffer); screen->release_buffer(buffer);
} }
@ -848,7 +847,7 @@ driSwapBuffers(__DRIdrawable *pdp)
assert(drawable->screen->swrast_loader); assert(drawable->screen->swrast_loader);
drawable->screen->driver->SwapBuffers(drawable); drawable->swap_buffers(drawable);
} }
/** Core interface */ /** Core interface */

View file

@ -27,29 +27,10 @@
* \file dri_util.h * \file dri_util.h
* DRI utility functions definitions. * DRI utility functions definitions.
* *
* This module acts as glue between GLX and the actual hardware driver. A DRI
* driver doesn't really \e have to use any of this - it's optional. But, some
* useful stuff is done here that otherwise would have to be duplicated in most
* drivers.
*
* Basically, these utility functions take care of some of the dirty details of
* screen initialization, context creation, context binding, DRM setup, etc.
*
* These functions are compiled into each DRI driver so libGL.so knows nothing
* about them.
*
* \sa dri_util.c.
*
* \author Kevin E. Martin <kevin@precisioninsight.com> * \author Kevin E. Martin <kevin@precisioninsight.com>
* \author Brian Paul <brian@precisioninsight.com> * \author Brian Paul <brian@precisioninsight.com>
*/ */
/**
* The following structs are shared between DRISW and DRI2, the DRISW structs
* are essentially base classes of the DRI2 structs. DRISW needs to compile on
* platforms without DRM, so keep the structs opaque to DRM.
*/
#ifndef _DRI_UTIL_H_ #ifndef _DRI_UTIL_H_
#define _DRI_UTIL_H_ #define _DRI_UTIL_H_
@ -62,29 +43,14 @@
#include "util/xmlconfig.h" #include "util/xmlconfig.h"
#include <stdbool.h> #include <stdbool.h>
#define __DRI_DRIVER_VTABLE "DRI_DriverVtable"
struct dri_screen; struct dri_screen;
typedef struct __DRIDriverVtableExtensionRec { #define __DRI_BACKEND_VTABLE "DRI_DriverVtable"
typedef struct __DRIBackendVtableExtensionRec {
__DRIextension base; __DRIextension base;
const __DRIconfig **(*InitScreen)(struct dri_screen *screen); const __DRIconfig **(*InitScreen)(struct dri_screen *screen);
} __DRIBackendVtableExtension;
struct dri_drawable *(*CreateBuffer)(struct dri_screen *screen,
const struct gl_config *glVis,
GLboolean pixmapBuffer,
void *loaderPrivate);
void (*SwapBuffers)(struct dri_drawable *drawable);
__DRIbuffer *(*AllocateBuffer)(struct dri_screen *screen,
unsigned int attachment,
unsigned int format,
int width, int height);
void (*ReleaseBuffer)(__DRIbuffer *buffer);
} __DRIDriverVtableExtension;
struct __DRIconfigRec { struct __DRIconfigRec {
struct gl_config modes; struct gl_config modes;

View file

@ -523,6 +523,24 @@ static const struct drisw_loader_funcs drisw_shm_lf = {
.put_image_shm = drisw_put_image_shm .put_image_shm = drisw_put_image_shm
}; };
static struct dri_drawable *
drisw_create_drawable(struct dri_screen *screen, const struct gl_config * visual,
boolean isPixmap, void *loaderPrivate)
{
struct dri_drawable *drawable = dri_create_drawable(screen, visual, isPixmap,
loaderPrivate);
if (!drawable)
return NULL;
drawable->allocate_textures = drisw_allocate_textures;
drawable->update_drawable_info = drisw_update_drawable_info;
drawable->flush_frontbuffer = drisw_flush_frontbuffer;
drawable->update_tex_buffer = drisw_update_tex_buffer;
drawable->swap_buffers = drisw_swap_buffers;
return drawable;
}
static const __DRIconfig ** static const __DRIconfig **
drisw_init_screen(struct dri_screen *screen) drisw_init_screen(struct dri_screen *screen)
{ {
@ -574,6 +592,8 @@ drisw_init_screen(struct dri_screen *screen)
screen->lookup_egl_image_validated = dri2_lookup_egl_image_validated; screen->lookup_egl_image_validated = dri2_lookup_egl_image_validated;
} }
screen->create_drawable = drisw_create_drawable;
return configs; return configs;
fail: fail:
dri_destroy_screen_helper(screen); dri_destroy_screen_helper(screen);
@ -583,33 +603,14 @@ fail:
return NULL; return NULL;
} }
static struct dri_drawable *
drisw_create_buffer(struct dri_screen *screen, const struct gl_config * visual,
boolean isPixmap, void *loaderPrivate)
{
struct dri_drawable *drawable = dri_create_buffer(screen, visual, isPixmap,
loaderPrivate);
if (!drawable)
return NULL;
drawable->allocate_textures = drisw_allocate_textures;
drawable->update_drawable_info = drisw_update_drawable_info;
drawable->flush_frontbuffer = drisw_flush_frontbuffer;
drawable->update_tex_buffer = drisw_update_tex_buffer;
return drawable;
}
/** /**
* DRI driver virtual function table. * DRI driver virtual function table.
* *
* DRI versions differ in their implementation of init_screen and swap_buffers. * DRI versions differ in their implementation of init_screen and swap_buffers.
*/ */
static const struct __DRIDriverVtableExtensionRec galliumsw_vtable = { static const struct __DRIBackendVtableExtensionRec galliumsw_vtable = {
.base = { __DRI_DRIVER_VTABLE, 1 }, .base = { __DRI_BACKEND_VTABLE, 1 },
.InitScreen = drisw_init_screen, .InitScreen = drisw_init_screen,
.CreateBuffer = drisw_create_buffer,
.SwapBuffers = drisw_swap_buffers,
}; };
/* swrast copy sub buffer entrypoint. */ /* swrast copy sub buffer entrypoint. */

View file

@ -55,6 +55,10 @@
extern const __DRIimageExtension driVkImageExtension; extern const __DRIimageExtension driVkImageExtension;
extern const __DRIimageExtension driVkImageExtensionSw; extern const __DRIimageExtension driVkImageExtensionSw;
static struct dri_drawable *
kopper_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
boolean isPixmap, void *loaderPrivate);
static void static void
kopper_flush_drawable(__DRIdrawable *dPriv) kopper_flush_drawable(__DRIdrawable *dPriv)
{ {
@ -167,6 +171,8 @@ kopper_init_screen(struct dri_screen *screen)
screen->lookup_egl_image_validated = dri2_lookup_egl_image_validated; screen->lookup_egl_image_validated = dri2_lookup_egl_image_validated;
} }
screen->create_drawable = kopper_create_drawable;
return configs; return configs;
fail: fail:
dri_destroy_screen_helper(screen); dri_destroy_screen_helper(screen);
@ -812,13 +818,16 @@ kopper_flush_swapbuffers(struct dri_context *ctx,
/* does this actually need to do anything? */ /* does this actually need to do anything? */
} }
static void
kopper_swap_buffers(struct dri_drawable *drawable);
static struct dri_drawable * static struct dri_drawable *
kopper_create_buffer(struct dri_screen *screen, const struct gl_config *visual, kopper_create_drawable(struct dri_screen *screen, const struct gl_config *visual,
boolean isPixmap, void *loaderPrivate) boolean isPixmap, void *loaderPrivate)
{ {
/* always pass !pixmap because it isn't "handled" or relevant */ /* always pass !pixmap because it isn't "handled" or relevant */
struct dri_drawable *drawable = dri_create_buffer(screen, visual, false, struct dri_drawable *drawable = dri_create_drawable(screen, visual, false,
loaderPrivate); loaderPrivate);
if (!drawable) if (!drawable)
return NULL; return NULL;
@ -832,6 +841,7 @@ kopper_create_buffer(struct dri_screen *screen, const struct gl_config *visual,
drawable->flush_frontbuffer = kopper_flush_frontbuffer; drawable->flush_frontbuffer = kopper_flush_frontbuffer;
drawable->update_tex_buffer = kopper_update_tex_buffer; drawable->update_tex_buffer = kopper_update_tex_buffer;
drawable->flush_swapbuffers = kopper_flush_swapbuffers; drawable->flush_swapbuffers = kopper_flush_swapbuffers;
drawable->swap_buffers = kopper_swap_buffers;
drawable->info.has_alpha = visual->alphaBits > 0; drawable->info.has_alpha = visual->alphaBits > 0;
if (screen->kopper_loader->SetSurfaceCreateInfo) if (screen->kopper_loader->SetSurfaceCreateInfo)
@ -898,7 +908,7 @@ kopperCreateNewDrawable(__DRIscreen *psp,
struct dri_screen *screen = dri_screen(psp); struct dri_screen *screen = dri_screen(psp);
struct dri_drawable *drawable = struct dri_drawable *drawable =
screen->driver->CreateBuffer(screen, &config->modes, is_pixmap, data); screen->create_drawable(screen, &config->modes, is_pixmap, data);
return opaque_dri_drawable(drawable); return opaque_dri_drawable(drawable);
} }
@ -948,11 +958,9 @@ const __DRIkopperExtension driKopperExtension = {
.queryBufferAge = kopperQueryBufferAge, .queryBufferAge = kopperQueryBufferAge,
}; };
static const struct __DRIDriverVtableExtensionRec galliumvk_vtable = { static const struct __DRIBackendVtableExtensionRec galliumvk_vtable = {
.base = { __DRI_DRIVER_VTABLE, 1 }, .base = { __DRI_BACKEND_VTABLE, 1 },
.InitScreen = kopper_init_screen, .InitScreen = kopper_init_screen,
.CreateBuffer = kopper_create_buffer,
.SwapBuffers = kopper_swap_buffers,
}; };
const __DRIextension *galliumvk_driver_extensions[] = { const __DRIextension *galliumvk_driver_extensions[] = {