boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct u_resource *ur = u_resource(resource);
return ur->vtbl->resource_get_handle(screen, resource, handle);
boolean u_resource_get_handle_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource,
- struct winsys_handle *handle);
+ struct winsys_handle *handle,
+ unsigned usage);
void u_resource_destroy_vtbl(struct pipe_screen *screen,
struct pipe_resource *resource);
template.flags = 0;
tex = scrn->base.pscreen->resource_from_handle(scrn->base.pscreen, &template,
- &dri2_handle);
+ &dri2_handle,
+ PIPE_HANDLE_USAGE_READ_WRITE);
free(reply);
return tex;
static struct pipe_resource *
dd_screen_resource_from_handle(struct pipe_screen *_screen,
const struct pipe_resource *templ,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct pipe_screen *screen = dd_screen(_screen)->screen;
struct pipe_resource *res =
- screen->resource_from_handle(screen, templ, handle);
+ screen->resource_from_handle(screen, templ, handle, usage);
if (!res)
return NULL;
static boolean
dd_screen_resource_get_handle(struct pipe_screen *_screen,
struct pipe_resource *resource,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct pipe_screen *screen = dd_screen(_screen)->screen;
- return screen->resource_get_handle(screen, resource, handle);
+ return screen->resource_get_handle(screen, resource, handle, usage);
}
static struct pipe_resource *
fd_resource_from_handle(struct pipe_screen *pscreen,
const struct pipe_resource *tmpl,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
struct fd_resource_slice *slice = &rsc->slices[0];
static struct pipe_resource *
i915_resource_from_handle(struct pipe_screen * screen,
const struct pipe_resource *template,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
if (template->target == PIPE_BUFFER)
return NULL;
static struct pipe_resource *
ilo_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templ,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
if (templ->target == PIPE_BUFFER)
return NULL;
static boolean
ilo_resource_get_handle(struct pipe_screen *screen,
struct pipe_resource *res,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
if (res->target == PIPE_BUFFER)
return false;
static struct pipe_resource *
llvmpipe_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *template,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
struct llvmpipe_resource *lpr;
static boolean
llvmpipe_resource_get_handle(struct pipe_screen *screen,
struct pipe_resource *pt,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
struct llvmpipe_resource *lpr = llvmpipe_resource(pt);
static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templ,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
struct pipe_screen *oscreen = noop_screen->oscreen;
struct pipe_resource *result;
struct pipe_resource *noop_resource;
- result = oscreen->resource_from_handle(oscreen, templ, handle);
+ result = oscreen->resource_from_handle(oscreen, templ, handle, usage);
noop_resource = noop_resource_create(screen, result);
pipe_resource_reference(&result, NULL);
return noop_resource;
static boolean noop_resource_get_handle(struct pipe_screen *screen,
struct pipe_resource *resource,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
return FALSE;
}
static struct pipe_resource *
nv30_resource_from_handle(struct pipe_screen *pscreen,
const struct pipe_resource *tmpl,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
if (tmpl->target == PIPE_BUFFER)
return NULL;
static struct pipe_resource *
nv50_resource_from_handle(struct pipe_screen * screen,
const struct pipe_resource *templ,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
if (templ->target == PIPE_BUFFER)
return NULL;
static struct pipe_resource *
nvc0_resource_from_handle(struct pipe_screen * screen,
const struct pipe_resource *templ,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
if (templ->target == PIPE_BUFFER) {
return NULL;
boolean r300_resource_get_handle(struct pipe_screen* screen,
struct pipe_resource *texture,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct radeon_winsys *rws = r300_screen(screen)->rws;
struct r300_resource* tex = (struct r300_resource*)texture;
struct pipe_resource *r300_texture_from_handle(struct pipe_screen *screen,
const struct pipe_resource *base,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct r300_screen *rscreen = r300_screen(screen);
struct radeon_winsys *rws = rscreen->rws;
#include "pipe/p_compiler.h"
#include "pipe/p_format.h"
+#include "pipe/p_screen.h"
struct pipe_screen;
struct pipe_context;
boolean r300_resource_get_handle(struct pipe_screen* screen,
struct pipe_resource *texture,
- struct winsys_handle *whandle);
+ struct winsys_handle *whandle,
+ unsigned usage);
struct pipe_resource*
r300_texture_from_handle(struct pipe_screen* screen,
const struct pipe_resource* base,
- struct winsys_handle *whandle);
+ struct winsys_handle *whandle,
+ unsigned usage);
struct pipe_resource*
r300_texture_create(struct pipe_screen* screen,
static boolean r600_texture_get_handle(struct pipe_screen* screen,
struct pipe_resource *ptex,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct r600_texture *rtex = (struct r600_texture*)ptex;
struct r600_resource *resource = &rtex->resource;
static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templ,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
struct pb_buffer *buf = NULL;
static struct pipe_resource *
rbug_screen_resource_from_handle(struct pipe_screen *_screen,
const struct pipe_resource *templ,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct rbug_screen *rb_screen = rbug_screen(_screen);
struct pipe_screen *screen = rb_screen->screen;
struct pipe_resource *result;
- result = screen->resource_from_handle(screen, templ, handle);
+ result = screen->resource_from_handle(screen, templ, handle, usage);
result = rbug_resource_create(rbug_screen(_screen), result);
static boolean
rbug_screen_resource_get_handle(struct pipe_screen *_screen,
struct pipe_resource *_resource,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct rbug_screen *rb_screen = rbug_screen(_screen);
struct rbug_resource *rb_resource = rbug_resource(_resource);
struct pipe_screen *screen = rb_screen->screen;
struct pipe_resource *resource = rb_resource->resource;
- return screen->resource_get_handle(screen, resource, handle);
+ return screen->resource_get_handle(screen, resource, handle, usage);
}
static struct pipe_resource *
softpipe_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templat,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
struct softpipe_resource *spr = CALLOC_STRUCT(softpipe_resource);
static boolean
softpipe_resource_get_handle(struct pipe_screen *screen,
struct pipe_resource *pt,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
struct softpipe_resource *spr = softpipe_resource(pt);
static struct pipe_resource *
svga_resource_from_handle(struct pipe_screen * screen,
const struct pipe_resource *template,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
if (template->target == PIPE_BUFFER)
return NULL;
static struct pipe_resource *
trace_screen_resource_from_handle(struct pipe_screen *_screen,
const struct pipe_resource *templ,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct trace_screen *tr_screen = trace_screen(_screen);
struct pipe_screen *screen = tr_screen->screen;
/* TODO trace call */
- result = screen->resource_from_handle(screen, templ, handle);
+ result = screen->resource_from_handle(screen, templ, handle, usage);
result = trace_resource_create(trace_screen(_screen), result);
static boolean
trace_screen_resource_get_handle(struct pipe_screen *_screen,
struct pipe_resource *_resource,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct trace_screen *tr_screen = trace_screen(_screen);
struct trace_resource *tr_resource = trace_resource(_resource);
/* TODO trace call */
- return screen->resource_get_handle(screen, resource, handle);
+ return screen->resource_get_handle(screen, resource, handle, usage);
}
static struct pipe_resource *
vc4_resource_from_handle(struct pipe_screen *pscreen,
const struct pipe_resource *tmpl,
- struct winsys_handle *handle)
+ struct winsys_handle *handle,
+ unsigned usage)
{
struct vc4_resource *rsc = vc4_resource_setup(pscreen, tmpl);
struct pipe_resource *prsc = &rsc->base.b;
static struct pipe_resource *virgl_resource_from_handle(struct pipe_screen *screen,
const struct pipe_resource *templ,
- struct winsys_handle *whandle)
+ struct winsys_handle *whandle,
+ unsigned usage)
{
struct virgl_screen *vs = virgl_screen(screen);
if (templ->target == PIPE_BUFFER)
};
+/**
+ * resource_get_handle flags.
+ */
+/* Requires pipe_context::flush_resource before external use. */
+#define PIPE_HANDLE_USAGE_EXPLICIT_FLUSH (1 << 0)
+/* Expected external use of the resource: */
+#define PIPE_HANDLE_USAGE_READ (1 << 1)
+#define PIPE_HANDLE_USAGE_WRITE (1 << 2)
+#define PIPE_HANDLE_USAGE_READ_WRITE (PIPE_HANDLE_USAGE_READ | \
+ PIPE_HANDLE_USAGE_WRITE)
+
/**
* Implementation capabilities/limits which are queried through
* pipe_screen::get_param()
* NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
* retains ownership of the FD. (This is consistent with
* EGL_EXT_image_dma_buf_import)
+ *
+ * \param usage A combination of PIPE_HANDLE_USAGE_* flags.
*/
struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
const struct pipe_resource *templat,
- struct winsys_handle *handle);
+ struct winsys_handle *handle,
+ unsigned usage);
/**
* Create a resource from user memory. This maps the user memory into
* NOTE: in the case of DRM_API_HANDLE_TYPE_FD handles, the caller
* takes ownership of the FD. (This is consistent with
* EGL_MESA_image_dma_buf_export)
+ *
+ * \param usage A combination of PIPE_HANDLE_USAGE_* flags.
*/
boolean (*resource_get_handle)(struct pipe_screen *,
struct pipe_resource *tex,
- struct winsys_handle *handle);
+ struct winsys_handle *handle,
+ unsigned usage);
void (*resource_destroy)(struct pipe_screen *,
whandle.type = DRM_API_HANDLE_TYPE_KMS;
screen->base.screen->resource_get_handle(screen->base.screen,
- buffer->resource, &whandle);
+ buffer->resource, &whandle,
+ PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
buffer->base.attachment = attachment;
buffer->base.name = whandle.handle;
whandle.type = DRM_API_HANDLE_TYPE_KMS;
drawable->textures[statt] =
screen->base.screen->resource_from_handle(screen->base.screen,
- &templ, &whandle);
+ &templ, &whandle,
+ PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ);
assert(drawable->textures[statt]);
}
}
whandle->stride = pitch * util_format_get_blocksize(pf);
img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
- &templ, whandle);
+ &templ, whandle, PIPE_HANDLE_USAGE_READ_WRITE);
if (!img->texture) {
FREE(img);
return NULL;
img->level = 0;
img->layer = 0;
img->dri_format = format;
+ img->use = 0;
img->loader_private = loaderPrivate;
return img;
img->layer = 0;
img->dri_format = format;
img->dri_components = 0;
+ img->use = use;
img->loader_private = loaderPrivate;
return img;
dri2_query_image(__DRIimage *image, int attrib, int *value)
{
struct winsys_handle whandle;
+ unsigned usage;
+
+ if (image->use & __DRI_IMAGE_USE_BACKBUFFER)
+ usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ;
+ else
+ usage = PIPE_HANDLE_USAGE_READ_WRITE;
+
memset(&whandle, 0, sizeof(whandle));
switch (attrib) {
case __DRI_IMAGE_ATTRIB_STRIDE:
whandle.type = DRM_API_HANDLE_TYPE_KMS;
image->texture->screen->resource_get_handle(image->texture->screen,
- image->texture, &whandle);
+ image->texture, &whandle, usage);
*value = whandle.stride;
return GL_TRUE;
case __DRI_IMAGE_ATTRIB_HANDLE:
whandle.type = DRM_API_HANDLE_TYPE_KMS;
image->texture->screen->resource_get_handle(image->texture->screen,
- image->texture, &whandle);
+ image->texture, &whandle, usage);
*value = whandle.handle;
return GL_TRUE;
case __DRI_IMAGE_ATTRIB_NAME:
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
image->texture->screen->resource_get_handle(image->texture->screen,
- image->texture, &whandle);
+ image->texture, &whandle, usage);
*value = whandle.handle;
return GL_TRUE;
case __DRI_IMAGE_ATTRIB_FD:
whandle.type= DRM_API_HANDLE_TYPE_FD;
image->texture->screen->resource_get_handle(image->texture->screen,
- image->texture, &whandle);
+ image->texture, &whandle, usage);
*value = whandle.handle;
return GL_TRUE;
case __DRI_IMAGE_ATTRIB_FORMAT:
unsigned layer;
uint32_t dri_format;
uint32_t dri_components;
+ unsigned use;
void *loader_private;
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_FD;
- This->screen->resource_get_handle(This->screen, resource, &whandle);
+ This->screen->resource_get_handle(This->screen, resource, &whandle,
+ PIPE_HANDLE_USAGE_EXPLICIT_FLUSH |
+ PIPE_HANDLE_USAGE_READ);
stride = whandle.stride;
dmaBufFd = whandle.handle;
ID3DPresent_NewD3DWindowBufferFromDmaBuf(This->present,
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_FD;
- if (!screen->resource_get_handle(screen, buf->derived_surface.resource, &whandle))
+ if (!screen->resource_get_handle(screen, buf->derived_surface.resource,
+ &whandle, PIPE_HANDLE_USAGE_READ_WRITE))
return VA_STATUS_ERROR_INVALID_BUFFER;
buf_info->handle = (intptr_t)whandle.handle;
whandle.handle = memory_attibute->buffers[index];
whandle.stride = memory_attibute->pitches[index];
- resource = pscreen->resource_from_handle(pscreen, &res_templ, &whandle);
+ resource = pscreen->resource_from_handle(pscreen, &res_templ, &whandle,
+ PIPE_HANDLE_USAGE_READ_WRITE);
if (!resource)
return VA_STATUS_ERROR_ALLOCATION_FAILED;
template->bind |= PIPE_BIND_SCANOUT;
if (whandle)
- srf->tex = xa->screen->resource_from_handle(xa->screen, template, whandle);
+ srf->tex = xa->screen->resource_from_handle(xa->screen, template, whandle,
+ PIPE_HANDLE_USAGE_READ_WRITE);
else
srf->tex = xa->screen->resource_create(xa->screen, template);
if (!srf->tex)
memset(&whandle, 0, sizeof(whandle));
whandle.type = handle_type(type);
- res = screen->resource_get_handle(screen, srf->tex, &whandle);
+ res = screen->resource_get_handle(screen, srf->tex, &whandle,
+ PIPE_HANDLE_USAGE_READ_WRITE);
if (!res)
return -XA_ERR_INVAL;
struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws);
struct pipe_resource *tex;
- tex = wsw->screen->resource_from_handle(wsw->screen, templ, whandle);
+ tex = wsw->screen->resource_from_handle(wsw->screen, templ, whandle,
+ PIPE_HANDLE_USAGE_READ_WRITE);
if (!tex)
return NULL;
struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt);
struct pipe_resource *tex = wdt->tex;
- return wsw->screen->resource_get_handle(wsw->screen, tex, whandle);
+ return wsw->screen->resource_get_handle(wsw->screen, tex, whandle,
+ PIPE_HANDLE_USAGE_READ_WRITE);
}
static void *