};
static struct xa_format_descriptor
-xa_get_pipe_format(enum xa_formats xa_format)
+xa_get_pipe_format(struct xa_tracker *xa, enum xa_formats xa_format)
{
struct xa_format_descriptor fdesc;
fdesc.xa_format = xa_format;
switch (xa_format) {
+ case xa_format_a8:
+ if (xa->screen->is_format_supported(xa->screen, PIPE_FORMAT_R8_UNORM,
+ PIPE_TEXTURE_2D, 0, 0,
+ stype_bind[xa_type_a] |
+ PIPE_BIND_RENDER_TARGET))
+ fdesc.format = PIPE_FORMAT_R8_UNORM;
+ else
+ fdesc.format = PIPE_FORMAT_L8_UNORM;
+ break;
case xa_format_a8r8g8b8:
fdesc.format = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
case xa_format_x1r5g5b5:
fdesc.format = PIPE_FORMAT_B5G5R5A1_UNORM;
break;
- case xa_format_a8:
- fdesc.format = PIPE_FORMAT_L8_UNORM;
- break;
+ case xa_format_a4r4g4b4:
+ fdesc.format = PIPE_FORMAT_B4G4R4A4_UNORM;
+ break;
+ case xa_format_a2b10g10r10:
+ fdesc.format = PIPE_FORMAT_R10G10B10A2_UNORM;
+ break;
+ case xa_format_x2b10g10r10:
+ fdesc.format = PIPE_FORMAT_R10G10B10X2_UNORM;
+ break;
+ case xa_format_b8g8r8a8:
+ fdesc.format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ break;
+ case xa_format_b8g8r8x8:
+ fdesc.format = PIPE_FORMAT_X8R8G8B8_UNORM;
+ break;
case xa_format_z24:
fdesc.format = PIPE_FORMAT_Z24X8_UNORM;
break;
fdesc.format = PIPE_FORMAT_S8_UINT_Z24_UNORM;
break;
case xa_format_yuv8:
- fdesc.format = PIPE_FORMAT_L8_UNORM;
+ if (xa->screen->is_format_supported(xa->screen, PIPE_FORMAT_R8_UNORM,
+ PIPE_TEXTURE_2D, 0, 0,
+ stype_bind[xa_type_yuv_component]))
+ fdesc.format = PIPE_FORMAT_R8_UNORM;
+ else
+ fdesc.format = PIPE_FORMAT_L8_UNORM;
break;
default:
fdesc.xa_format = xa_format_unknown;
struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker));
enum xa_surface_type stype;
unsigned int num_formats;
- int loader_fd;
if (!xa)
return NULL;
-#if GALLIUM_STATIC_TARGETS
- xa->screen = dd_create_screen(drm_fd);
- (void) loader_fd; /* silence unused var warning */
-#else
- loader_fd = dup(drm_fd);
- if (loader_fd == -1)
- return NULL;
- if (pipe_loader_drm_probe_fd(&xa->dev, loader_fd))
- xa->screen = pipe_loader_create_screen(xa->dev, PIPE_SEARCH_DIR);
-#endif
+ if (pipe_loader_drm_probe_fd(&xa->dev, drm_fd))
+ xa->screen = pipe_loader_create_screen(xa->dev);
+
if (!xa->screen)
goto out_no_screen;
for (i = 0; i < num_preferred[stype]; ++i) {
xa_format = preferred[stype][i];
- struct xa_format_descriptor fdesc = xa_get_pipe_format(xa_format);
+ struct xa_format_descriptor fdesc =
+ xa_get_pipe_format(xa, xa_format);
if (xa->screen->is_format_supported(xa->screen, fdesc.format,
- PIPE_TEXTURE_2D, 0, bind)) {
+ PIPE_TEXTURE_2D, 0, 0, bind)) {
if (xa->format_map[stype][0] == 0)
xa->format_map[stype][0] = num_formats;
xa->format_map[stype][1] = num_formats;
out_no_pipe:
xa->screen->destroy(xa->screen);
out_no_screen:
-#if !GALLIUM_STATIC_TARGETS
if (xa->dev)
pipe_loader_release(&xa->dev, 1);
-#endif
+
free(xa);
return NULL;
}
free(xa->supported_formats);
xa_context_destroy(xa->default_ctx);
xa->screen->destroy(xa->screen);
-#if !GALLIUM_STATIC_TARGETS
pipe_loader_release(&xa->dev, 1);
-#endif
+ /* CHECK: The XA API user preserves ownership of the original fd */
free(xa);
}
int found = 0;
for (i = xa->format_map[stype][0]; i <= xa->format_map[stype][1]; ++i) {
- fdesc = xa_get_pipe_format(xa->supported_formats[i]);
+ fdesc = xa_get_pipe_format(xa, xa->supported_formats[i]);
if (fdesc.xa_format != xa_format_unknown &&
xa_format_depth(fdesc.xa_format) == depth) {
found = 1;
xa_format_check_supported(struct xa_tracker *xa,
enum xa_formats xa_format, unsigned int flags)
{
- struct xa_format_descriptor fdesc = xa_get_pipe_format(xa_format);
+ struct xa_format_descriptor fdesc = xa_get_pipe_format(xa, xa_format);
unsigned int bind;
if (fdesc.xa_format == xa_format_unknown)
bind |= PIPE_BIND_SCANOUT;
if (!xa->screen->is_format_supported(xa->screen, fdesc.format,
- PIPE_TEXTURE_2D, 0, bind))
+ PIPE_TEXTURE_2D, 0, 0, bind))
return -XA_ERR_INVAL;
return XA_ERR_NONE;
}
+static unsigned
+handle_type(enum xa_handle_type type)
+{
+ switch (type) {
+ case xa_handle_type_kms:
+ return WINSYS_HANDLE_TYPE_KMS;
+ case xa_handle_type_fd:
+ return WINSYS_HANDLE_TYPE_FD;
+ case xa_handle_type_shared:
+ default:
+ return WINSYS_HANDLE_TYPE_SHARED;
+ }
+}
+
static struct xa_surface *
surface_create(struct xa_tracker *xa,
int width,
if (xa_format == xa_format_unknown)
fdesc = xa_get_format_stype_depth(xa, stype, depth);
else
- fdesc = xa_get_pipe_format(xa_format);
+ fdesc = xa_get_pipe_format(xa, xa_format);
if (fdesc.xa_format == xa_format_unknown)
return NULL;
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_FRAMEBUFFER_WRITE);
else
srf->tex = xa->screen->resource_create(xa->screen, template);
if (!srf->tex)
enum xa_surface_type stype,
enum xa_formats xa_format, unsigned int flags,
uint32_t handle, uint32_t stride)
+{
+ return xa_surface_from_handle2(xa, width, height, depth, stype, xa_format,
+ WINSYS_HANDLE_TYPE_SHARED, flags, handle,
+ stride);
+}
+
+XA_EXPORT struct xa_surface *
+xa_surface_from_handle2(struct xa_tracker *xa,
+ int width,
+ int height,
+ int depth,
+ enum xa_surface_type stype,
+ enum xa_formats xa_format, unsigned int flags,
+ enum xa_handle_type type,
+ uint32_t handle, uint32_t stride)
{
struct winsys_handle whandle;
memset(&whandle, 0, sizeof(whandle));
- whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+ whandle.type = handle_type(type);
whandle.handle = handle;
whandle.stride = stride;
return surface_create(xa, width, height, depth, stype, xa_format, flags, &whandle);
if (xa_format == xa_format_unknown)
fdesc = xa_get_format_stype_depth(xa, stype, depth);
else
- fdesc = xa_get_pipe_format(xa_format);
+ fdesc = xa_get_pipe_format(xa, xa_format);
if (width == template->width0 && height == template->height0 &&
template->format == fdesc.format &&
return -XA_ERR_INVAL;
if (!xa->screen->is_format_supported(xa->screen, fdesc.format,
- PIPE_TEXTURE_2D, 0,
+ PIPE_TEXTURE_2D, 0, 0,
template->bind |
PIPE_BIND_RENDER_TARGET))
return -XA_ERR_INVAL;
boolean res;
memset(&whandle, 0, sizeof(whandle));
- switch (type) {
- case xa_handle_type_kms:
- whandle.type = DRM_API_HANDLE_TYPE_KMS;
- break;
- case xa_handle_type_shared:
- default:
- whandle.type = DRM_API_HANDLE_TYPE_SHARED;
- break;
- }
- res = screen->resource_get_handle(screen, srf->tex, &whandle);
+ whandle.type = handle_type(type);
+ res = screen->resource_get_handle(screen, srf->xa->default_ctx->pipe,
+ srf->tex, &whandle,
+ PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE);
if (!res)
return -XA_ERR_INVAL;