gl-renderer: do not expose query_dmabuf_formats and query_dmabuf_modifiers
In commit "libweston: add struct weston_drm_format" struct weston_drm_format and its helper functions were added to libweston. The functions query_dmabuf_formats and query_dmabuf_modifiers are very specific to GL-renderer and its internals. So instead of exposing them in libweston, query and store DRM formats and modifiers internally in GL-renderer. Also, add a vfunction to struct weston_renderer in order to retrieve the formats. Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
committed by
Daniel Stone
parent
a5560d6dbe
commit
1b403263d4
@@ -919,6 +919,8 @@ struct weston_plane {
|
|||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct weston_drm_format_array;
|
||||||
|
|
||||||
struct weston_renderer {
|
struct weston_renderer {
|
||||||
int (*read_pixels)(struct weston_output *output,
|
int (*read_pixels)(struct weston_output *output,
|
||||||
pixman_format_code_t format, void *pixels,
|
pixman_format_code_t format, void *pixels,
|
||||||
@@ -948,14 +950,8 @@ struct weston_renderer {
|
|||||||
bool (*import_dmabuf)(struct weston_compositor *ec,
|
bool (*import_dmabuf)(struct weston_compositor *ec,
|
||||||
struct linux_dmabuf_buffer *buffer);
|
struct linux_dmabuf_buffer *buffer);
|
||||||
|
|
||||||
/** On error sets num_formats to zero */
|
const struct weston_drm_format_array *
|
||||||
void (*query_dmabuf_formats)(struct weston_compositor *ec,
|
(*get_supported_formats)(struct weston_compositor *ec);
|
||||||
int **formats, int *num_formats);
|
|
||||||
|
|
||||||
/** On error sets num_modifiers to zero */
|
|
||||||
void (*query_dmabuf_modifiers)(struct weston_compositor *ec,
|
|
||||||
int format, uint64_t **modifiers,
|
|
||||||
int *num_modifiers);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum weston_capability {
|
enum weston_capability {
|
||||||
|
|||||||
+16
-34
@@ -477,12 +477,12 @@ bind_linux_dmabuf(struct wl_client *client,
|
|||||||
void *data, uint32_t version, uint32_t id)
|
void *data, uint32_t version, uint32_t id)
|
||||||
{
|
{
|
||||||
struct weston_compositor *compositor = data;
|
struct weston_compositor *compositor = data;
|
||||||
|
const struct weston_drm_format_array *supported_formats;
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
int *formats = NULL;
|
struct weston_drm_format *fmt;
|
||||||
uint64_t *modifiers = NULL;
|
const uint64_t *modifiers;
|
||||||
int num_formats, num_modifiers;
|
unsigned int num_modifiers;
|
||||||
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
unsigned int i;
|
||||||
int i, j;
|
|
||||||
|
|
||||||
resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
|
resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
|
||||||
version, id);
|
version, id);
|
||||||
@@ -494,43 +494,25 @@ bind_linux_dmabuf(struct wl_client *client,
|
|||||||
wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
|
wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
|
||||||
compositor, NULL);
|
compositor, NULL);
|
||||||
|
|
||||||
/*
|
/* Advertise the formats/modifiers */
|
||||||
* Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
|
supported_formats = compositor->renderer->get_supported_formats(compositor);
|
||||||
* format/modifier codes.
|
wl_array_for_each(fmt, &supported_formats->arr) {
|
||||||
*/
|
modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
|
||||||
compositor->renderer->query_dmabuf_formats(compositor, &formats,
|
for (i = 0; i < num_modifiers; i++) {
|
||||||
&num_formats);
|
|
||||||
|
|
||||||
for (i = 0; i < num_formats; i++) {
|
|
||||||
compositor->renderer->query_dmabuf_modifiers(compositor,
|
|
||||||
formats[i],
|
|
||||||
&modifiers,
|
|
||||||
&num_modifiers);
|
|
||||||
|
|
||||||
/* send DRM_FORMAT_MOD_INVALID token when no modifiers are supported
|
|
||||||
* for this format */
|
|
||||||
if (num_modifiers == 0) {
|
|
||||||
num_modifiers = 1;
|
|
||||||
modifiers = &modifier_invalid;
|
|
||||||
}
|
|
||||||
for (j = 0; j < num_modifiers; j++) {
|
|
||||||
if (version >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) {
|
if (version >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) {
|
||||||
uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
|
uint32_t modifier_lo = modifiers[i] & 0xFFFFFFFF;
|
||||||
uint32_t modifier_hi = modifiers[j] >> 32;
|
uint32_t modifier_hi = modifiers[i] >> 32;
|
||||||
zwp_linux_dmabuf_v1_send_modifier(resource,
|
zwp_linux_dmabuf_v1_send_modifier(resource,
|
||||||
formats[i],
|
fmt->format,
|
||||||
modifier_hi,
|
modifier_hi,
|
||||||
modifier_lo);
|
modifier_lo);
|
||||||
} else if (modifiers[j] == DRM_FORMAT_MOD_LINEAR ||
|
} else if (modifiers[i] == DRM_FORMAT_MOD_LINEAR ||
|
||||||
modifiers == &modifier_invalid) {
|
modifiers[i] == DRM_FORMAT_MOD_INVALID) {
|
||||||
zwp_linux_dmabuf_v1_send_format(resource,
|
zwp_linux_dmabuf_v1_send_format(resource,
|
||||||
formats[i]);
|
fmt->format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (modifiers != &modifier_invalid)
|
|
||||||
free(modifiers);
|
|
||||||
}
|
}
|
||||||
free(formats);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Advertise linux_dmabuf support
|
/** Advertise linux_dmabuf support
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ struct gl_renderer {
|
|||||||
struct wl_array vertices;
|
struct wl_array vertices;
|
||||||
struct wl_array vtxcnt;
|
struct wl_array vtxcnt;
|
||||||
|
|
||||||
|
struct weston_drm_format_array supported_formats;
|
||||||
|
|
||||||
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
|
||||||
PFNEGLCREATEIMAGEKHRPROC create_image;
|
PFNEGLCREATEIMAGEKHRPROC create_image;
|
||||||
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
|
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
|
||||||
|
|||||||
@@ -2777,6 +2777,63 @@ gl_renderer_attach_dmabuf(struct weston_surface *surface,
|
|||||||
gs->shader_variant = image->shader_variant;
|
gs->shader_variant = image->shader_variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct weston_drm_format_array *
|
||||||
|
gl_renderer_get_supported_formats(struct weston_compositor *ec)
|
||||||
|
{
|
||||||
|
struct gl_renderer *gr = get_renderer(ec);
|
||||||
|
|
||||||
|
return &gr->supported_formats;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
populate_supported_formats(struct weston_compositor *ec,
|
||||||
|
struct weston_drm_format_array *supported_formats)
|
||||||
|
{
|
||||||
|
struct weston_drm_format *fmt;
|
||||||
|
int *formats = NULL;
|
||||||
|
uint64_t *modifiers = NULL;
|
||||||
|
unsigned int num_formats, num_modifiers;
|
||||||
|
unsigned int i, j;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
/* Use EGL_EXT_image_dma_buf_import_modifiers to query the
|
||||||
|
* list of formats/modifiers of the renderer. */
|
||||||
|
gl_renderer_query_dmabuf_formats(ec, &formats, &num_formats);
|
||||||
|
if (num_formats == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < num_formats; i++) {
|
||||||
|
fmt = weston_drm_format_array_add_format(supported_formats,
|
||||||
|
formats[i]);
|
||||||
|
if (!fmt) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_renderer_query_dmabuf_modifiers(ec, formats[i],
|
||||||
|
&modifiers, &num_modifiers);
|
||||||
|
if (num_modifiers == 0) {
|
||||||
|
ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID);
|
||||||
|
if (ret < 0)
|
||||||
|
goto out;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < num_modifiers; j++) {
|
||||||
|
ret = weston_drm_format_add_modifier(fmt, modifiers[j]);
|
||||||
|
if (ret < 0) {
|
||||||
|
free(modifiers);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(formats);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
|
gl_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
|
||||||
{
|
{
|
||||||
@@ -3423,6 +3480,8 @@ gl_renderer_destroy(struct weston_compositor *ec)
|
|||||||
wl_list_for_each_safe(format, next_format, &gr->dmabuf_formats, link)
|
wl_list_for_each_safe(format, next_format, &gr->dmabuf_formats, link)
|
||||||
dmabuf_format_destroy(format);
|
dmabuf_format_destroy(format);
|
||||||
|
|
||||||
|
weston_drm_format_array_fini(&gr->supported_formats);
|
||||||
|
|
||||||
if (gr->dummy_surface != EGL_NO_SURFACE)
|
if (gr->dummy_surface != EGL_NO_SURFACE)
|
||||||
weston_platform_destroy_egl_surface(gr->egl_display,
|
weston_platform_destroy_egl_surface(gr->egl_display,
|
||||||
gr->dummy_surface);
|
gr->dummy_surface);
|
||||||
@@ -3495,6 +3554,7 @@ gl_renderer_display_create(struct weston_compositor *ec,
|
|||||||
const struct gl_renderer_display_options *options)
|
const struct gl_renderer_display_options *options)
|
||||||
{
|
{
|
||||||
struct gl_renderer *gr;
|
struct gl_renderer *gr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
gr = zalloc(sizeof *gr);
|
gr = zalloc(sizeof *gr);
|
||||||
if (gr == NULL)
|
if (gr == NULL)
|
||||||
@@ -3524,6 +3584,8 @@ gl_renderer_display_create(struct weston_compositor *ec,
|
|||||||
if (gl_renderer_setup_egl_display(gr, options->egl_native_display) < 0)
|
if (gl_renderer_setup_egl_display(gr, options->egl_native_display) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
weston_drm_format_array_init(&gr->supported_formats);
|
||||||
|
|
||||||
log_egl_info(gr->egl_display);
|
log_egl_info(gr->egl_display);
|
||||||
|
|
||||||
ec->renderer = &gr->base;
|
ec->renderer = &gr->base;
|
||||||
@@ -3557,10 +3619,10 @@ gl_renderer_display_create(struct weston_compositor *ec,
|
|||||||
wl_list_init(&gr->dmabuf_images);
|
wl_list_init(&gr->dmabuf_images);
|
||||||
if (gr->has_dmabuf_import) {
|
if (gr->has_dmabuf_import) {
|
||||||
gr->base.import_dmabuf = gl_renderer_import_dmabuf;
|
gr->base.import_dmabuf = gl_renderer_import_dmabuf;
|
||||||
gr->base.query_dmabuf_formats =
|
gr->base.get_supported_formats = gl_renderer_get_supported_formats;
|
||||||
gl_renderer_query_dmabuf_formats;
|
ret = populate_supported_formats(ec, &gr->supported_formats);
|
||||||
gr->base.query_dmabuf_modifiers =
|
if (ret < 0)
|
||||||
gl_renderer_query_dmabuf_modifiers;
|
goto fail_terminate;
|
||||||
}
|
}
|
||||||
wl_list_init(&gr->dmabuf_formats);
|
wl_list_init(&gr->dmabuf_formats);
|
||||||
|
|
||||||
@@ -3598,6 +3660,7 @@ gl_renderer_display_create(struct weston_compositor *ec,
|
|||||||
fail_with_error:
|
fail_with_error:
|
||||||
gl_renderer_print_egl_error_state();
|
gl_renderer_print_egl_error_state();
|
||||||
fail_terminate:
|
fail_terminate:
|
||||||
|
weston_drm_format_array_fini(&gr->supported_formats);
|
||||||
eglTerminate(gr->egl_display);
|
eglTerminate(gr->egl_display);
|
||||||
fail:
|
fail:
|
||||||
weston_log_scope_destroy(gr->shader_scope);
|
weston_log_scope_destroy(gr->shader_scope);
|
||||||
|
|||||||
Reference in New Issue
Block a user