Skip to content
Commits on Source (8)
......@@ -43,7 +43,7 @@
variables:
FDO_UPSTREAM_REPO: wayland/weston
FDO_REPO_SUFFIX: "$BUILD_OS/$BUILD_ARCH"
FDO_DISTRIBUTION_TAG: '2021-11-25.2-bullseye-sphinx'
FDO_DISTRIBUTION_TAG: '2021-11-25.0-dmabuf-feedback'
include:
......
......@@ -106,14 +106,12 @@ rm -rf wayland
# Keep this version in sync with our dependency in meson.build. If you wish to
# raise a MR against custom protocol, please change this reference to clone
# your relevant tree, and make sure you bump $FDO_DISTRIBUTION_TAG.
git clone --branch 1.19 https://gitlab.freedesktop.org/wayland/wayland-protocols
git clone --branch 1.24 --depth=1 https://gitlab.freedesktop.org/wayland/wayland-protocols
cd wayland-protocols
git show -s HEAD
mkdir build
cd build
../autogen.sh
make install
cd ../../
meson build
ninja ${NINJAFLAGS} -C build install
cd ..
rm -rf wayland-protocols
# Build and install our own version of Mesa. Debian provides a perfectly usable
......@@ -123,9 +121,8 @@ rm -rf wayland-protocols
# features from Mesa then bump this version and $FDO_DISTRIBUTION_TAG, however
# please be prepared for some of the tests to change output, which will need to
# be manually inspected for correctness.
git clone --single-branch --branch 20.3 --shallow-since='2020-12-15' https://gitlab.freedesktop.org/mesa/mesa.git mesa
git clone --branch 21.3 --depth=1 https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
git checkout -b snapshot mesa-20.3.1
meson build -Dauto_features=disabled \
-Dgallium-drivers=swrast -Dvulkan-drivers= -Ddri-drivers=
ninja ${NINJAFLAGS} -C build install
......
......@@ -50,6 +50,26 @@ simple_clients = [
],
'dep_objs': [ dep_wayland_client, dep_libshared ]
},
{
'name': 'dmabuf-feedback',
'sources': [
'simple-dmabuf-feedback.c',
'../libweston/pixel-formats.c',
linux_dmabuf_unstable_v1_client_protocol_h,
linux_dmabuf_unstable_v1_protocol_c,
xdg_shell_client_protocol_h,
xdg_shell_protocol_c,
],
'dep_objs': [
dep_wayland_client,
dep_libshared,
dep_pixman,
dep_libdrm,
dependency('libudev', version: '>= 136'),
],
'deps': [ 'egl', 'glesv2', 'gbm' ],
'options': [ 'renderer-gl' ]
},
{
'name': 'dmabuf-egl',
'sources': [
......
This diff is collapsed.
......@@ -1054,6 +1054,8 @@ struct weston_desktop_xwayland;
struct weston_desktop_xwayland_interface;
struct weston_debug_compositor;
struct weston_color_manager;
struct weston_dmabuf_feedback;
struct weston_dmabuf_feedback_format_table;
/** Main object, container-like structure which aggregates all other objects.
*
......@@ -1129,6 +1131,9 @@ struct weston_compositor {
struct weston_backend *backend;
struct weston_launcher *launcher;
struct weston_dmabuf_feedback *default_dmabuf_feedback;
struct weston_dmabuf_feedback_format_table *dmabuf_feedback_format_table;
struct wl_list plugin_api_list; /* struct weston_plugin_api::link */
uint32_t output_id_pool;
......@@ -1538,6 +1543,8 @@ struct weston_surface {
int acquire_fence_fd;
struct weston_buffer_release_reference buffer_release_ref;
struct weston_dmabuf_feedback *dmabuf_feedback;
enum weston_hdcp_protection desired_protection;
enum weston_hdcp_protection current_protection;
enum weston_surface_protection_mode protection_mode;
......
......@@ -227,6 +227,27 @@ enum wdrm_crtc_property {
WDRM_CRTC__COUNT
};
/**
* Reasons why placing a view on a plane failed. Needed by the dma-buf feedback.
*/
enum try_view_on_plane_failure_reasons {
FAILURE_REASONS_NONE = 0,
FAILURE_REASONS_FORCE_RENDERER = (1 << 0),
FAILURE_REASONS_FB_FORMAT_INCOMPATIBLE = (1 << 1),
FAILURE_REASONS_DMABUF_MODIFIER_INVALID = (1 << 2),
FAILURE_REASONS_ADD_FB_FAILED = (1 << 3),
};
/**
* We use this to keep track of actions we need to do with the dma-buf feedback
* in order to keep it up-to-date with the info we get from the DRM-backend.
*/
enum actions_needed_dmabuf_feedback {
ACTION_NEEDED_NONE = 0,
ACTION_NEEDED_ADD_SCANOUT_TRANCHE = (1 << 0),
ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE = (1 << 1),
};
struct drm_backend {
struct weston_backend base;
struct weston_compositor *compositor;
......@@ -694,13 +715,15 @@ drm_output_set_cursor_view(struct drm_output *output, struct weston_view *ev);
#ifdef BUILD_DRM_GBM
extern struct drm_fb *
drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev);
drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
uint32_t *try_view_on_plane_failure_reasons);
extern bool
drm_can_scanout_dmabuf(struct weston_compositor *ec,
struct linux_dmabuf_buffer *dmabuf);
#else
static inline struct drm_fb *
drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
uint32_t *try_view_on_plane_failure_reasons)
{
return NULL;
}
......
......@@ -1669,6 +1669,65 @@ drm_output_deinit_planes(struct drm_output *output)
output->scanout_plane = NULL;
}
static struct weston_drm_format_array *
get_scanout_formats(struct drm_backend *b)
{
struct weston_compositor *ec = b->compositor;
const struct weston_drm_format_array *renderer_formats;
struct weston_drm_format_array *scanout_formats, union_planes_formats;
struct drm_plane *plane;
int ret;
/* If we got here it means that dma-buf feedback is supported and that
* the renderer has formats/modifiers to expose. */
assert(ec->renderer->get_supported_formats != NULL);
renderer_formats = ec->renderer->get_supported_formats(ec);
scanout_formats = zalloc(sizeof(*scanout_formats));
if (!scanout_formats) {
weston_log("%s: out of memory\n", __func__);
return NULL;
}
weston_drm_format_array_init(&union_planes_formats);
weston_drm_format_array_init(scanout_formats);
/* Compute the union of the format/modifiers of the KMS planes */
wl_list_for_each(plane, &b->plane_list, link) {
/* The scanout formats are used by the dma-buf feedback. But for
* now cursor planes do not support dma-buf buffers, only wl_shm
* buffers. So we skip cursor planes here. */
if (plane->type == WDRM_PLANE_TYPE_CURSOR)
continue;
ret = weston_drm_format_array_join(&union_planes_formats,
&plane->formats);
if (ret < 0)
goto err;
}
/* Compute the intersection between the union of format/modifiers of KMS
* planes and the formats supported by the renderer */
ret = weston_drm_format_array_replace(scanout_formats,
renderer_formats);
if (ret < 0)
goto err;
ret = weston_drm_format_array_intersect(scanout_formats,
&union_planes_formats);
if (ret < 0)
goto err;
weston_drm_format_array_fini(&union_planes_formats);
return scanout_formats;
err:
weston_drm_format_array_fini(&union_planes_formats);
weston_drm_format_array_fini(scanout_formats);
return NULL;
}
/** Pick a CRTC and reserve it for the output.
*
* On failure, the output remains without a CRTC.
......@@ -2917,6 +2976,7 @@ drm_backend_create(struct weston_compositor *compositor,
struct wl_event_loop *loop;
const char *seat_id = default_seat;
const char *session_seat;
struct weston_drm_format_array *scanout_formats;
drmModeRes *res;
int ret;
......@@ -3082,6 +3142,21 @@ drm_backend_create(struct weston_compositor *compositor,
if (linux_dmabuf_setup(compositor) < 0)
weston_log("Error: initializing dmabuf "
"support failed.\n");
if (compositor->default_dmabuf_feedback) {
/* We were able to create the compositor's default
* dma-buf feedback in the renderer, that means that the
* table was already created and populated with
* renderer's format/modifier pairs. So now we must
* compute the scanout formats indices in the table */
scanout_formats = get_scanout_formats(b);
if (!scanout_formats)
goto err_udev_monitor;
ret = weston_dmabuf_feedback_format_table_set_scanout_indices(compositor->dmabuf_feedback_format_table,
scanout_formats);
weston_drm_format_array_fini(scanout_formats);
if (ret < 0)
goto err_udev_monitor;
}
if (weston_direct_display_setup(compositor) < 0)
weston_log("Error: initializing direct-display "
"support failed.\n");
......
......@@ -220,7 +220,8 @@ drm_fb_destroy_dmabuf(struct drm_fb *fb)
static struct drm_fb *
drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
struct drm_backend *backend, bool is_opaque)
struct drm_backend *backend, bool is_opaque,
uint32_t *try_view_on_plane_failure_reasons)
{
#ifndef HAVE_GBM_FD_IMPORT
/* Importing a buffer to KMS requires explicit modifiers, so
......@@ -245,8 +246,12 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
* KMS driver can't know. So giving the buffer to KMS is not safe, as
* not knowing its layout can result in garbage being displayed. In
* short, importing a buffer to KMS requires explicit modifiers. */
if (dmabuf->attributes.modifier[0] == DRM_FORMAT_MOD_INVALID)
if (dmabuf->attributes.modifier[0] == DRM_FORMAT_MOD_INVALID) {
if (try_view_on_plane_failure_reasons)
*try_view_on_plane_failure_reasons |=
FAILURE_REASONS_DMABUF_MODIFIER_INVALID;
return NULL;
}
/* XXX: TODO:
*
......@@ -313,8 +318,12 @@ drm_fb_get_from_dmabuf(struct linux_dmabuf_buffer *dmabuf,
fb->handles[i] = handle.u32;
}
if (drm_fb_addfb(backend, fb) != 0)
if (drm_fb_addfb(backend, fb) != 0) {
if (try_view_on_plane_failure_reasons)
*try_view_on_plane_failure_reasons |=
FAILURE_REASONS_ADD_FB_FAILED;
goto err_free;
}
return fb;
......@@ -455,7 +464,7 @@ drm_can_scanout_dmabuf(struct weston_compositor *ec,
struct drm_backend *b = to_drm_backend(ec);
bool ret = false;
fb = drm_fb_get_from_dmabuf(dmabuf, b, true);
fb = drm_fb_get_from_dmabuf(dmabuf, b, true, NULL);
if (fb)
ret = true;
......@@ -466,7 +475,8 @@ drm_can_scanout_dmabuf(struct weston_compositor *ec,
}
struct drm_fb *
drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev,
uint32_t *try_view_on_plane_failure_reasons)
{
struct drm_output *output = state->output;
struct drm_backend *b = to_drm_backend(output->base.compositor);
......@@ -497,7 +507,8 @@ drm_fb_get_from_view(struct drm_output_state *state, struct weston_view *ev)
dmabuf = linux_dmabuf_buffer_get(buffer->resource);
if (dmabuf) {
fb = drm_fb_get_from_dmabuf(dmabuf, b, is_opaque);
fb = drm_fb_get_from_dmabuf(dmabuf, b, is_opaque,
try_view_on_plane_failure_reasons);
if (!fb)
return NULL;
} else {
......
......@@ -649,12 +649,108 @@ drm_output_check_zpos_plane_states(struct drm_output_state *state)
}
}
static bool
dmabuf_feedback_maybe_update(struct drm_backend *b, struct weston_view *ev,
uint32_t try_view_on_plane_failure_reasons)
{
struct weston_dmabuf_feedback *dmabuf_feedback = ev->surface->dmabuf_feedback;
struct weston_dmabuf_feedback_tranche *scanout_tranche;
dev_t scanout_dev = b->drm.devnum;
uint32_t scanout_flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT;
uint32_t action_needed = ACTION_NEEDED_NONE;
struct timespec current_time, delta_time;
const time_t MAX_TIME_SECONDS = 2;
/* Find out what we need to do with the dma-buf feedback */
if (try_view_on_plane_failure_reasons & FAILURE_REASONS_FORCE_RENDERER)
action_needed |= ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE;
if (try_view_on_plane_failure_reasons &
(FAILURE_REASONS_ADD_FB_FAILED |
FAILURE_REASONS_FB_FORMAT_INCOMPATIBLE |
FAILURE_REASONS_DMABUF_MODIFIER_INVALID))
action_needed |= ACTION_NEEDED_ADD_SCANOUT_TRANCHE;
assert(action_needed != (ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE |
ACTION_NEEDED_ADD_SCANOUT_TRANCHE));
/* Look for scanout tranche. If not found, add it but in disabled mode
* (we still don't know if we'll have to send it to clients). This
* simplifies the code. */
scanout_tranche =
weston_dmabuf_feedback_find_tranche(dmabuf_feedback, scanout_dev,
scanout_flags, SCANOUT_PREF);
if (!scanout_tranche) {
scanout_tranche =
weston_dmabuf_feedback_tranche_create(dmabuf_feedback,
b->compositor->dmabuf_feedback_format_table,
scanout_dev, scanout_flags,
SCANOUT_PREF);
scanout_tranche->active = false;
}
/* No actions needed, so disarm timer and return */
if (action_needed == ACTION_NEEDED_NONE ||
(action_needed == ACTION_NEEDED_ADD_SCANOUT_TRANCHE &&
scanout_tranche->active) ||
(action_needed == ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE &&
!scanout_tranche->active)) {
dmabuf_feedback->action_needed = ACTION_NEEDED_NONE;
return false;
}
/* We hit this if:
*
* 1. timer is still off, or
* 2. the action needed when it was set to on does not match the most
* recent needed action we've detected.
*
* So we reset the timestamp, set the timer to on it with the most
* recent needed action, return and leave the timer running. */
if (dmabuf_feedback->action_needed == ACTION_NEEDED_NONE ||
dmabuf_feedback->action_needed != action_needed) {
clock_gettime(CLOCK_MONOTONIC, &dmabuf_feedback->timer);
dmabuf_feedback->action_needed = action_needed;
return false;
/* Timer is already on and the action needed when it was set to on does
* not conflict with the most recent needed action we've detected. If
* more than MAX_TIME_SECONDS has passed, we need to resend the dma-buf
* feedback. Otherwise, return and leave the timer running. */
} else {
clock_gettime(CLOCK_MONOTONIC, &current_time);
delta_time.tv_sec = current_time.tv_sec -
dmabuf_feedback->timer.tv_sec;
if (delta_time.tv_sec < MAX_TIME_SECONDS)
return false;
}
/* If we got here it means that the timer has triggered, so we have
* pending actions with the dma-buf feedback. So we update and resend
* them. */
if (action_needed == ACTION_NEEDED_ADD_SCANOUT_TRANCHE)
scanout_tranche->active = true;
else if (action_needed == ACTION_NEEDED_REMOVE_SCANOUT_TRANCHE)
scanout_tranche->active = false;
else
assert(0);
drm_debug(b, "\t[repaint] Need to update and resend the "
"dma-buf feedback for surface of view %p\n", ev);
weston_dmabuf_feedback_send_all(dmabuf_feedback,
b->compositor->dmabuf_feedback_format_table);
/* Set the timer to off */
dmabuf_feedback->action_needed = ACTION_NEEDED_NONE;
return true;
}
static struct drm_plane_state *
drm_output_prepare_plane_view(struct drm_output_state *state,
struct weston_view *ev,
enum drm_output_propose_state_mode mode,
struct drm_plane_state *scanout_state,
uint64_t current_lowest_zpos)
uint64_t current_lowest_zpos,
uint32_t *try_view_on_plane_failure_reasons)
{
struct drm_output *output = state->output;
struct drm_backend *b = to_drm_backend(output->base.compositor);
......@@ -676,7 +772,7 @@ drm_output_prepare_plane_view(struct drm_output_state *state,
buffer = ev->surface->buffer_ref.buffer;
shmbuf = wl_shm_buffer_get(buffer->resource);
fb = drm_fb_get_from_view(state, ev);
fb = drm_fb_get_from_view(state, ev, try_view_on_plane_failure_reasons);
/* assemble a list with possible candidates */
wl_list_for_each(plane, &b->plane_list, link) {
......@@ -730,6 +826,8 @@ drm_output_prepare_plane_view(struct drm_output_state *state,
}
if (!drm_output_plane_view_has_valid_format(plane, state, ev, fb)) {
*try_view_on_plane_failure_reasons |=
FAILURE_REASONS_FB_FORMAT_INCOMPATIBLE;
drm_debug(b, "\t\t\t\t[plane] not adding plane %d to "
"candidate list: invalid pixel format\n",
plane->plane_id);
......@@ -960,7 +1058,18 @@ drm_output_propose_state(struct weston_output *output_base,
current_lowest_zpos);
ps = drm_output_prepare_plane_view(state, ev, mode,
scanout_state,
current_lowest_zpos);
current_lowest_zpos,
&pnode->try_view_on_plane_failure_reasons);
/* If we were able to place the view in a plane, set
* failure reasons to none. */
if (ps)
pnode->try_view_on_plane_failure_reasons =
FAILURE_REASONS_NONE;
} else {
/* We are forced to place the view in the renderer, set
* the failure reason accordingly. */
pnode->try_view_on_plane_failure_reasons =
FAILURE_REASONS_FORCE_RENDERER;
}
if (ps) {
......@@ -1093,6 +1202,12 @@ drm_assign_planes(struct weston_output *output_base, void *repaint_data)
if (!(ev->output_mask & (1u << output->base.id)))
continue;
/* Update dmabuf-feedback if needed */
if (ev->surface->dmabuf_feedback)
dmabuf_feedback_maybe_update(b, ev,
pnode->try_view_on_plane_failure_reasons);
pnode->try_view_on_plane_failure_reasons = FAILURE_REASONS_NONE;
/* Test whether this buffer can ever go into a plane:
* non-shm, or small enough to be a cursor.
*
......
......@@ -2313,6 +2313,9 @@ weston_surface_destroy(struct weston_surface *surface)
assert(wl_list_empty(&surface->subsurface_list_pending));
assert(wl_list_empty(&surface->subsurface_list));
if (surface->dmabuf_feedback)
weston_dmabuf_feedback_destroy(surface->dmabuf_feedback);
wl_list_for_each_safe(ev, nv, &surface->views, surface_link)
weston_view_destroy(ev);
......@@ -4038,31 +4041,65 @@ static const struct wl_surface_interface surface_interface = {
surface_damage_buffer
};
static int
create_surface_dmabuf_feedback(struct weston_compositor *ec,
struct weston_surface *surface)
{
struct weston_dmabuf_feedback_tranche *tranche;
dev_t main_device = ec->default_dmabuf_feedback->main_device;
uint32_t flags = 0;
surface->dmabuf_feedback = weston_dmabuf_feedback_create(main_device);
if (!surface->dmabuf_feedback)
return -1;
tranche = weston_dmabuf_feedback_tranche_create(surface->dmabuf_feedback,
ec->dmabuf_feedback_format_table,
main_device, flags,
RENDERER_PREF);
if (!tranche) {
weston_dmabuf_feedback_destroy(surface->dmabuf_feedback);
surface->dmabuf_feedback = NULL;
return -1;
}
return 0;
}
static void
compositor_create_surface(struct wl_client *client,
struct wl_resource *resource, uint32_t id)
{
struct weston_compositor *ec = wl_resource_get_user_data(resource);
struct weston_surface *surface;
int ret;
surface = weston_surface_create(ec);
if (surface == NULL) {
wl_resource_post_no_memory(resource);
return;
if (surface == NULL)
goto err;
if (ec->default_dmabuf_feedback) {
ret = create_surface_dmabuf_feedback(ec, surface);
if (ret < 0)
goto err_dmabuf_feedback;
}
surface->resource =
wl_resource_create(client, &wl_surface_interface,
wl_resource_get_version(resource), id);
if (surface->resource == NULL) {
weston_surface_destroy(surface);
wl_resource_post_no_memory(resource);
return;
}
if (surface->resource == NULL)
goto err_dmabuf_feedback;
wl_resource_set_implementation(surface->resource, &surface_interface,
surface, destroy_surface);
wl_signal_emit(&ec->create_surface_signal, surface);
return;
err_dmabuf_feedback:
weston_surface_destroy(surface);
err:
wl_resource_post_no_memory(resource);
}
static void
......@@ -8191,6 +8228,11 @@ weston_compositor_destroy(struct weston_compositor *compositor)
weston_log_scope_destroy(compositor->timeline);
compositor->timeline = NULL;
if (compositor->default_dmabuf_feedback) {
weston_dmabuf_feedback_destroy(compositor->default_dmabuf_feedback);
weston_dmabuf_feedback_format_table_destroy(compositor->dmabuf_feedback_format_table);
}
free(compositor);
}
......
......@@ -184,6 +184,24 @@ weston_drm_format_array_find_format(const struct weston_drm_format_array *format
return NULL;
}
/**
* Counts the number of format/modifier pairs in a weston_drm_format_array
*
* @param formats The weston_drm_format_array
* @return The number of format/modifier pairs in the array
*/
WL_EXPORT unsigned int
weston_drm_format_array_count_pairs(const struct weston_drm_format_array *formats)
{
struct weston_drm_format *fmt;
unsigned int num_pairs = 0;
wl_array_for_each(fmt, &formats->arr)
num_pairs += fmt->modifiers.size / sizeof(uint64_t);
return num_pairs;
}
/**
* Compare the content of two weston_drm_format_array
*
......
......@@ -358,6 +358,9 @@ struct weston_drm_format *
weston_drm_format_array_find_format(const struct weston_drm_format_array *formats,
uint32_t format);
unsigned int
weston_drm_format_array_count_pairs(const struct weston_drm_format_array *formats);
bool
weston_drm_format_array_equal(const struct weston_drm_format_array *formats_A,
const struct weston_drm_format_array *formats_B);
......@@ -413,6 +416,8 @@ struct weston_paint_node {
struct weston_surface_color_transform surf_xform;
bool surf_xform_valid;
uint32_t try_view_on_plane_failure_reasons;
};
struct weston_paint_node *
......
......@@ -26,13 +26,16 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <libweston/libweston.h>
#include "linux-dmabuf.h"
#include "linux-dmabuf-unstable-v1-server-protocol.h"
#include "shared/os-compatibility.h"
#include "libweston-internal.h"
#include "shared/weston-drm-fourcc.h"
......@@ -395,6 +398,489 @@ err_out:
wl_resource_post_no_memory(linux_dmabuf_resource);
}
/** Creates dma-buf feedback tranche
*
* The tranche is added to dma-buf feedback's tranche list
*
* @param dmabuf_feedback The dma-buf feedback object to which the tranche is added
* @param format_table The dma-buf feedback formats table
* @param target_device The target device of the new tranche
* @param flags The flags of the new tranche
* @param preference The preference of the new tranche
* @return The tranche created, or NULL on failure
*/
WL_EXPORT struct weston_dmabuf_feedback_tranche *
weston_dmabuf_feedback_tranche_create(struct weston_dmabuf_feedback *dmabuf_feedback,
struct weston_dmabuf_feedback_format_table *format_table,
dev_t target_device, uint32_t flags,
enum weston_dmabuf_feedback_tranche_preference preference)
{
struct weston_dmabuf_feedback_tranche *tranche, *ptr;
struct wl_list *pos;
tranche = zalloc(sizeof(*tranche));
if (!tranche) {
weston_log("%s: out of memory\n", __func__);
return NULL;
}
tranche->active = true;
tranche->target_device = target_device;
tranche->flags = flags;
tranche->preference = preference;
/* Get the formats indices array */
if (flags == 0) {
if (wl_array_copy(&tranche->formats_indices,
&format_table->renderer_formats_indices) < 0) {
weston_log("%s: out of memory\n", __func__);
goto err;
}
} else if (flags & ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT) {
if (wl_array_copy(&tranche->formats_indices,
&format_table->scanout_formats_indices) < 0) {
weston_log("%s: out of memory\n", __func__);
goto err;
}
} else {
weston_log("error: for now we just have renderer and scanout "
"tranches, can't create other type of tranche\n");
goto err;
}
/* The list of tranches is ordered by preference.
* Highest preference comes first. */
pos = &dmabuf_feedback->tranche_list;
wl_list_for_each(ptr, &dmabuf_feedback->tranche_list, link) {
pos = &ptr->link;
if (ptr->preference <= tranche->preference)
break;
}
wl_list_insert(pos->prev, &tranche->link);
return tranche;
err:
free(tranche);
return NULL;
}
static void
weston_dmabuf_feedback_tranche_destroy(struct weston_dmabuf_feedback_tranche *tranche)
{
wl_array_release(&tranche->formats_indices);
wl_list_remove(&tranche->link);
free(tranche);
}
static int
format_table_add_renderer_formats(struct weston_dmabuf_feedback_format_table *format_table,
const struct weston_drm_format_array *renderer_formats)
{
struct weston_drm_format *fmt;
unsigned int num_modifiers;
const uint64_t *modifiers;
uint16_t index, *index_ptr;
unsigned int size;
unsigned int i;
size = sizeof(index) *
weston_drm_format_array_count_pairs(renderer_formats);
if (!wl_array_add(&format_table->renderer_formats_indices, size)) {
weston_log("%s: out of memory\n", __func__);
return -1;
}
index = 0;
wl_array_for_each(fmt, &renderer_formats->arr) {
modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
for (i = 0; i < num_modifiers; i++) {
format_table->data[index].format = fmt->format;
format_table->data[index].modifier = modifiers[i];
index++;
}
}
index = 0;
wl_array_for_each(index_ptr, &format_table->renderer_formats_indices)
*index_ptr = index++;
return 0;
}
/** Creates dma-buf feedback format table
*
* @param renderer_formats The formats that compose the table
* @return The dma-buf feedback format table, or NULL on failure
*/
WL_EXPORT struct weston_dmabuf_feedback_format_table *
weston_dmabuf_feedback_format_table_create(const struct weston_drm_format_array *renderer_formats)
{
struct weston_dmabuf_feedback_format_table *format_table;
int ret;
format_table = zalloc(sizeof(*format_table));
if (!format_table) {
weston_log("%s: out of memory\n", __func__);
return NULL;
}
wl_array_init(&format_table->renderer_formats_indices);
wl_array_init(&format_table->scanout_formats_indices);
/* Creates formats file table and mmap it */
format_table->size = weston_drm_format_array_count_pairs(renderer_formats) *
sizeof(*format_table->data);
format_table->fd = os_create_anonymous_file(format_table->size);
if (format_table->fd < 0) {
weston_log("error: failed to create format table file: %s\n",
strerror(errno));
goto err_fd;
}
format_table->data = mmap(NULL, format_table->size, PROT_READ | PROT_WRITE,
MAP_SHARED, format_table->fd, 0);
if (format_table->data == MAP_FAILED) {
weston_log("error: mmap for format table failed: %s\n",
strerror(errno));
goto err_mmap;
}
/* Add renderer formats to file table */
ret = format_table_add_renderer_formats(format_table, renderer_formats);
if (ret < 0)
goto err_formats;
return format_table;
err_formats:
munmap(format_table->data, format_table->size);
err_mmap:
close(format_table->fd);
err_fd:
wl_array_release(&format_table->renderer_formats_indices);
free(format_table);
return NULL;
}
/** Destroys dma-buf feedback formats table
*
* @param format_table The dma-buf feedback format table to destroy
*/
WL_EXPORT void
weston_dmabuf_feedback_format_table_destroy(struct weston_dmabuf_feedback_format_table *format_table)
{
wl_array_release(&format_table->renderer_formats_indices);
wl_array_release(&format_table->scanout_formats_indices);
munmap(format_table->data, format_table->size);
close(format_table->fd);
free(format_table);
}
static int
format_table_get_format_index(struct weston_dmabuf_feedback_format_table *format_table,
uint32_t format, uint64_t modifier, uint16_t *index_out)
{
uint16_t index;
unsigned int num_elements = format_table->size / sizeof(index);
for (index = 0; index < num_elements; index++) {
if (format_table->data[index].format == format &&
format_table->data[index].modifier == modifier) {
*index_out = index;
return 0;
}
}
return -1;
}
/** Set scanout formats indices in the dma-buf feedback format table
*
* The table consists of the formats supported by the renderer. A dma-buf
* feedback scanout tranche consists of the union of the KMS plane's formats
* intersected with the renderer formats. With this function we compute the
* indices of these plane's formats in the table and save them in the
* table->scanout_formats_indices, allowing us to create scanout tranches.
*
* @param format_table The dma-buf feedback format table
* @param scanout_formats The scanout formats
* @return 0 on success, -1 on failure
*/
WL_EXPORT int
weston_dmabuf_feedback_format_table_set_scanout_indices(struct weston_dmabuf_feedback_format_table *format_table,
const struct weston_drm_format_array *scanout_formats)
{
struct weston_drm_format *fmt;
unsigned int num_modifiers;
const uint64_t *modifiers;
uint16_t index, *index_ptr;
unsigned int i;
int ret;
wl_array_for_each(fmt, &scanout_formats->arr) {
modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
for (i = 0; i < num_modifiers; i++) {
index_ptr =
wl_array_add(&format_table->scanout_formats_indices,
sizeof(index));
if (!index_ptr)
goto err;
ret = format_table_get_format_index(format_table, fmt->format,
modifiers[i], &index);
if (ret < 0)
goto err;
*index_ptr = index;
}
}
return 0;
err:
wl_array_release(&format_table->scanout_formats_indices);
wl_array_init(&format_table->scanout_formats_indices);
return -1;
}
/** Creates dma-buf feedback object
*
* @param main_device The main device of the dma-buf feedback
* @return The dma-buf feedback object created, or NULL on failure
*/
WL_EXPORT struct weston_dmabuf_feedback *
weston_dmabuf_feedback_create(dev_t main_device)
{
struct weston_dmabuf_feedback *dmabuf_feedback;
dmabuf_feedback = zalloc(sizeof(*dmabuf_feedback));
if (!dmabuf_feedback) {
weston_log("%s: out of memory\n", __func__);
return NULL;
}
dmabuf_feedback->main_device = main_device;
wl_list_init(&dmabuf_feedback->tranche_list);
wl_list_init(&dmabuf_feedback->resource_list);
return dmabuf_feedback;
}
/** Destroy dma-buf feedback object
*
* @param dmabuf_feedback The dma-buf feedback object to destroy
*/
WL_EXPORT void
weston_dmabuf_feedback_destroy(struct weston_dmabuf_feedback *dmabuf_feedback)
{
struct weston_dmabuf_feedback_tranche *tranche, *tranche_tmp;
struct wl_resource *res, *res_tmp;
wl_list_for_each_safe(tranche, tranche_tmp, &dmabuf_feedback->tranche_list, link)
weston_dmabuf_feedback_tranche_destroy(tranche);
wl_resource_for_each_safe(res, res_tmp, &dmabuf_feedback->resource_list) {
wl_list_remove(wl_resource_get_link(res));
wl_list_init(wl_resource_get_link(res));
}
free(dmabuf_feedback);
}
/** Find tranche in a dma-buf feedback object
*
* @param dmabuf_feedback The dma-buf feedback object where to look for
* @param target_device The target device of the tranche
* @param flags The flags of the tranche
* @param preference The preference of the tranche
* @return The tranche, or NULL if it was not found
*/
WL_EXPORT struct weston_dmabuf_feedback_tranche *
weston_dmabuf_feedback_find_tranche(struct weston_dmabuf_feedback *dmabuf_feedback,
dev_t target_device, uint32_t flags,
enum weston_dmabuf_feedback_tranche_preference preference)
{
struct weston_dmabuf_feedback_tranche *tranche;
wl_list_for_each(tranche, &dmabuf_feedback->tranche_list, link)
if (tranche->target_device == target_device &&
tranche->flags == flags && tranche->preference == preference)
return tranche;
return NULL;
}
static void
weston_dmabuf_feedback_send(struct weston_dmabuf_feedback *dmabuf_feedback,
struct weston_dmabuf_feedback_format_table *format_table,
struct wl_resource *res, bool advertise_format_table)
{
struct weston_dmabuf_feedback_tranche *tranche;
struct wl_array device;
dev_t *dev;
/* main_device and target_device events need a dev_t as parameter,
* but we can't use this directly to communicate with the Wayland
* client. The solution is to use a wl_array, which is supported by
* Wayland, and add the dev_t as an element of the array. */
wl_array_init(&device);
dev = wl_array_add(&device, sizeof(*dev));
if (!dev) {
wl_resource_post_no_memory(res);
return;
}
/* format_table event - In Weston, we never modify the dma-buf feedback
* format table. So we have this flag in order to advertise the format
* table only if the client has just subscribed to receive the events
* for this feedback object. When we need to re-send the feedback events
* for this client, the table event won't be sent. */
if (advertise_format_table)
zwp_linux_dmabuf_feedback_v1_send_format_table(res, format_table->fd,
format_table->size);
/* main_device event */
*dev = dmabuf_feedback->main_device;
zwp_linux_dmabuf_feedback_v1_send_main_device(res, &device);
/* send events for each tranche */
wl_list_for_each(tranche, &dmabuf_feedback->tranche_list, link) {
if (!tranche->active)
continue;
/* tranche_target_device event */
*dev = tranche->target_device;
zwp_linux_dmabuf_feedback_v1_send_tranche_target_device(res, &device);
/* tranche_flags event */
zwp_linux_dmabuf_feedback_v1_send_tranche_flags(res, tranche->flags);
/* tranche_formats event */
zwp_linux_dmabuf_feedback_v1_send_tranche_formats(res, &tranche->formats_indices);
/* tranche_done_event */
zwp_linux_dmabuf_feedback_v1_send_tranche_done(res);
}
/* compositor_done_event */
zwp_linux_dmabuf_feedback_v1_send_done(res);
wl_array_release(&device);
}
/** Sends the feedback events for a dma-buf feedback object
*
* Given a dma-buf feedback object, this will send events to clients that are
* subscribed to it. This is useful for the per-surface dma-buf feedback, which
* is dynamic and can change throughout compositor's life. These changes results
* in the need to resend the feedback events to clients.
*
* @param dmabuf_feedback The weston_dmabuf_feedback object
* @param format_table The dma-buf feedback formats table
*/
WL_EXPORT void
weston_dmabuf_feedback_send_all(struct weston_dmabuf_feedback *dmabuf_feedback,
struct weston_dmabuf_feedback_format_table *format_table)
{
struct wl_resource *res;
wl_resource_for_each(res, &dmabuf_feedback->resource_list)
weston_dmabuf_feedback_send(dmabuf_feedback,
format_table, res, false);
}
static void
dmabuf_feedback_resource_destroy(struct wl_resource *resource)
{
wl_list_remove(wl_resource_get_link(resource));
}
static void
dmabuf_feedback_destroy(struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy(resource);
}
static const struct zwp_linux_dmabuf_feedback_v1_interface
zwp_linux_dmabuf_feedback_implementation = {
dmabuf_feedback_destroy
};
static struct wl_resource *
dmabuf_feedback_resource_create(struct wl_resource *dmabuf_resource,
struct wl_client *client, uint32_t dmabuf_feedback_id)
{
struct wl_resource *dmabuf_feedback_res;
uint32_t version;
version = wl_resource_get_version(dmabuf_resource);
dmabuf_feedback_res =
wl_resource_create(client, &zwp_linux_dmabuf_feedback_v1_interface,
version, dmabuf_feedback_id);
if (!dmabuf_feedback_res)
return NULL;
wl_list_init(wl_resource_get_link(dmabuf_feedback_res));
wl_resource_set_implementation(dmabuf_feedback_res,
&zwp_linux_dmabuf_feedback_implementation,
NULL, dmabuf_feedback_resource_destroy);
return dmabuf_feedback_res;
}
static void
linux_dmabuf_get_default_feedback(struct wl_client *client,
struct wl_resource *dmabuf_resource,
uint32_t dmabuf_feedback_id)
{
struct weston_compositor *compositor =
wl_resource_get_user_data(dmabuf_resource);
struct wl_resource *dmabuf_feedback_resource;
dmabuf_feedback_resource =
dmabuf_feedback_resource_create(dmabuf_resource,
client, dmabuf_feedback_id);
if (!dmabuf_feedback_resource) {
wl_resource_post_no_memory(dmabuf_resource);
return;
}
weston_dmabuf_feedback_send(compositor->default_dmabuf_feedback,
compositor->dmabuf_feedback_format_table,
dmabuf_feedback_resource, true);
}
static void
linux_dmabuf_get_per_surface_feedback(struct wl_client *client,
struct wl_resource *dmabuf_resource,
uint32_t dmabuf_feedback_id,
struct wl_resource *surface_resource)
{
struct weston_surface *surface =
wl_resource_get_user_data(surface_resource);
struct wl_resource *dmabuf_feedback_resource;
dmabuf_feedback_resource =
dmabuf_feedback_resource_create(dmabuf_resource,
client, dmabuf_feedback_id);
if (!dmabuf_feedback_resource) {
wl_resource_post_no_memory(dmabuf_resource);
return;
}
/* Surface dma-buf feedback is dynamic and may need to be resent to
* clients when they change. So we need to keep the resources list */
wl_list_insert(&surface->dmabuf_feedback->resource_list,
wl_resource_get_link(dmabuf_feedback_resource));
weston_dmabuf_feedback_send(surface->dmabuf_feedback,
surface->compositor->dmabuf_feedback_format_table,
dmabuf_feedback_resource, true);
}
/** Get the linux_dmabuf_buffer from a wl_buffer resource
*
* If the given wl_buffer resource was created through the linux_dmabuf
......@@ -469,7 +955,9 @@ linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer)
static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation = {
linux_dmabuf_destroy,
linux_dmabuf_create_params
linux_dmabuf_create_params,
linux_dmabuf_get_default_feedback,
linux_dmabuf_get_per_surface_feedback
};
static void
......@@ -494,8 +982,17 @@ bind_linux_dmabuf(struct wl_client *client,
wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
compositor, NULL);
/* Advertise the formats/modifiers */
/* Advertise formats/modifiers. From version 4 onwards, we should not send
* zwp_linux_dmabuf_v1_send_modifier and zwp_linux_dmabuf_v1_send_format
* events, instead we must send the dma-buf feedback events. */
if (version >= 4)
return;
/* If we got here, it means that the renderer is able to import dma-buf
* buffers, and so it must have get_supported_formats() set. */
assert(compositor->renderer->get_supported_formats != NULL);
supported_formats = compositor->renderer->get_supported_formats(compositor);
wl_array_for_each(fmt, &supported_formats->arr) {
modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers);
for (i = 0; i < num_modifiers; i++) {
......@@ -529,9 +1026,16 @@ bind_linux_dmabuf(struct wl_client *client,
WL_EXPORT int
linux_dmabuf_setup(struct weston_compositor *compositor)
{
int max_version;
/* If we were able to create the default dma-buf feedback for the
* compositor, that means that we are able to advertise dma-buf feedback
* events. In such case we support the version 4 of the protocol. */
max_version = compositor->default_dmabuf_feedback ? 4 : 3;
if (!wl_global_create(compositor->wl_display,
&zwp_linux_dmabuf_v1_interface, 3,
compositor, bind_linux_dmabuf))
&zwp_linux_dmabuf_v1_interface,
max_version, compositor, bind_linux_dmabuf))
return -1;
return 0;
......
......@@ -27,6 +27,7 @@
#define WESTON_LINUX_DMABUF_H
#include <stdint.h>
#include "linux-dmabuf-unstable-v1-server-protocol.h"
#define MAX_DMABUF_PLANES 4
......@@ -74,6 +75,76 @@ struct linux_dmabuf_buffer {
bool direct_display;
};
enum weston_dmabuf_feedback_tranche_preference {
RENDERER_PREF = 0,
SCANOUT_PREF = 1
};
struct weston_dmabuf_feedback_format_table {
int fd;
unsigned int size;
/* This is a pointer to the region of memory where we mapped the file
* that clients receive. We fill it with the format/modifier pairs
* supported by the renderer. We don't formats not supported by the
* renderer in the table, as we must always be able to fallback to the
* renderer if direct scanout fails. */
struct {
uint32_t format;
uint32_t pad; /* unused */
uint64_t modifier;
} *data;
/* Indices of the renderer formats in the table. As the table consists
* of formats supported by the renderer, this goes from 0 to the number
* of pairs in the table. */
struct wl_array renderer_formats_indices;
/* Indices of the scanout formats (union of KMS plane's supported
* formats intersected with the renderer formats). */
struct wl_array scanout_formats_indices;
};
struct weston_dmabuf_feedback {
/* We can have multiple clients subscribing to the same surface dma-buf
* feedback. As they are dynamic and we need to re-send them multiple
* times during Weston's lifetime, we need to keep track of the
* resources of each client. In the case of the default feedback this is
* not necessary, as we only advertise them when clients subscribe. IOW,
* default feedback events are never re-sent. */
struct wl_list resource_list;
dev_t main_device;
/* weston_dmabuf_feedback_tranche::link */
struct wl_list tranche_list;
/* We use this timer to know if the scene has stabilized and that would
* be useful to resend dma-buf feedback events to clients. Consider the
* timer off when action_needed == ACTION_NEEDED_NONE. See enum
* actions_needed_dmabuf_feedback. */
struct timespec timer;
uint32_t action_needed;
};
struct weston_dmabuf_feedback_tranche {
/* weston_dmabuf_feedback::tranche_list */
struct wl_list link;
/* Instead of destroying tranches and reconstructing them when necessary
* (it can be expensive), we have this flag to know if the tranche
* should be advertised or not. This is particularly useful for the
* scanout tranche, as based on the DRM-backend feedback and the current
* scene (which changes a lot during compositor lifetime) we can decide
* to send it or not. */
bool active;
dev_t target_device;
uint32_t flags;
enum weston_dmabuf_feedback_tranche_preference preference;
struct wl_array formats_indices;
};
int
linux_dmabuf_setup(struct weston_compositor *compositor);
......@@ -94,4 +165,35 @@ void
linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
const char *msg);
struct weston_dmabuf_feedback *
weston_dmabuf_feedback_create(dev_t main_device);
void
weston_dmabuf_feedback_destroy(struct weston_dmabuf_feedback *dmabuf_feedback);
void
weston_dmabuf_feedback_send_all(struct weston_dmabuf_feedback *dmabuf_feedback,
struct weston_dmabuf_feedback_format_table *format_table);
struct weston_dmabuf_feedback_tranche *
weston_dmabuf_feedback_find_tranche(struct weston_dmabuf_feedback *dmabuf_feedback,
dev_t target_device, uint32_t flags,
enum weston_dmabuf_feedback_tranche_preference preference);
struct weston_dmabuf_feedback_format_table *
weston_dmabuf_feedback_format_table_create(const struct weston_drm_format_array *renderer_formats);
void
weston_dmabuf_feedback_format_table_destroy(struct weston_dmabuf_feedback_format_table *format_table);
int
weston_dmabuf_feedback_format_table_set_scanout_indices(struct weston_dmabuf_feedback_format_table *format_table,
const struct weston_drm_format_array *scanout_formats);
struct weston_dmabuf_feedback_tranche *
weston_dmabuf_feedback_tranche_create(struct weston_dmabuf_feedback *dmabuf_feedback,
struct weston_dmabuf_feedback_format_table *format_table,
dev_t target_device, uint32_t flags,
enum weston_dmabuf_feedback_tranche_preference preference);
#endif /* WESTON_LINUX_DMABUF_H */
......@@ -455,6 +455,45 @@ gl_renderer_get_egl_config(struct gl_renderer *gr,
return egl_config;
}
static void
gl_renderer_set_egl_device(struct gl_renderer *gr)
{
EGLAttrib attrib;
const char *extensions;
assert(gr->has_device_query);
if (!gr->query_display_attrib(gr->egl_display, EGL_DEVICE_EXT, &attrib)) {
weston_log("failed to get EGL device\n");
gl_renderer_print_egl_error_state();
return;
}
gr->egl_device = (EGLDeviceEXT) attrib;
extensions = gr->query_device_string(gr->egl_device, EGL_EXTENSIONS);
if (!extensions) {
weston_log("failed to get EGL extensions\n");
return;
}
gl_renderer_log_extensions("EGL device extensions", extensions);
/* Try to query the render node using EGL_DRM_RENDER_NODE_FILE_EXT */
if (weston_check_egl_extension(extensions, "EGL_EXT_device_drm_render_node"))
gr->drm_device = gr->query_device_string(gr->egl_device,
EGL_DRM_RENDER_NODE_FILE_EXT);
/* The extension is not supported by the Mesa version of the system or
* the query failed. Fallback to EGL_DRM_DEVICE_FILE_EXT */
if (!gr->drm_device && weston_check_egl_extension(extensions, "EGL_EXT_device_drm"))
gr->drm_device = gr->query_device_string(gr->egl_device,
EGL_DRM_DEVICE_FILE_EXT);
if (!gr->drm_device)
weston_log("failed to query DRM device from EGL\n");
}
int
gl_renderer_setup_egl_display(struct gl_renderer *gr,
void *native_display)
......@@ -484,6 +523,9 @@ gl_renderer_setup_egl_display(struct gl_renderer *gr,
goto fail;
}
if (gr->has_device_query)
gl_renderer_set_egl_device(gr);
return 0;
fail:
......@@ -534,6 +576,14 @@ gl_renderer_setup_egl_client_extensions(struct gl_renderer *gr)
gl_renderer_log_extensions("EGL client extensions",
extensions);
if (weston_check_egl_extension(extensions, "EGL_EXT_device_query")) {
gr->query_display_attrib =
(void *) eglGetProcAddress("eglQueryDisplayAttribEXT");
gr->query_device_string =
(void *) eglGetProcAddress("eglQueryDeviceStringEXT");
gr->has_device_query = true;
}
if (weston_check_egl_extension(extensions, "EGL_EXT_platform_base")) {
gr->get_platform_display =
(void *) eglGetProcAddress("eglGetPlatformDisplayEXT");
......
......@@ -119,6 +119,9 @@ struct gl_renderer {
struct wl_array vertices;
struct wl_array vtxcnt;
EGLDeviceEXT egl_device;
const char *drm_device;
struct weston_drm_format_array supported_formats;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
......@@ -163,6 +166,10 @@ struct gl_renderer {
PFNEGLQUERYDMABUFFORMATSEXTPROC query_dmabuf_formats;
PFNEGLQUERYDMABUFMODIFIERSEXTPROC query_dmabuf_modifiers;
bool has_device_query;
PFNEGLQUERYDISPLAYATTRIBEXTPROC query_display_attrib;
PFNEGLQUERYDEVICESTRINGEXTPROC query_device_string;
bool has_native_fence_sync;
PFNEGLCREATESYNCKHRPROC create_sync;
PFNEGLDESTROYSYNCKHRPROC destroy_sync;
......
......@@ -35,6 +35,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <ctype.h>
#include <float.h>
#include <assert.h>
......@@ -3611,6 +3612,38 @@ gl_renderer_create_pbuffer_surface(struct gl_renderer *gr) {
return 0;
}
static int
create_default_dmabuf_feedback(struct weston_compositor *ec,
struct gl_renderer *gr)
{
struct stat dev_stat;
struct weston_dmabuf_feedback_tranche *tranche;
uint32_t flags = 0;
if (stat(gr->drm_device, &dev_stat) != 0) {
weston_log("%s: device disappeared, so we can't recover\n", __func__);
abort();
}
ec->default_dmabuf_feedback =
weston_dmabuf_feedback_create(dev_stat.st_rdev);
if (!ec->default_dmabuf_feedback)
return -1;
tranche =
weston_dmabuf_feedback_tranche_create(ec->default_dmabuf_feedback,
ec->dmabuf_feedback_format_table,
dev_stat.st_rdev, flags,
RENDERER_PREF);
if (!tranche) {
weston_dmabuf_feedback_destroy(ec->default_dmabuf_feedback);
ec->default_dmabuf_feedback = NULL;
return -1;
}
return 0;
}
static int
gl_renderer_display_create(struct weston_compositor *ec,
const struct gl_renderer_display_options *options)
......@@ -3685,6 +3718,17 @@ gl_renderer_display_create(struct weston_compositor *ec,
ret = populate_supported_formats(ec, &gr->supported_formats);
if (ret < 0)
goto fail_terminate;
if (gr->drm_device) {
/* We support dma-buf feedback only when the renderer
* exposes a DRM-device */
ec->dmabuf_feedback_format_table =
weston_dmabuf_feedback_format_table_create(&gr->supported_formats);
if (!ec->dmabuf_feedback_format_table)
goto fail_terminate;
ret = create_default_dmabuf_feedback(ec, gr);
if (ret < 0)
goto fail_feedback;
}
}
wl_list_init(&gr->dmabuf_formats);
......@@ -3731,6 +3775,15 @@ gl_renderer_display_create(struct weston_compositor *ec,
fail_with_error:
gl_renderer_print_egl_error_state();
if (gr->drm_device) {
weston_dmabuf_feedback_destroy(ec->default_dmabuf_feedback);
ec->default_dmabuf_feedback = NULL;
}
fail_feedback:
if (gr->drm_device) {
weston_dmabuf_feedback_format_table_destroy(ec->dmabuf_feedback_format_table);
ec->dmabuf_feedback_format_table = NULL;
}
fail_terminate:
weston_drm_format_array_fini(&gr->supported_formats);
eglTerminate(gr->egl_display);
......
......@@ -200,7 +200,7 @@ option(
option(
'simple-clients',
type: 'array',
choices: [ 'all', 'damage', 'im', 'egl', 'shm', 'touch', 'dmabuf-v4l', 'dmabuf-egl' ],
choices: [ 'all', 'damage', 'im', 'egl', 'shm', 'touch', 'dmabuf-feedback', 'dmabuf-v4l', 'dmabuf-egl' ],
value: [ 'all' ],
description: 'Sample clients: simple test programs'
)
......
dep_scanner = dependency('wayland-scanner', native: true)
prog_scanner = find_program(dep_scanner.get_pkgconfig_variable('wayland_scanner'))
dep_wp = dependency('wayland-protocols', version: '>= 1.19')
dep_wp = dependency('wayland-protocols', version: '>= 1.24')
dir_wp_base = dep_wp.get_pkgconfig_variable('pkgdatadir')
install_data(
......
......@@ -143,6 +143,38 @@ typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFFORMATSEXTPROC) (EGLDisplay dp
typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFMODIFIERSEXTPROC) (EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers);
#endif
/* Define tokens from EGL_EXT_device_base */
#ifndef EGL_EXT_device_base
#define EGL_EXT_device_base 1
typedef void *EGLDeviceEXT;
#define EGL_NO_DEVICE_EXT EGL_CAST(EGLDeviceEXT,0)
#define EGL_BAD_DEVICE_EXT 0x322B
#define EGL_DEVICE_EXT 0x322C
typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICEATTRIBEXTPROC) (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
typedef const char *(EGLAPIENTRYP PFNEGLQUERYDEVICESTRINGEXTPROC) (EGLDeviceEXT device, EGLint name);
typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDEVICESEXTPROC) (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBEXTPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
#ifdef EGL_EGLEXT_PROTOTYPES
EGLAPI EGLBoolean EGLAPIENTRY eglQueryDeviceAttribEXT (EGLDeviceEXT device, EGLint attribute, EGLAttrib *value);
EGLAPI const char *EGLAPIENTRY eglQueryDeviceStringEXT (EGLDeviceEXT device, EGLint name);
EGLAPI EGLBoolean EGLAPIENTRY eglQueryDevicesEXT (EGLint max_devices, EGLDeviceEXT *devices, EGLint *num_devices);
EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribEXT (EGLDisplay dpy, EGLint attribute, EGLAttrib *value);
#endif
#endif /* EGL_EXT_device_base */
/* Define tokens from EGL_EXT_device_drm */
#ifndef EGL_EXT_device_drm
#define EGL_EXT_device_drm 1
#define EGL_DRM_DEVICE_FILE_EXT 0x3233
#define EGL_DRM_MASTER_FD_EXT 0x333C
#endif /* EGL_EXT_device_drm */
/* Define tokens from EGL_EXT_device_drm_render_node */
#ifndef EGL_EXT_device_drm_render_node
#define EGL_EXT_device_drm_render_node 1
#define EGL_DRM_RENDER_NODE_FILE_EXT 0x3377
#endif /* EGL_EXT_device_drm_render_node */
#ifndef EGL_EXT_swap_buffers_with_damage
#define EGL_EXT_swap_buffers_with_damage 1
typedef EGLBoolean (EGLAPIENTRYP PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC) (EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint n_rects);
......