struct xa_tracker * xa_tracker_create(int drm_fd) { struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker)); enum xa_surface_type stype; unsigned int num_formats; if (!xa) return NULL; xa->screen = driver_descriptor.create_screen(drm_fd); if (!xa->screen) goto out_no_screen; xa->default_ctx = xa_context_create(xa); if (!xa->default_ctx) goto out_no_pipe; num_formats = 0; for (stype = 0; stype < XA_LAST_SURFACE_TYPE; ++stype) num_formats += num_preferred[stype]; num_formats += 1; xa->supported_formats = calloc(num_formats, sizeof(*xa->supported_formats)); if (!xa->supported_formats) goto out_sf_alloc_fail; xa->supported_formats[0] = xa_format_unknown; num_formats = 1; memset(xa->format_map, 0, sizeof(xa->format_map)); for (stype = 0; stype < XA_LAST_SURFACE_TYPE; ++stype) { unsigned int bind = stype_bind[stype]; enum xa_formats xa_format; int i; for (i = 0; i < num_preferred[stype]; ++i) { xa_format = preferred[stype][i]; struct xa_format_descriptor fdesc = xa_get_pipe_format(xa_format); if (xa->screen->is_format_supported(xa->screen, fdesc.format, PIPE_TEXTURE_2D, 0, bind)) { if (xa->format_map[stype][0] == 0) xa->format_map[stype][0] = num_formats; xa->format_map[stype][1] = num_formats; xa->supported_formats[num_formats++] = xa_format; } } } return xa; out_sf_alloc_fail: xa_context_destroy(xa->default_ctx); out_no_pipe: xa->screen->destroy(xa->screen); out_no_screen: free(xa); return NULL; }
static struct xa_format_descriptor xa_get_format_stype_depth(struct xa_tracker *xa, enum xa_surface_type stype, unsigned int depth) { unsigned int i; struct xa_format_descriptor fdesc; 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]); if (fdesc.xa_format != xa_format_unknown && xa_format_depth(fdesc.xa_format) == depth) { found = 1; break; } } if (!found) fdesc.xa_format = xa_format_unknown; return fdesc; }
int 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); unsigned int bind; if (fdesc.xa_format == xa_format_unknown) return -XA_ERR_INVAL; bind = stype_bind[xa_format_type(fdesc.xa_format)]; if (flags & XA_FLAG_SHARED) bind |= PIPE_BIND_SHARED; if (flags & XA_FLAG_RENDER_TARGET) bind |= PIPE_BIND_RENDER_TARGET; if (!xa->screen->is_format_supported(xa->screen, fdesc.format, PIPE_TEXTURE_2D, 0, bind)) return -XA_ERR_INVAL; return XA_ERR_NONE; }
struct xa_surface * xa_surface_create(struct xa_tracker *xa, int width, int height, int depth, enum xa_surface_type stype, enum xa_formats xa_format, unsigned int flags) { struct pipe_resource *template; struct xa_surface *srf; struct xa_format_descriptor fdesc; if (xa_format == xa_format_unknown) fdesc = xa_get_format_stype_depth(xa, stype, depth); else fdesc = xa_get_pipe_format(xa_format); if (fdesc.xa_format == xa_format_unknown) return NULL; srf = calloc(1, sizeof(*srf)); if (!srf) return NULL;
XA_EXPORT struct xa_tracker * xa_tracker_create(int drm_fd) { 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 (!xa->screen) goto out_no_screen; xa->default_ctx = xa_context_create(xa); if (!xa->default_ctx) goto out_no_pipe; num_formats = 0; for (stype = 0; stype < XA_LAST_SURFACE_TYPE; ++stype) num_formats += num_preferred[stype]; num_formats += 1; xa->supported_formats = calloc(num_formats, sizeof(*xa->supported_formats)); if (!xa->supported_formats) goto out_sf_alloc_fail; xa->supported_formats[0] = xa_format_unknown; num_formats = 1; memset(xa->format_map, 0, sizeof(xa->format_map)); for (stype = 0; stype < XA_LAST_SURFACE_TYPE; ++stype) { unsigned int bind = stype_bind[stype]; enum xa_formats xa_format; int i; for (i = 0; i < num_preferred[stype]; ++i) { xa_format = preferred[stype][i]; struct xa_format_descriptor fdesc = xa_get_pipe_format(xa_format); if (xa->screen->is_format_supported(xa->screen, fdesc.format, PIPE_TEXTURE_2D, 0, bind)) { if (xa->format_map[stype][0] == 0) xa->format_map[stype][0] = num_formats; xa->format_map[stype][1] = num_formats; xa->supported_formats[num_formats++] = xa_format; } } } return xa; out_sf_alloc_fail: xa_context_destroy(xa->default_ctx); 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; }