gallium: Expose a opaque winsys handle and functions on pipe_screen
Instead of having these functions on a side interface like on drm_api create a opaque winsys_handle that is to be passed down into the winsys. Currently the only thing ported to this new interface is drm_api, and of that only the components that builds by default is ported. All the drivers and any extra state trackers needs to be ported before this can go into master.
This commit is contained in:
parent
f54aecc4f2
commit
b2e94d05c9
|
@ -63,62 +63,6 @@ identity_drm_create_screen(struct drm_api *_api, int fd,
|
|||
return identity_screen_create(screen);
|
||||
}
|
||||
|
||||
|
||||
static struct pipe_texture *
|
||||
identity_drm_texture_from_shared_handle(struct drm_api *_api,
|
||||
struct pipe_screen *_screen,
|
||||
struct pipe_texture *templ,
|
||||
const char *name,
|
||||
unsigned stride,
|
||||
unsigned handle)
|
||||
{
|
||||
struct identity_screen *id_screen = identity_screen(_screen);
|
||||
struct identity_drm_api *id_api = identity_drm_api(_api);
|
||||
struct pipe_screen *screen = id_screen->screen;
|
||||
struct drm_api *api = id_api->api;
|
||||
struct pipe_texture *result;
|
||||
|
||||
result = api->texture_from_shared_handle(api, screen, templ, name, stride, handle);
|
||||
|
||||
result = identity_texture_create(identity_screen(_screen), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean
|
||||
identity_drm_shared_handle_from_texture(struct drm_api *_api,
|
||||
struct pipe_screen *_screen,
|
||||
struct pipe_texture *_texture,
|
||||
unsigned *stride,
|
||||
unsigned *handle)
|
||||
{
|
||||
struct identity_screen *id_screen = identity_screen(_screen);
|
||||
struct identity_texture *id_texture = identity_texture(_texture);
|
||||
struct identity_drm_api *id_api = identity_drm_api(_api);
|
||||
struct pipe_screen *screen = id_screen->screen;
|
||||
struct pipe_texture *texture = id_texture->texture;
|
||||
struct drm_api *api = id_api->api;
|
||||
|
||||
return api->shared_handle_from_texture(api, screen, texture, stride, handle);
|
||||
}
|
||||
|
||||
static boolean
|
||||
identity_drm_local_handle_from_texture(struct drm_api *_api,
|
||||
struct pipe_screen *_screen,
|
||||
struct pipe_texture *_texture,
|
||||
unsigned *stride,
|
||||
unsigned *handle)
|
||||
{
|
||||
struct identity_screen *id_screen = identity_screen(_screen);
|
||||
struct identity_texture *id_texture = identity_texture(_texture);
|
||||
struct identity_drm_api *id_api = identity_drm_api(_api);
|
||||
struct pipe_screen *screen = id_screen->screen;
|
||||
struct pipe_texture *texture = id_texture->texture;
|
||||
struct drm_api *api = id_api->api;
|
||||
|
||||
return api->local_handle_from_texture(api, screen, texture, stride, handle);
|
||||
}
|
||||
|
||||
static void
|
||||
identity_drm_destroy(struct drm_api *_api)
|
||||
{
|
||||
|
@ -145,9 +89,6 @@ identity_drm_create(struct drm_api *api)
|
|||
id_api->base.name = api->name;
|
||||
id_api->base.driver_name = api->driver_name;
|
||||
id_api->base.create_screen = identity_drm_create_screen;
|
||||
id_api->base.texture_from_shared_handle = identity_drm_texture_from_shared_handle;
|
||||
id_api->base.shared_handle_from_texture = identity_drm_shared_handle_from_texture;
|
||||
id_api->base.local_handle_from_texture = identity_drm_local_handle_from_texture;
|
||||
id_api->base.destroy = identity_drm_destroy;
|
||||
id_api->api = api;
|
||||
|
||||
|
|
|
@ -134,6 +134,39 @@ identity_screen_texture_create(struct pipe_screen *_screen,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct pipe_texture *
|
||||
identity_screen_texture_from_handle(struct pipe_screen *_screen,
|
||||
const struct pipe_texture *templ,
|
||||
struct winsys_handle *handle)
|
||||
{
|
||||
struct identity_screen *id_screen = identity_screen(_screen);
|
||||
struct pipe_screen *screen = id_screen->screen;
|
||||
struct pipe_texture *result;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
result = screen->texture_from_handle(screen, templ, handle);
|
||||
|
||||
result = identity_texture_create(identity_screen(_screen), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean
|
||||
identity_screen_texture_get_handle(struct pipe_screen *_screen,
|
||||
struct pipe_texture *_texture,
|
||||
struct winsys_handle *handle)
|
||||
{
|
||||
struct identity_screen *id_screen = identity_screen(_screen);
|
||||
struct identity_texture *id_texture = identity_texture(_texture);
|
||||
struct pipe_screen *screen = id_screen->screen;
|
||||
struct pipe_texture *texture = id_texture->texture;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
return screen->texture_get_handle(screen, texture, handle);
|
||||
}
|
||||
|
||||
static struct pipe_texture *
|
||||
identity_screen_texture_blanket(struct pipe_screen *_screen,
|
||||
const struct pipe_texture *templat,
|
||||
|
@ -495,6 +528,8 @@ identity_screen_create(struct pipe_screen *screen)
|
|||
id_screen->base.is_format_supported = identity_screen_is_format_supported;
|
||||
id_screen->base.context_create = identity_screen_context_create;
|
||||
id_screen->base.texture_create = identity_screen_texture_create;
|
||||
id_screen->base.texture_from_handle = identity_screen_texture_from_handle;
|
||||
id_screen->base.texture_get_handle = identity_screen_texture_get_handle;
|
||||
id_screen->base.texture_blanket = identity_screen_texture_blanket;
|
||||
id_screen->base.texture_destroy = identity_screen_texture_destroy;
|
||||
id_screen->base.get_tex_surface = identity_screen_get_tex_surface;
|
||||
|
|
|
@ -62,71 +62,10 @@ trace_drm_create_screen(struct drm_api *_api, int fd,
|
|||
|
||||
screen = api->create_screen(api, fd, arg);
|
||||
|
||||
|
||||
return trace_screen_create(screen);
|
||||
}
|
||||
|
||||
|
||||
static struct pipe_texture *
|
||||
trace_drm_texture_from_shared_handle(struct drm_api *_api,
|
||||
struct pipe_screen *_screen,
|
||||
struct pipe_texture *templ,
|
||||
const char *name,
|
||||
unsigned stride,
|
||||
unsigned handle)
|
||||
{
|
||||
struct trace_screen *tr_screen = trace_screen(_screen);
|
||||
struct trace_drm_api *tr_api = trace_drm_api(_api);
|
||||
struct pipe_screen *screen = tr_screen->screen;
|
||||
struct drm_api *api = tr_api->api;
|
||||
struct pipe_texture *result;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
result = api->texture_from_shared_handle(api, screen, templ, name, stride, handle);
|
||||
|
||||
result = trace_texture_create(trace_screen(_screen), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean
|
||||
trace_drm_shared_handle_from_texture(struct drm_api *_api,
|
||||
struct pipe_screen *_screen,
|
||||
struct pipe_texture *_texture,
|
||||
unsigned *stride,
|
||||
unsigned *handle)
|
||||
{
|
||||
struct trace_screen *tr_screen = trace_screen(_screen);
|
||||
struct trace_texture *tr_texture = trace_texture(_texture);
|
||||
struct trace_drm_api *tr_api = trace_drm_api(_api);
|
||||
struct pipe_screen *screen = tr_screen->screen;
|
||||
struct pipe_texture *texture = tr_texture->texture;
|
||||
struct drm_api *api = tr_api->api;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
return api->shared_handle_from_texture(api, screen, texture, stride, handle);
|
||||
}
|
||||
|
||||
static boolean
|
||||
trace_drm_local_handle_from_texture(struct drm_api *_api,
|
||||
struct pipe_screen *_screen,
|
||||
struct pipe_texture *_texture,
|
||||
unsigned *stride,
|
||||
unsigned *handle)
|
||||
{
|
||||
struct trace_screen *tr_screen = trace_screen(_screen);
|
||||
struct trace_texture *tr_texture = trace_texture(_texture);
|
||||
struct trace_drm_api *tr_api = trace_drm_api(_api);
|
||||
struct pipe_screen *screen = tr_screen->screen;
|
||||
struct pipe_texture *texture = tr_texture->texture;
|
||||
struct drm_api *api = tr_api->api;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
return api->local_handle_from_texture(api, screen, texture, stride, handle);
|
||||
}
|
||||
|
||||
static void
|
||||
trace_drm_destroy(struct drm_api *_api)
|
||||
{
|
||||
|
@ -158,9 +97,6 @@ trace_drm_create(struct drm_api *api)
|
|||
tr_api->base.name = api->name;
|
||||
tr_api->base.driver_name = api->driver_name;
|
||||
tr_api->base.create_screen = trace_drm_create_screen;
|
||||
tr_api->base.texture_from_shared_handle = trace_drm_texture_from_shared_handle;
|
||||
tr_api->base.shared_handle_from_texture = trace_drm_shared_handle_from_texture;
|
||||
tr_api->base.local_handle_from_texture = trace_drm_local_handle_from_texture;
|
||||
tr_api->base.destroy = trace_drm_destroy;
|
||||
tr_api->api = api;
|
||||
|
||||
|
|
|
@ -236,6 +236,38 @@ trace_screen_texture_create(struct pipe_screen *_screen,
|
|||
return result;
|
||||
}
|
||||
|
||||
static struct pipe_texture *
|
||||
trace_screen_texture_from_handle(struct pipe_screen *_screen,
|
||||
const struct pipe_texture *templ,
|
||||
struct winsys_handle *handle)
|
||||
{
|
||||
struct trace_screen *tr_screen = trace_screen(_screen);
|
||||
struct pipe_screen *screen = tr_screen->screen;
|
||||
struct pipe_texture *result;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
result = screen->texture_from_handle(screen, templ, handle);
|
||||
|
||||
result = trace_texture_create(trace_screen(_screen), result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean
|
||||
trace_screen_texture_get_handle(struct pipe_screen *_screen,
|
||||
struct pipe_texture *_texture,
|
||||
struct winsys_handle *handle)
|
||||
{
|
||||
struct trace_screen *tr_screen = trace_screen(_screen);
|
||||
struct trace_texture *tr_texture = trace_texture(_texture);
|
||||
struct pipe_screen *screen = tr_screen->screen;
|
||||
struct pipe_texture *texture = tr_texture->texture;
|
||||
|
||||
/* TODO trace call */
|
||||
|
||||
return screen->texture_get_handle(screen, texture, handle);
|
||||
}
|
||||
|
||||
static struct pipe_texture *
|
||||
trace_screen_texture_blanket(struct pipe_screen *_screen,
|
||||
|
@ -931,6 +963,8 @@ trace_screen_create(struct pipe_screen *screen)
|
|||
assert(screen->context_create);
|
||||
tr_scr->base.context_create = trace_screen_context_create;
|
||||
tr_scr->base.texture_create = trace_screen_texture_create;
|
||||
tr_scr->base.texture_from_handle = trace_screen_texture_from_handle;
|
||||
tr_scr->base.texture_get_handle = trace_screen_texture_get_handle;
|
||||
tr_scr->base.texture_blanket = trace_screen_texture_blanket;
|
||||
tr_scr->base.texture_destroy = trace_screen_texture_destroy;
|
||||
tr_scr->base.get_tex_surface = trace_screen_get_tex_surface;
|
||||
|
|
|
@ -49,6 +49,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
/** Opaque type */
|
||||
struct winsys_handle;
|
||||
/** Opaque type */
|
||||
struct pipe_fence_handle;
|
||||
struct pipe_winsys;
|
||||
|
@ -107,6 +109,24 @@ struct pipe_screen {
|
|||
struct pipe_texture * (*texture_create)(struct pipe_screen *,
|
||||
const struct pipe_texture *templat);
|
||||
|
||||
/**
|
||||
* Create a texture from a winsys_handle. The handle is often created in
|
||||
* another process by first creating a pipe texture and then calling
|
||||
* texture_get_handle.
|
||||
*/
|
||||
struct pipe_texture * (*texture_from_handle)(struct pipe_screen *,
|
||||
const struct pipe_texture *templat,
|
||||
struct winsys_handle *handle);
|
||||
|
||||
/**
|
||||
* Get a winsys_handle from a texture. Some platforms/winsys requires
|
||||
* that the texture is created with a special usage flag like
|
||||
* DISPLAYTARGET or PRIMARY.
|
||||
*/
|
||||
boolean (*texture_get_handle)(struct pipe_screen *,
|
||||
struct pipe_texture *tex,
|
||||
struct winsys_handle *handle);
|
||||
|
||||
/**
|
||||
* Create a new texture object, using the given template info, but on top of
|
||||
* existing memory.
|
||||
|
|
|
@ -17,6 +17,31 @@ enum drm_create_screen_mode {
|
|||
DRM_CREATE_MAX
|
||||
};
|
||||
|
||||
#define DRM_API_HANDLE_TYPE_SHARED 0
|
||||
#define DRM_API_HANDLE_TYPE_KMS 1
|
||||
|
||||
/**
|
||||
* For use with pipe_screen::{texture_from_handle|texture_get_handle}.
|
||||
*/
|
||||
struct winsys_handle
|
||||
{
|
||||
/**
|
||||
* Unused for texture_from_handle, always DRM_API_HANDLE_TYPE_SHARED.
|
||||
* Input to texture_get_handle, use TEXTURE_USAGE to select handle for kms or ipc.
|
||||
*/
|
||||
unsigned type;
|
||||
/**
|
||||
* Input to texture_from_handle.
|
||||
* Output for texture_get_handle.
|
||||
*/
|
||||
unsigned handle;
|
||||
/**
|
||||
* Input to texture_from_handle.
|
||||
* Output for texture_get_handle.
|
||||
*/
|
||||
unsigned stride;
|
||||
};
|
||||
|
||||
/**
|
||||
* Modes other than DRM_CREATE_NORMAL derive from this struct.
|
||||
*/
|
||||
|
@ -28,6 +53,8 @@ struct drm_create_screen_arg {
|
|||
|
||||
struct drm_api
|
||||
{
|
||||
void (*destroy)(struct drm_api *api);
|
||||
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
|
@ -36,37 +63,10 @@ struct drm_api
|
|||
const char *driver_name;
|
||||
|
||||
/**
|
||||
* Special buffer functions
|
||||
* Create a pipe srcreen.
|
||||
*/
|
||||
/*@{*/
|
||||
struct pipe_screen* (*create_screen)(struct drm_api *api, int drm_fd,
|
||||
struct drm_create_screen_arg *arg);
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Special buffer functions
|
||||
*/
|
||||
/*@{*/
|
||||
struct pipe_texture*
|
||||
(*texture_from_shared_handle)(struct drm_api *api,
|
||||
struct pipe_screen *screen,
|
||||
struct pipe_texture *templ,
|
||||
const char *name,
|
||||
unsigned stride,
|
||||
unsigned handle);
|
||||
boolean (*shared_handle_from_texture)(struct drm_api *api,
|
||||
struct pipe_screen *screen,
|
||||
struct pipe_texture *texture,
|
||||
unsigned *stride,
|
||||
unsigned *handle);
|
||||
boolean (*local_handle_from_texture)(struct drm_api *api,
|
||||
struct pipe_screen *screen,
|
||||
struct pipe_texture *texture,
|
||||
unsigned *stride,
|
||||
unsigned *handle);
|
||||
/*@}*/
|
||||
|
||||
void (*destroy)(struct drm_api *api);
|
||||
};
|
||||
|
||||
extern struct drm_api * drm_api_create(void);
|
||||
|
|
|
@ -58,6 +58,7 @@ dri_surface_from_handle(struct drm_api *api,
|
|||
struct pipe_surface *surface = NULL;
|
||||
struct pipe_texture *texture = NULL;
|
||||
struct pipe_texture templat;
|
||||
struct winsys_handle whandle;
|
||||
|
||||
memset(&templat, 0, sizeof(templat));
|
||||
templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
|
||||
|
@ -68,8 +69,11 @@ dri_surface_from_handle(struct drm_api *api,
|
|||
templat.width0 = width;
|
||||
templat.height0 = height;
|
||||
|
||||
texture = api->texture_from_shared_handle(api, screen, &templat,
|
||||
"dri2 buffer", pitch, handle);
|
||||
memset(&whandle, 0, sizeof(whandle));
|
||||
whandle.handle = handle;
|
||||
whandle.stride = pitch;
|
||||
|
||||
texture = screen->texture_from_handle(screen, &templat, &whandle);
|
||||
|
||||
if (!texture) {
|
||||
debug_printf("%s: Failed to blanket the buffer with a texture\n", __func__);
|
||||
|
|
|
@ -112,6 +112,7 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf,
|
|||
struct dri2_surface *dri2surf = dri2_surface(nsurf);
|
||||
struct dri2_display *dri2dpy = dri2surf->dri2dpy;
|
||||
struct pipe_texture templ;
|
||||
struct winsys_handle whandle;
|
||||
uint valid_mask;
|
||||
int i;
|
||||
|
||||
|
@ -169,9 +170,11 @@ dri2_surface_process_drawable_buffers(struct native_surface *nsurf,
|
|||
continue;
|
||||
}
|
||||
|
||||
dri2surf->textures[natt] =
|
||||
dri2dpy->api->texture_from_shared_handle(dri2dpy->api,
|
||||
dri2dpy->base.screen, &templ, desc, xbuf->pitch, xbuf->name);
|
||||
memset(&whandle, 0, sizeof(whandle));
|
||||
whandle.stride = xbuf->pitch;
|
||||
whandle.handle = xbuf->name;
|
||||
dri2surf->textures[natt] = dri2dpy->base.screen->texture_from_handle(
|
||||
dri2dpy->base.screen, &templ, &whandle);
|
||||
if (dri2surf->textures[natt])
|
||||
valid_mask |= 1 << natt;
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image)
|
|||
|
||||
if (!crtcp->cursor_tex) {
|
||||
struct pipe_texture templat;
|
||||
unsigned pitch;
|
||||
struct winsys_handle whandle;
|
||||
|
||||
memset(&templat, 0, sizeof(templat));
|
||||
templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
|
||||
|
@ -209,13 +209,14 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image)
|
|||
templat.width0 = 64;
|
||||
templat.height0 = 64;
|
||||
|
||||
memset(&whandle, 0, sizeof(whandle));
|
||||
whandle.type = DRM_API_HANDLE_TYPE_KMS;
|
||||
|
||||
crtcp->cursor_tex = ms->screen->texture_create(ms->screen,
|
||||
&templat);
|
||||
ms->api->local_handle_from_texture(ms->api,
|
||||
ms->screen,
|
||||
crtcp->cursor_tex,
|
||||
&pitch,
|
||||
&crtcp->cursor_handle);
|
||||
ms->screen->texture_get_handle(ms->screen, crtcp->cursor_tex, &whandle);
|
||||
|
||||
crtcp->cursor_handle = whandle.handle;
|
||||
}
|
||||
|
||||
transfer = ms->screen->get_tex_transfer(ms->screen, crtcp->cursor_tex,
|
||||
|
|
|
@ -67,7 +67,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form
|
|||
struct exa_pixmap_priv *exa_priv;
|
||||
BufferPrivatePtr private = buffer->driverPrivate;
|
||||
PixmapPtr pPixmap;
|
||||
unsigned stride, handle;
|
||||
struct winsys_handle whandle;
|
||||
|
||||
if (pDraw->type == DRAWABLE_PIXMAP)
|
||||
pPixmap = (PixmapPtr) pDraw;
|
||||
|
@ -75,6 +75,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form
|
|||
pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw);
|
||||
exa_priv = exaGetPixmapDriverPrivate(pPixmap);
|
||||
|
||||
|
||||
switch (buffer->attachment) {
|
||||
default:
|
||||
if (buffer->attachment != DRI2BufferFakeFrontLeft ||
|
||||
|
@ -153,10 +154,13 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form
|
|||
if (!tex)
|
||||
FatalError("NO TEXTURE IN DRI2\n");
|
||||
|
||||
ms->api->shared_handle_from_texture(ms->api, ms->screen, tex, &stride, &handle);
|
||||
memset(&whandle, 0, sizeof(whandle));
|
||||
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
|
||||
|
||||
buffer->name = handle;
|
||||
buffer->pitch = stride;
|
||||
ms->screen->texture_get_handle(ms->screen, tex, &whandle);
|
||||
|
||||
buffer->name = whandle.handle;
|
||||
buffer->pitch = whandle.stride;
|
||||
buffer->cpp = 4;
|
||||
buffer->driverPrivate = private;
|
||||
buffer->flags = 0; /* not tiled */
|
||||
|
|
|
@ -989,8 +989,9 @@ static Bool
|
|||
drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
|
||||
{
|
||||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
unsigned handle, stride, fb_id;
|
||||
struct pipe_texture *tex;
|
||||
struct winsys_handle whandle;
|
||||
unsigned fb_id;
|
||||
int ret;
|
||||
|
||||
ms->noEvict = TRUE;
|
||||
|
@ -1001,10 +1002,10 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
|
|||
if (!tex)
|
||||
return FALSE;
|
||||
|
||||
if (!ms->api->local_handle_from_texture(ms->api, ms->screen,
|
||||
tex,
|
||||
&stride,
|
||||
&handle))
|
||||
memset(&whandle, 0, sizeof(whandle));
|
||||
whandle.type = DRM_API_HANDLE_TYPE_KMS;
|
||||
|
||||
if (!ms->screen->texture_get_handle(ms->screen, tex, &whandle))
|
||||
goto err_destroy;
|
||||
|
||||
ret = drmModeAddFB(ms->fd,
|
||||
|
@ -1012,8 +1013,8 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
|
|||
pScrn->virtualY,
|
||||
pScrn->depth,
|
||||
pScrn->bitsPerPixel,
|
||||
stride,
|
||||
handle,
|
||||
whandle.stride,
|
||||
whandle.handle,
|
||||
&fb_id);
|
||||
if (ret) {
|
||||
debug_printf("%s: failed to create framebuffer (%i, %s)\n",
|
||||
|
|
Loading…
Reference in New Issue