2010-06-11 20:56:24 +04:00
|
|
|
/*
|
Change remaining GPLv2 headers to MIT
The files in question are copyright Benjamin Franzke (who agrees),
Intel Corporation, Red Hat and myself. On behalf of Red Hat,
Richard Fontana says:
"Therefore, to the extent that Red Hat, Inc. has any copyright
interest in the files you cited as of this date (compositor-drm.c,
compositor.c, compositor.h, screenshooter.c in
http://cgit.freedesktop.org/wayland/wayland-demos/tree/compositor),
Red Hat hereby elects to apply the CC0 1.0 Universal Public Domain
Dedication to such copyrighted material. See:
http://creativecommons.org/publicdomain/zero/1.0/legalcode .
Thanks,
Richard E. Fontana
Open Source Licensing and Patent Counsel
Red Hat, Inc."
2011-09-15 23:43:14 +04:00
|
|
|
* Copyright © 2008-2011 Kristian Høgsberg
|
|
|
|
* Copyright © 2011 Intel Corporation
|
2018-04-19 14:20:01 +03:00
|
|
|
* Copyright © 2017, 2018 Collabora, Ltd.
|
|
|
|
* Copyright © 2017, 2018 General Electric Company
|
2018-09-26 14:33:36 +03:00
|
|
|
* Copyright (c) 2018 DisplayLink (UK) Ltd.
|
2010-06-11 20:56:24 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2010-06-11 20:56:24 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-06-11 20:56:24 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
2011-04-12 19:34:32 +04:00
|
|
|
|
2012-02-23 18:45:49 +04:00
|
|
|
#include <errno.h>
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2010-06-11 20:56:24 +04:00
|
|
|
#include <stdlib.h>
|
2013-04-24 17:58:02 +04:00
|
|
|
#include <ctype.h>
|
2010-06-11 20:56:24 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2012-04-10 08:11:50 +04:00
|
|
|
#include <linux/input.h>
|
2013-09-19 10:00:17 +04:00
|
|
|
#include <linux/vt.h>
|
2012-06-26 18:09:14 +04:00
|
|
|
#include <assert.h>
|
2013-01-25 17:13:04 +04:00
|
|
|
#include <sys/mman.h>
|
2013-05-07 15:16:59 +04:00
|
|
|
#include <time.h>
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2011-03-02 13:56:04 +03:00
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
|
2012-08-03 21:30:30 +04:00
|
|
|
#include <libudev.h>
|
2011-04-30 11:32:11 +04:00
|
|
|
|
2019-03-28 17:28:47 +03:00
|
|
|
#include <libweston/libweston.h>
|
2019-03-29 17:39:12 +03:00
|
|
|
#include <libweston/backend-drm.h>
|
2019-06-21 22:49:18 +03:00
|
|
|
#include <libweston/weston-log.h>
|
2019-06-17 14:13:46 +03:00
|
|
|
#include "drm-internal.h"
|
2015-06-16 01:37:08 +03:00
|
|
|
#include "shared/helpers.h"
|
compositor-drm: Allow instant start of repaint loop. (v4)
drm_output_start_repaint_loop() incurred a delay of
one refresh cycle by using a no-op page-flip to get
an accurate vblank timestamp as reference. This causes
unwanted lag whenever Weston exited its repaint loop, e.g.,
whenever an application wants to repaint with less than
full video refresh rate but still minimum lag.
Try to use the drmWaitVblank ioctl to get a proper
timestamp instantaneously without lag. If that does
not work, fall back to the old method of idle page-flip.
This optimization will work on any drm/kms driver
which supports high precision vblank timestamping.
As of Linux 4.0 these would be intel, radeon and
nouveau on all their supported gpu's.
On kms drivers without instant high precision timestamping
support, the kernel is supposed to return a timestamp
of zero when calling drmWaitVblank() to query the current
vblank count and time iff vblank irqs are currently
disabled, because the only way to get a valid timestamp
on such kms drivers is to enable vblank interrupts and
then wait a bit for the next vblank irq to take a new valid
timestamp. The caller is supposed to poll until at next
vblank irq it gets a valid non-zero timestamp if it needs
a timestamp.
This zero-timestamp signalling works up to Linux 3.17, but
got broken due to a regression in Linux 3.18 and later. On
Linux 3.18+ with kms drivers that don't have high precision
timestamping, the kernel erroneously returns a stale timestamp
from an earlier vblank, ie. the vblank count and timestamp are
mismatched. A patch is under way to fix this, but to deal with
broken kernels, we also check non-zero timestamps if they are
more than one refresh duration in the past, as this indicates
a stale/invalid timestamp, so we need to take the page-flip
fallback for restarting the repaint loop.
v2: Implement review suggestions by Pekka Paalanen, especially
extend the commit message to describe when and why the
instant restart won't work due to missing Linux kernel
functionality or a Linux kernel regression.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
v3: Fix timespec_to_nsec() which was computing picoseconds,
use the new timespec-util.h helpers.
v4: Rebased to master, split long lines.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-21 22:25:14 +03:00
|
|
|
#include "shared/timespec-util.h"
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
#include "shared/string-helpers.h"
|
2021-02-04 18:39:45 +03:00
|
|
|
#include "shared/weston-drm-fourcc.h"
|
2013-01-25 17:13:05 +04:00
|
|
|
#include "pixman-renderer.h"
|
2017-04-04 19:54:23 +03:00
|
|
|
#include "pixel-formats.h"
|
2016-04-30 01:40:34 +03:00
|
|
|
#include "libbacklight.h"
|
2014-11-26 00:06:31 +03:00
|
|
|
#include "libinput-seat.h"
|
2012-01-30 17:04:04 +04:00
|
|
|
#include "launcher-util.h"
|
2013-08-23 18:15:48 +04:00
|
|
|
#include "vaapi-recorder.h"
|
2016-02-18 17:53:27 +03:00
|
|
|
#include "presentation-time-server-protocol.h"
|
2014-06-12 16:12:48 +04:00
|
|
|
#include "linux-dmabuf.h"
|
2017-02-01 23:28:23 +03:00
|
|
|
#include "linux-dmabuf-unstable-v1-server-protocol.h"
|
libweston: Support zwp_surface_synchronization_v1.set_acquire_fence
Implement the set_acquire_fence request of the
zwp_surface_synchronization_v1 interface.
The implementation uses the acquire fence in two ways:
1. If the associated buffer is used as GL render source, an
EGLSyncKHR is created from the fence and used to synchronize
access.
2. If the associated buffer is used as a plane framebuffer,
the acquire fence is treated as an in-fence for the atomic
commit operation. If in-fences are not supported and the buffer
has an acquire fence, we don't consider it for plane placement.
If the used compositor/renderer doesn't support explicit
synchronization, we don't advertise the protocol at all. Currently only
the DRM and X11 backends when using the GL renderer advertise the
protocol for production use.
Issues for discussion
---------------------
a. Currently, a server-side wait of EGLSyncKHR is performed before
using the EGLImage/texture during rendering. Unfortunately, it's not clear
from the specs whether this is generally safe to do, or we need to
sync before glEGLImageTargetTexture2DOES. The exception is
TEXTURE_EXTERNAL_OES where the spec mentions it's enough to sync
and then glBindTexture for any changes to take effect.
Changes in v5:
- Meson support.
- Make explicit sync server error reporting more generic, supporting
all explicit sync related interfaces not just
wp_linux_surface_synchronization.
- Fix typo in warning for missing EGL_KHR_wait_sync extension.
- Support minor version 2 of the explicit sync protocol (i.e., support
fences for opaque EGL buffers).
Changes in v4:
- Introduce and use fd_clear and and fd_move helpers.
- Don't check for a valid buffer when updating surface acquire fence fd
from state.
- Assert that pending state acquire fence fd is always clear
after a commit.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to just the
renderer.
- Check for EGL_KHR_wait_sync before using eglWaitSyncKHR.
- Dup the acquire fence before passing to EGL.
Changes in v3:
- Keep acquire_fence_fd in surface instead of buffer.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to both backend and
renderer.
- Move comment about non-ownership of in_fence_fd to struct
drm_plane_state definition.
- Assert that we don't try to use planes with in-fences when using the
legacy KMS API.
- Remove unnecessary info from wayland error messages.
- Handle acquire fence for subsurface commits.
- Guard against self-update in fd_update.
- Disconnect the client if acquire fence EGLSyncKHR creation or wait
fails.
- Use updated protocol interface names.
- User correct format specifier for resource ids.
- Advertise protocol for X11 backend with GL renderer.
Changes in v2:
- Remove sync file wait fallbacks.
- Raise UNSUPPORTED_BUFFER error at commit if we have an acquire
fence, but the committed buffer is not a valid linux_dmabuf.
- Don't put buffers with in-fences on planes that don't support
in-fences.
- Don't advertise explicit sync protocol if backend does not
support explicit sync.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2018-10-19 12:14:11 +03:00
|
|
|
#include "linux-explicit-synchronization.h"
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2013-02-19 01:15:53 +04:00
|
|
|
static const char default_seat[] = "seat0";
|
2012-08-03 21:30:30 +04:00
|
|
|
|
2019-10-29 18:29:37 +03:00
|
|
|
static void
|
|
|
|
drm_backend_create_faked_zpos(struct drm_backend *b)
|
|
|
|
{
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2019-10-29 18:29:37 +03:00
|
|
|
struct drm_plane *plane;
|
|
|
|
uint64_t zpos = 0ULL;
|
|
|
|
uint64_t zpos_min_primary;
|
|
|
|
uint64_t zpos_min_overlay;
|
|
|
|
uint64_t zpos_min_cursor;
|
|
|
|
|
|
|
|
zpos_min_primary = zpos;
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(plane, &device->plane_list, link) {
|
2019-10-29 18:29:37 +03:00
|
|
|
/* if the property is there, bail out sooner */
|
|
|
|
if (plane->props[WDRM_PLANE_ZPOS].prop_id != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (plane->type != WDRM_PLANE_TYPE_PRIMARY)
|
|
|
|
continue;
|
|
|
|
zpos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
zpos_min_overlay = zpos;
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(plane, &device->plane_list, link) {
|
2019-10-29 18:29:37 +03:00
|
|
|
if (plane->type != WDRM_PLANE_TYPE_OVERLAY)
|
|
|
|
continue;
|
|
|
|
zpos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
zpos_min_cursor = zpos;
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(plane, &device->plane_list, link) {
|
2019-10-29 18:29:37 +03:00
|
|
|
if (plane->type != WDRM_PLANE_TYPE_CURSOR)
|
|
|
|
continue;
|
|
|
|
zpos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_debug(b, "[drm-backend] zpos property not found. "
|
|
|
|
"Using invented immutable zpos values:\n");
|
|
|
|
/* assume that invented zpos values are immutable */
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(plane, &device->plane_list, link) {
|
2019-10-29 18:29:37 +03:00
|
|
|
if (plane->type == WDRM_PLANE_TYPE_PRIMARY) {
|
|
|
|
plane->zpos_min = zpos_min_primary;
|
|
|
|
plane->zpos_max = zpos_min_primary;
|
|
|
|
} else if (plane->type == WDRM_PLANE_TYPE_OVERLAY) {
|
|
|
|
plane->zpos_min = zpos_min_overlay;
|
|
|
|
plane->zpos_max = zpos_min_overlay;
|
|
|
|
} else if (plane->type == WDRM_PLANE_TYPE_CURSOR) {
|
|
|
|
plane->zpos_min = zpos_min_cursor;
|
|
|
|
plane->zpos_max = zpos_min_cursor;
|
|
|
|
}
|
|
|
|
drm_debug(b, "\t[plane] %s plane %d, zpos_min %"PRIu64", "
|
|
|
|
"zpos_max %"PRIu64"\n",
|
|
|
|
drm_output_get_plane_type_name(plane),
|
|
|
|
plane->plane_id, plane->zpos_min, plane->zpos_max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 16:27:54 +03:00
|
|
|
static int
|
|
|
|
pageflip_timeout(void *data) {
|
|
|
|
/*
|
|
|
|
* Our timer just went off, that means we're not receiving drm
|
|
|
|
* page flip events anymore for that output. Let's gracefully exit
|
|
|
|
* weston with a return value so devs can debug what's going on.
|
|
|
|
*/
|
|
|
|
struct drm_output *output = data;
|
|
|
|
struct weston_compositor *compositor = output->base.compositor;
|
|
|
|
|
|
|
|
weston_log("Pageflip timeout reached on output %s, your "
|
|
|
|
"driver is probably buggy! Exiting.\n",
|
|
|
|
output->base.name);
|
|
|
|
weston_compositor_exit_with_code(compositor, EXIT_FAILURE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Creates the pageflip timer. Note that it isn't armed by default */
|
|
|
|
static int
|
|
|
|
drm_output_pageflip_timer_create(struct drm_output *output)
|
|
|
|
{
|
|
|
|
struct wl_event_loop *loop = NULL;
|
|
|
|
struct weston_compositor *ec = output->base.compositor;
|
|
|
|
|
|
|
|
loop = wl_display_get_event_loop(ec->wl_display);
|
|
|
|
assert(loop);
|
|
|
|
output->pageflip_timer = wl_event_loop_add_timer(loop,
|
|
|
|
pageflip_timeout,
|
|
|
|
output);
|
|
|
|
|
|
|
|
if (output->pageflip_timer == NULL) {
|
2019-04-27 00:57:31 +03:00
|
|
|
weston_log("creating drm pageflip timer failed: %s\n",
|
|
|
|
strerror(errno));
|
2017-03-07 16:27:54 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-07 14:59:02 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the plane can be used on the given output for its current
|
|
|
|
* repaint cycle.
|
|
|
|
*/
|
2019-06-22 20:40:31 +03:00
|
|
|
bool
|
2017-10-07 14:59:02 +03:00
|
|
|
drm_plane_is_available(struct drm_plane *plane, struct drm_output *output)
|
2012-02-23 18:45:49 +04:00
|
|
|
{
|
2017-10-07 14:59:02 +03:00
|
|
|
assert(plane->state_cur);
|
|
|
|
|
2018-01-31 11:50:48 +03:00
|
|
|
if (output->virtual)
|
|
|
|
return false;
|
|
|
|
|
2017-10-07 14:59:02 +03:00
|
|
|
/* The plane still has a request not yet completed by the kernel. */
|
|
|
|
if (!plane->state_cur->complete)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* The plane is still active on another output. */
|
|
|
|
if (plane->state_cur->output && plane->state_cur->output != output)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Check whether the plane can be used with this CRTC; possible_crtcs
|
|
|
|
* is a bitmask of CRTC indices (pipe), rather than CRTC object ID. */
|
2020-08-13 20:12:28 +03:00
|
|
|
return !!(plane->possible_crtcs & (1 << output->crtc->pipe));
|
2012-02-23 18:45:49 +04:00
|
|
|
}
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
struct drm_crtc *
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_crtc_find(struct drm_device *device, uint32_t crtc_id)
|
2017-02-09 16:49:15 +03:00
|
|
|
{
|
2020-08-13 20:12:28 +03:00
|
|
|
struct drm_crtc *crtc;
|
2017-02-09 16:49:15 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(crtc, &device->crtc_list, link) {
|
2020-08-13 20:12:28 +03:00
|
|
|
if (crtc->crtc_id == crtc_id)
|
|
|
|
return crtc;
|
2017-02-09 16:49:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
struct drm_head *
|
2017-08-31 11:58:41 +03:00
|
|
|
drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id)
|
|
|
|
{
|
|
|
|
struct weston_head *base;
|
|
|
|
struct drm_head *head;
|
|
|
|
|
|
|
|
wl_list_for_each(base,
|
|
|
|
&backend->compositor->head_list, compositor_link) {
|
|
|
|
head = to_drm_head(base);
|
2021-03-11 13:04:32 +03:00
|
|
|
if (!head)
|
|
|
|
continue;
|
2020-06-17 17:09:47 +03:00
|
|
|
if (head->connector.connector_id == connector_id)
|
2017-08-31 11:58:41 +03:00
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
static struct drm_writeback *
|
|
|
|
drm_writeback_find_by_connector(struct drm_backend *backend, uint32_t connector_id)
|
|
|
|
{
|
|
|
|
struct drm_writeback *writeback;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(writeback, &backend->drm->writeback_connector_list, link) {
|
2020-09-09 21:23:49 +03:00
|
|
|
if (writeback->connector.connector_id == connector_id)
|
|
|
|
return writeback;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
/**
|
|
|
|
* Get output state to disable output
|
|
|
|
*
|
|
|
|
* Returns a pointer to an output_state object which can be used to disable
|
|
|
|
* an output (e.g. DPMS off).
|
|
|
|
*
|
|
|
|
* @param pending_state The pending state object owning this update
|
|
|
|
* @param output The output to disable
|
|
|
|
* @returns A drm_output_state to disable the output
|
|
|
|
*/
|
|
|
|
static struct drm_output_state *
|
|
|
|
drm_output_get_disable_state(struct drm_pending_state *pending_state,
|
|
|
|
struct drm_output *output)
|
|
|
|
{
|
|
|
|
struct drm_output_state *output_state;
|
|
|
|
|
|
|
|
output_state = drm_output_state_duplicate(output->state_cur,
|
|
|
|
pending_state,
|
|
|
|
DRM_OUTPUT_STATE_CLEAR_PLANES);
|
|
|
|
output_state->dpms = WESTON_DPMS_OFF;
|
|
|
|
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
output_state->protection = WESTON_HDCP_DISABLE;
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
return output_state;
|
|
|
|
}
|
|
|
|
|
2016-11-11 22:11:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark a drm_output_state (the output's last state) as complete. This handles
|
|
|
|
* any post-completion actions such as updating the repaint timer, disabling the
|
|
|
|
* output, and finally freeing the state.
|
|
|
|
*/
|
2019-06-18 13:12:07 +03:00
|
|
|
void
|
2016-11-11 22:11:49 +03:00
|
|
|
drm_output_update_complete(struct drm_output *output, uint32_t flags,
|
|
|
|
unsigned int sec, unsigned int usec)
|
|
|
|
{
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2016-11-14 19:57:01 +03:00
|
|
|
struct drm_plane_state *ps;
|
2016-11-11 22:11:49 +03:00
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
/* Stop the pageflip timer instead of rearming it here */
|
|
|
|
if (output->pageflip_timer)
|
|
|
|
wl_event_source_timer_update(output->pageflip_timer, 0);
|
|
|
|
|
2016-11-14 19:57:01 +03:00
|
|
|
wl_list_for_each(ps, &output->state_cur->plane_list, link)
|
|
|
|
ps->complete = true;
|
|
|
|
|
2016-11-11 22:11:49 +03:00
|
|
|
drm_output_state_free(output->state_last);
|
|
|
|
output->state_last = NULL;
|
|
|
|
|
|
|
|
if (output->destroy_pending) {
|
2019-12-09 04:50:55 +03:00
|
|
|
output->destroy_pending = false;
|
|
|
|
output->disable_pending = false;
|
|
|
|
output->dpms_off_pending = false;
|
2016-11-11 22:11:49 +03:00
|
|
|
drm_output_destroy(&output->base);
|
|
|
|
return;
|
|
|
|
} else if (output->disable_pending) {
|
2019-12-09 04:50:55 +03:00
|
|
|
output->disable_pending = false;
|
|
|
|
output->dpms_off_pending = false;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
weston_output_disable(&output->base);
|
|
|
|
return;
|
|
|
|
} else if (output->dpms_off_pending) {
|
2021-11-03 14:56:31 +03:00
|
|
|
struct drm_pending_state *pending = drm_pending_state_alloc(device);
|
2019-12-09 04:50:55 +03:00
|
|
|
output->dpms_off_pending = false;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
drm_output_get_disable_state(pending, output);
|
|
|
|
drm_pending_state_apply_sync(pending);
|
2020-08-06 10:57:54 +03:00
|
|
|
}
|
|
|
|
if (output->state_cur->dpms == WESTON_DPMS_OFF &&
|
|
|
|
output->base.repaint_status != REPAINT_AWAITING_COMPLETION) {
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
/* DPMS can happen to us either in the middle of a repaint
|
|
|
|
* cycle (when we have painted fresh content, only to throw it
|
|
|
|
* away for DPMS off), or at any other random point. If the
|
|
|
|
* latter is true, then we cannot go through finish_frame,
|
|
|
|
* because the repaint machinery does not expect this. */
|
2016-11-11 22:11:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts.tv_sec = sec;
|
|
|
|
ts.tv_nsec = usec * 1000;
|
2021-07-29 17:02:04 +03:00
|
|
|
|
|
|
|
if (output->state_cur->dpms != WESTON_DPMS_OFF)
|
|
|
|
weston_output_finish_frame(&output->base, &ts, flags);
|
|
|
|
else
|
|
|
|
weston_output_finish_frame(&output->base, NULL,
|
|
|
|
WP_PRESENTATION_FEEDBACK_INVALID);
|
2016-11-11 22:11:49 +03:00
|
|
|
|
|
|
|
/* We can't call this from frame_notify, because the output's
|
|
|
|
* repaint needed flag is cleared just after that */
|
|
|
|
if (output->recorder)
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
}
|
|
|
|
|
2017-04-04 19:54:30 +03:00
|
|
|
static struct drm_fb *
|
2016-11-11 22:11:49 +03:00
|
|
|
drm_output_render_pixman(struct drm_output_state *state,
|
|
|
|
pixman_region32_t *damage)
|
2013-01-25 17:13:05 +04:00
|
|
|
{
|
2016-11-11 22:11:49 +03:00
|
|
|
struct drm_output *output = state->output;
|
2013-01-25 17:13:05 +04:00
|
|
|
struct weston_compositor *ec = output->base.compositor;
|
|
|
|
|
|
|
|
output->current_image ^= 1;
|
|
|
|
|
|
|
|
pixman_renderer_output_set_buffer(&output->base,
|
|
|
|
output->image[output->current_image]);
|
2018-04-23 12:44:56 +03:00
|
|
|
pixman_renderer_output_set_hw_extra_damage(&output->base,
|
|
|
|
&output->previous_damage);
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2018-04-23 12:44:56 +03:00
|
|
|
ec->renderer->repaint_output(&output->base, damage);
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2018-04-23 12:44:56 +03:00
|
|
|
pixman_region32_copy(&output->previous_damage, damage);
|
2017-04-04 19:54:30 +03:00
|
|
|
|
|
|
|
return drm_fb_ref(output->dumb[output->current_image]);
|
2013-01-25 17:13:05 +04:00
|
|
|
}
|
|
|
|
|
2019-07-09 01:50:30 +03:00
|
|
|
void
|
2016-11-11 22:11:49 +03:00
|
|
|
drm_output_render(struct drm_output_state *state, pixman_region32_t *damage)
|
2013-01-25 17:13:05 +04:00
|
|
|
{
|
2016-11-11 22:11:49 +03:00
|
|
|
struct drm_output *output = state->output;
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct weston_compositor *c = output->base.compositor;
|
2018-01-16 18:37:33 +03:00
|
|
|
struct drm_plane_state *scanout_state;
|
2016-11-14 20:46:59 +03:00
|
|
|
struct drm_plane *scanout_plane = output->scanout_plane;
|
2020-06-02 08:39:43 +03:00
|
|
|
struct drm_property_info *damage_info =
|
|
|
|
&scanout_plane->props[WDRM_PLANE_FB_DAMAGE_CLIPS];
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_backend *b = device->backend;
|
2017-04-04 19:54:30 +03:00
|
|
|
struct drm_fb *fb;
|
2020-06-02 08:39:43 +03:00
|
|
|
pixman_region32_t scanout_damage;
|
|
|
|
pixman_box32_t *rects;
|
|
|
|
int n_rects;
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2017-04-04 19:54:29 +03:00
|
|
|
/* If we already have a client buffer promoted to scanout, then we don't
|
|
|
|
* want to render. */
|
2020-08-13 23:34:58 +03:00
|
|
|
scanout_state = drm_output_state_get_plane(state, scanout_plane);
|
2018-01-16 18:37:33 +03:00
|
|
|
if (scanout_state->fb)
|
2017-04-04 19:54:29 +03:00
|
|
|
return;
|
|
|
|
|
2020-03-06 14:03:14 +03:00
|
|
|
/*
|
|
|
|
* If we don't have any damage on the primary plane, and we already
|
|
|
|
* have a renderer buffer active, we can reuse it; else we pass
|
|
|
|
* the damaged region into the renderer to re-render the affected
|
2020-12-07 15:59:44 +03:00
|
|
|
* area. But, we still have to call the renderer anyway if any screen
|
|
|
|
* capture is pending, otherwise the capture will not complete.
|
2020-03-06 14:03:14 +03:00
|
|
|
*/
|
2016-11-14 20:46:59 +03:00
|
|
|
if (!pixman_region32_not_empty(damage) &&
|
2020-12-07 15:59:44 +03:00
|
|
|
wl_list_empty(&output->base.frame_signal.listener_list) &&
|
2016-11-14 20:46:59 +03:00
|
|
|
scanout_plane->state_cur->fb &&
|
|
|
|
(scanout_plane->state_cur->fb->type == BUFFER_GBM_SURFACE ||
|
2020-03-06 14:03:14 +03:00
|
|
|
scanout_plane->state_cur->fb->type == BUFFER_PIXMAN_DUMB)) {
|
2016-11-14 20:46:59 +03:00
|
|
|
fb = drm_fb_ref(scanout_plane->state_cur->fb);
|
|
|
|
} else if (b->use_pixman) {
|
2016-11-11 22:11:49 +03:00
|
|
|
fb = drm_output_render_pixman(state, damage);
|
2016-11-14 20:46:59 +03:00
|
|
|
} else {
|
2016-11-11 22:11:49 +03:00
|
|
|
fb = drm_output_render_gl(state, damage);
|
2016-11-14 20:46:59 +03:00
|
|
|
}
|
2017-04-04 19:54:30 +03:00
|
|
|
|
2018-01-16 18:37:33 +03:00
|
|
|
if (!fb) {
|
|
|
|
drm_plane_state_put_back(scanout_state);
|
2017-04-04 19:54:30 +03:00
|
|
|
return;
|
2018-01-16 18:37:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
scanout_state->fb = fb;
|
|
|
|
scanout_state->output = output;
|
|
|
|
|
|
|
|
scanout_state->src_x = 0;
|
|
|
|
scanout_state->src_y = 0;
|
2020-03-06 14:07:15 +03:00
|
|
|
scanout_state->src_w = fb->width << 16;
|
|
|
|
scanout_state->src_h = fb->height << 16;
|
2018-01-16 18:37:33 +03:00
|
|
|
|
|
|
|
scanout_state->dest_x = 0;
|
|
|
|
scanout_state->dest_y = 0;
|
2020-03-06 14:07:15 +03:00
|
|
|
scanout_state->dest_w = output->base.current_mode->width;
|
|
|
|
scanout_state->dest_h = output->base.current_mode->height;
|
2018-01-16 18:37:33 +03:00
|
|
|
|
2020-06-02 08:39:43 +03:00
|
|
|
pixman_region32_subtract(&c->primary_plane.damage,
|
|
|
|
&c->primary_plane.damage, damage);
|
|
|
|
|
|
|
|
/* Don't bother calculating plane damage if the plane doesn't support it */
|
|
|
|
if (damage_info->prop_id == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pixman_region32_init(&scanout_damage);
|
|
|
|
pixman_region32_copy(&scanout_damage, damage);
|
|
|
|
|
2022-01-26 18:33:30 +03:00
|
|
|
pixman_region32_translate(&scanout_damage,
|
|
|
|
-output->base.x, -output->base.y);
|
|
|
|
weston_transformed_region(output->base.width,
|
|
|
|
output->base.height,
|
|
|
|
output->base.transform,
|
|
|
|
output->base.current_scale,
|
|
|
|
&scanout_damage,
|
|
|
|
&scanout_damage);
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2020-06-02 08:39:43 +03:00
|
|
|
assert(scanout_state->damage_blob_id == 0);
|
|
|
|
|
|
|
|
rects = pixman_region32_rectangles(&scanout_damage, &n_rects);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this function fails, the blob id should still be 0.
|
|
|
|
* This tells the kernel there is no damage information, which means
|
|
|
|
* that it will consider the whole plane damaged. While this may
|
|
|
|
* affect efficiency, it should still produce correct results.
|
|
|
|
*/
|
2021-11-29 16:21:40 +03:00
|
|
|
drmModeCreatePropertyBlob(device->drm.fd, rects,
|
2020-06-02 08:39:43 +03:00
|
|
|
sizeof(*rects) * n_rects,
|
|
|
|
&scanout_state->damage_blob_id);
|
|
|
|
|
|
|
|
pixman_region32_fini(&scanout_damage);
|
2013-01-25 17:13:05 +04:00
|
|
|
}
|
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
static int
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
drm_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
|
2013-05-02 00:52:12 +04:00
|
|
|
{
|
2016-08-05 16:54:18 +03:00
|
|
|
struct drm_output *output = to_drm_output(output_base);
|
2019-06-18 13:12:07 +03:00
|
|
|
struct drm_output_state *state = NULL;
|
|
|
|
struct drm_plane_state *scanout_state;
|
2021-11-16 18:37:04 +03:00
|
|
|
struct drm_pending_state *pending_state;
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device;
|
2013-05-02 00:52:12 +04:00
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
assert(output);
|
2019-06-18 13:12:07 +03:00
|
|
|
assert(!output->virtual);
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
device = output->device;
|
2021-11-29 16:21:40 +03:00
|
|
|
pending_state = device->repaint_data;
|
2021-11-16 18:37:04 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
if (output->disable_pending || output->destroy_pending)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
assert(!output->state_last);
|
|
|
|
|
|
|
|
/* If planes have been disabled in the core, we might not have
|
|
|
|
* hit assign_planes at all, so might not have valid output state
|
|
|
|
* here. */
|
|
|
|
state = drm_pending_state_get_output(pending_state, output);
|
|
|
|
if (!state)
|
|
|
|
state = drm_output_state_duplicate(output->state_cur,
|
|
|
|
pending_state,
|
|
|
|
DRM_OUTPUT_STATE_CLEAR_PLANES);
|
|
|
|
state->dpms = WESTON_DPMS_ON;
|
|
|
|
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (output_base->allow_protection)
|
|
|
|
state->protection = output_base->desired_protection;
|
|
|
|
else
|
|
|
|
state->protection = WESTON_HDCP_DISABLE;
|
|
|
|
|
2021-07-14 15:01:48 +03:00
|
|
|
if (drm_output_ensure_hdr_output_metadata_blob(output) < 0)
|
|
|
|
goto err;
|
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
drm_output_render(state, damage);
|
|
|
|
scanout_state = drm_output_state_get_plane(state,
|
|
|
|
output->scanout_plane);
|
|
|
|
if (!scanout_state || !scanout_state->fb)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
2013-05-02 00:52:12 +04:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
err:
|
|
|
|
drm_output_state_free(state);
|
|
|
|
return -1;
|
2013-05-02 00:52:12 +04:00
|
|
|
}
|
|
|
|
|
2015-06-30 23:25:46 +03:00
|
|
|
/* Determine the type of vblank synchronization to use for the output.
|
2016-02-18 17:53:27 +03:00
|
|
|
*
|
2015-06-30 23:25:46 +03:00
|
|
|
* The pipe parameter indicates which CRTC is in use. Knowing this, we
|
|
|
|
* can determine which vblank sequence type to use for it. Traditional
|
|
|
|
* cards had only two CRTCs, with CRTC 0 using no special flags, and
|
|
|
|
* CRTC 1 using DRM_VBLANK_SECONDARY. The first bit of the pipe
|
|
|
|
* parameter indicates this.
|
2016-02-18 17:53:27 +03:00
|
|
|
*
|
2015-06-30 23:25:46 +03:00
|
|
|
* Bits 1-5 of the pipe parameter are 5 bit wide pipe number between
|
|
|
|
* 0-31. If this is non-zero it indicates we're dealing with a
|
|
|
|
* multi-gpu situation and we need to calculate the vblank sync
|
|
|
|
* using DRM_BLANK_HIGH_CRTC_MASK.
|
|
|
|
*/
|
2015-07-02 15:06:08 +03:00
|
|
|
static unsigned int
|
2020-08-13 20:12:28 +03:00
|
|
|
drm_waitvblank_pipe(struct drm_crtc *crtc)
|
2015-06-21 22:25:13 +03:00
|
|
|
{
|
2020-08-13 20:12:28 +03:00
|
|
|
if (crtc->pipe > 1)
|
|
|
|
return (crtc->pipe << DRM_VBLANK_HIGH_CRTC_SHIFT) &
|
2015-06-21 22:25:13 +03:00
|
|
|
DRM_VBLANK_HIGH_CRTC_MASK;
|
2020-08-13 20:12:28 +03:00
|
|
|
else if (crtc->pipe > 0)
|
2015-06-21 22:25:13 +03:00
|
|
|
return DRM_VBLANK_SECONDARY;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-30 16:51:10 +03:00
|
|
|
static int
|
2019-06-18 13:12:07 +03:00
|
|
|
drm_output_start_repaint_loop(struct weston_output *output_base)
|
2011-03-11 18:39:20 +03:00
|
|
|
{
|
2019-06-18 13:12:07 +03:00
|
|
|
struct drm_output *output = to_drm_output(output_base);
|
|
|
|
struct drm_pending_state *pending_state;
|
2018-01-16 18:37:33 +03:00
|
|
|
struct drm_plane *scanout_plane = output->scanout_plane;
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
|
|
|
struct drm_backend *backend = device->backend;
|
|
|
|
struct weston_compositor *compositor = backend->compositor;
|
2019-06-18 13:12:07 +03:00
|
|
|
struct timespec ts, tnow;
|
|
|
|
struct timespec vbl2now;
|
|
|
|
int64_t refresh_nsec;
|
|
|
|
int ret;
|
|
|
|
drmVBlank vbl = {
|
|
|
|
.request.type = DRM_VBLANK_RELATIVE,
|
|
|
|
.request.sequence = 0,
|
|
|
|
.request.signal = 0,
|
|
|
|
};
|
2017-09-12 16:02:01 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
if (output->disable_pending || output->destroy_pending)
|
2019-06-30 16:51:10 +03:00
|
|
|
return 0;
|
2019-06-18 13:12:07 +03:00
|
|
|
|
2020-08-13 23:34:58 +03:00
|
|
|
if (!scanout_plane->state_cur->fb) {
|
2019-06-18 13:12:07 +03:00
|
|
|
/* We can't page flip if there's no mode set */
|
|
|
|
goto finish_frame;
|
2017-04-13 21:48:48 +03:00
|
|
|
}
|
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
/* Need to smash all state in from scratch; current timings might not
|
|
|
|
* be what we want, page flip might not work, etc.
|
|
|
|
*/
|
2021-11-29 16:21:40 +03:00
|
|
|
if (device->state_invalid)
|
2019-06-18 13:12:07 +03:00
|
|
|
goto finish_frame;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
assert(scanout_plane->state_cur->output == output);
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
/* Try to get current msc and timestamp via instant query */
|
2020-08-13 20:12:28 +03:00
|
|
|
vbl.request.type |= drm_waitvblank_pipe(output->crtc);
|
2021-11-29 16:21:40 +03:00
|
|
|
ret = drmWaitVBlank(device->drm.fd, &vbl);
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
/* Error ret or zero timestamp means failure to get valid timestamp */
|
|
|
|
if ((ret == 0) && (vbl.reply.tval_sec > 0 || vbl.reply.tval_usec > 0)) {
|
|
|
|
ts.tv_sec = vbl.reply.tval_sec;
|
|
|
|
ts.tv_nsec = vbl.reply.tval_usec * 1000;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
/* Valid timestamp for most recent vblank - not stale?
|
|
|
|
* Stale ts could happen on Linux 3.17+, so make sure it
|
|
|
|
* is not older than 1 refresh duration since now.
|
|
|
|
*/
|
2021-11-03 18:36:17 +03:00
|
|
|
weston_compositor_read_presentation_clock(compositor,
|
2019-06-18 13:12:07 +03:00
|
|
|
&tnow);
|
|
|
|
timespec_sub(&vbl2now, &tnow, &ts);
|
|
|
|
refresh_nsec =
|
|
|
|
millihz_to_nsec(output->base.current_mode->refresh);
|
|
|
|
if (timespec_to_nsec(&vbl2now) < refresh_nsec) {
|
|
|
|
drm_output_update_msc(output, vbl.reply.sequence);
|
|
|
|
weston_output_finish_frame(output_base, &ts,
|
|
|
|
WP_PRESENTATION_FEEDBACK_INVALID);
|
2019-06-30 16:51:10 +03:00
|
|
|
return 0;
|
2012-03-12 02:27:41 +04:00
|
|
|
}
|
2011-04-10 18:49:52 +04:00
|
|
|
}
|
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
/* Immediate query didn't provide valid timestamp.
|
|
|
|
* Use pageflip fallback.
|
|
|
|
*/
|
2011-03-11 18:39:20 +03:00
|
|
|
|
2017-04-04 19:54:33 +03:00
|
|
|
assert(!output->page_flip_pending);
|
2019-06-18 13:12:07 +03:00
|
|
|
assert(!output->state_last);
|
2012-06-26 18:09:13 +04:00
|
|
|
|
2021-11-03 14:56:31 +03:00
|
|
|
pending_state = drm_pending_state_alloc(device);
|
2019-06-18 13:12:07 +03:00
|
|
|
drm_output_state_duplicate(output->state_cur, pending_state,
|
|
|
|
DRM_OUTPUT_STATE_PRESERVE_PLANES);
|
2017-09-12 16:02:01 +03:00
|
|
|
|
2019-06-18 13:12:07 +03:00
|
|
|
ret = drm_pending_state_apply(pending_state);
|
|
|
|
if (ret != 0) {
|
|
|
|
weston_log("applying repaint-start state failed: %s\n",
|
|
|
|
strerror(errno));
|
2019-06-30 16:51:10 +03:00
|
|
|
if (ret == -EACCES)
|
|
|
|
return -1;
|
2019-06-18 13:12:07 +03:00
|
|
|
goto finish_frame;
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
2013-10-22 19:11:25 +04:00
|
|
|
|
2019-06-30 16:51:10 +03:00
|
|
|
return 0;
|
2013-10-22 19:11:25 +04:00
|
|
|
|
|
|
|
finish_frame:
|
|
|
|
/* if we cannot page-flip, immediately finish frame */
|
2017-03-01 14:34:05 +03:00
|
|
|
weston_output_finish_frame(output_base, NULL,
|
2016-02-18 17:53:27 +03:00
|
|
|
WP_PRESENTATION_FEEDBACK_INVALID);
|
2019-06-30 16:51:10 +03:00
|
|
|
return 0;
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
2017-02-10 21:06:04 +03:00
|
|
|
/**
|
|
|
|
* Begin a new repaint cycle
|
|
|
|
*
|
2016-11-11 22:11:49 +03:00
|
|
|
* Called by the core compositor at the beginning of a repaint cycle. Creates
|
|
|
|
* a new pending_state structure to own any output state created by individual
|
|
|
|
* output repaint functions until the repaint is flushed or cancelled.
|
2017-02-10 21:06:04 +03:00
|
|
|
*/
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
static void
|
2017-02-10 21:06:04 +03:00
|
|
|
drm_repaint_begin(struct weston_compositor *compositor)
|
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2021-11-16 18:37:04 +03:00
|
|
|
struct drm_pending_state *pending_state;
|
2017-02-10 21:06:04 +03:00
|
|
|
|
2021-11-03 14:56:31 +03:00
|
|
|
pending_state = drm_pending_state_alloc(device);
|
2021-11-29 16:21:40 +03:00
|
|
|
device->repaint_data = pending_state;
|
2017-02-10 21:06:04 +03:00
|
|
|
|
2019-04-17 13:47:06 +03:00
|
|
|
if (weston_log_scope_is_enabled(b->debug)) {
|
2018-07-20 12:21:28 +03:00
|
|
|
char *dbg = weston_compositor_print_scene_graph(compositor);
|
|
|
|
drm_debug(b, "[repaint] Beginning repaint; pending_state %p\n",
|
2021-11-29 16:21:40 +03:00
|
|
|
device->repaint_data);
|
2018-07-20 12:21:28 +03:00
|
|
|
drm_debug(b, "%s", dbg);
|
|
|
|
free(dbg);
|
|
|
|
}
|
2017-02-10 21:06:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush a repaint set
|
|
|
|
*
|
|
|
|
* Called by the core compositor when a repaint cycle has been completed
|
2016-11-11 22:11:49 +03:00
|
|
|
* and should be flushed. Frees the pending state, transitioning ownership
|
|
|
|
* of the output state from the pending state, to the update itself. When
|
|
|
|
* the update completes (see drm_output_update_complete), the output
|
|
|
|
* state will be freed.
|
2017-02-10 21:06:04 +03:00
|
|
|
*/
|
2019-06-30 16:51:10 +03:00
|
|
|
static int
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
drm_repaint_flush(struct weston_compositor *compositor)
|
2017-02-10 21:06:04 +03:00
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
|
|
|
struct drm_pending_state *pending_state = device->repaint_data;
|
2019-06-30 16:51:10 +03:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_pending_state_apply(pending_state);
|
|
|
|
if (ret != 0)
|
|
|
|
weston_log("repaint-flush failed: %s\n", strerror(errno));
|
compositor-drm: Disable unused CRTCs/connectors
If we have an unused CRTC or connector, explicitly disable it during the
end of the repaint cycle, or when we get VT-switched back in.
This commit moves state_invalid from an output property to a backend
property, as the unused CRTCs or connectors are likely not tracked by
drm_outputs. This matches the mechanics of later commits, where we move
to a global repaint-flush hook, applying the state for all outputs in
one go.
The output state_invalid flag originally provoked full changes on output
creation (via setting the flag at output enable time) and session enter.
For the new-output case, we will not have any FB in output->state_cur,
so we still take the same path in repaint as if state_invalid were set.
At session enter, we preserve the existing behaviour: as
start_repaint_loop will fail when state_invalid is set, all outputs will
be scheduled for repaint together, and state_invalid will not be cleared
until after all outputs have been repainted, inside repaint_flush.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2018-02-05 18:46:20 +03:00
|
|
|
|
2018-07-20 12:21:28 +03:00
|
|
|
drm_debug(b, "[repaint] flushed pending_state %p\n", pending_state);
|
2021-11-29 16:21:40 +03:00
|
|
|
device->repaint_data = NULL;
|
2019-06-30 16:51:10 +03:00
|
|
|
|
|
|
|
return (ret == -EACCES) ? -1 : 0;
|
2017-02-10 21:06:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancel a repaint set
|
|
|
|
*
|
|
|
|
* Called by the core compositor when a repaint has finished, so the data
|
|
|
|
* held across the repaint cycle should be discarded.
|
|
|
|
*/
|
|
|
|
static void
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
drm_repaint_cancel(struct weston_compositor *compositor)
|
2017-02-10 21:06:04 +03:00
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
|
|
|
struct drm_pending_state *pending_state = device->repaint_data;
|
2017-02-10 21:06:04 +03:00
|
|
|
|
|
|
|
drm_pending_state_free(pending_state);
|
2018-07-20 12:21:28 +03:00
|
|
|
drm_debug(b, "[repaint] cancel pending_state %p\n", pending_state);
|
2021-11-29 16:21:40 +03:00
|
|
|
device->repaint_data = NULL;
|
2017-02-10 21:06:04 +03:00
|
|
|
}
|
|
|
|
|
2013-01-25 17:13:05 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
drm_output_init_pixman(struct drm_output *output, struct drm_backend *b);
|
2016-11-04 20:24:06 +03:00
|
|
|
static void
|
|
|
|
drm_output_fini_pixman(struct drm_output *output);
|
2012-12-14 19:37:30 +04:00
|
|
|
|
2012-04-17 13:20:48 +04:00
|
|
|
static int
|
|
|
|
drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mode)
|
|
|
|
{
|
2017-10-07 16:01:45 +03:00
|
|
|
struct drm_output *output = to_drm_output(output_base);
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
|
|
|
struct drm_backend *b = device->backend;
|
2021-03-11 13:04:32 +03:00
|
|
|
struct drm_mode *drm_mode;
|
|
|
|
|
|
|
|
assert(output);
|
2012-04-17 13:20:48 +04:00
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
drm_mode = drm_output_choose_mode(output, mode);
|
2012-04-17 13:20:48 +04:00
|
|
|
if (!drm_mode) {
|
2017-10-07 16:01:45 +03:00
|
|
|
weston_log("%s: invalid resolution %dx%d\n",
|
|
|
|
output_base->name, mode->width, mode->height);
|
2012-04-17 13:20:48 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
if (&drm_mode->base == output->base.current_mode)
|
2012-12-14 19:37:30 +04:00
|
|
|
return 0;
|
2012-04-17 13:20:48 +04:00
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
output->base.current_mode->flags = 0;
|
2012-04-17 13:20:48 +04:00
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
output->base.current_mode = &drm_mode->base;
|
|
|
|
output->base.current_mode->flags =
|
2012-12-14 19:37:30 +04:00
|
|
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
2012-04-17 13:20:48 +04:00
|
|
|
|
compositor-drm: Introduce fb_last member
Previously, framebuffers were stored as fb_current and fb_pending.
In this scheme, current was the last buffer that the kernel/hardware had
acknowledged displaying: a framebuffer would be created, set as
fb_pending, and Weston would request the kernel display it. When the
kernel signals that the request was completed and the hardware had made
the buffer current (i.e. page_flip_handler / vblank_handler), we would
unreference the old fb_current, and promote fb_pending to fb_current.
In other words, the view is 'which buffer has turned to light?'.
This patch changes them to a tristate of fb_last, fb_current and
fb_pending, based around the kernel's view of the current state.
fb_pending is used purely as a staging area for request construction;
when the kernel acknowledges a request (e.g. drmModePageFlip returns 0),
the previous buffer is moved to fb_last, and this new buffer to
fb_current. When the kernel signals that the request has completed and
the hardware has made the buffer current, we simply unreference and
clear fb_last, without touching fb_current/fb_pending.
The view here is now 'which state is current in the kernel?'.
As all state changes are incremental on the last state submitted to the
kernel, even if the hardware has not yet been able to make it current,
this simplifies state tracking: all state submissions will always be
relative to fb_current, rather than the previous
(fb_pending) ? fb_pending : fb_current.
The use of fb_pending is strictly bounded between a repaint cycle
(including a grouped set of repaints) beginning, and those repaints
being flushed to the kernel.
fb_current will always be valid between an output's first repaint
flush, and when a disable/destroy request has been processed. For a
plane, it will be valid when a repaint cycle enabling that plane has
been flushed, and when a repaint cycle disabling that plane has been
flushed.
fb_last is only present when a repaint request for the output/plane has
been submitted, but not yet completed by the hardware.
This is the same set of constructs which will be used for storing
plane/output state objects in future patches.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-04-04 19:54:31 +03:00
|
|
|
/* XXX: This drops our current buffer too early, before we've started
|
|
|
|
* displaying it. Ideally this should be much more atomic and
|
|
|
|
* integrated with a full repaint cycle, rather than doing a
|
|
|
|
* sledgehammer modeswitch first, and only later showing new
|
|
|
|
* content.
|
|
|
|
*/
|
2021-11-29 16:21:40 +03:00
|
|
|
device->state_invalid = true;
|
2012-04-17 13:20:48 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
2013-01-25 17:13:05 +04:00
|
|
|
drm_output_fini_pixman(output);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (drm_output_init_pixman(output, b) < 0) {
|
2013-01-25 17:13:05 +04:00
|
|
|
weston_log("failed to init output pixman state with "
|
|
|
|
"new mode\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2016-11-04 20:24:06 +03:00
|
|
|
drm_output_fini_egl(output);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (drm_output_init_egl(output, b) < 0) {
|
2013-01-25 17:13:05 +04:00
|
|
|
weston_log("failed to init output egl state with "
|
|
|
|
"new mode");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-12-14 19:37:30 +04:00
|
|
|
}
|
2012-04-17 13:20:48 +04:00
|
|
|
|
2012-12-14 19:37:30 +04:00
|
|
|
return 0;
|
2012-04-17 13:20:48 +04:00
|
|
|
}
|
|
|
|
|
2013-01-25 17:13:05 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
init_pixman(struct drm_backend *b)
|
2013-01-25 17:13:05 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
return pixman_renderer_init(b->compositor);
|
2013-01-25 17:13:05 +04:00
|
|
|
}
|
|
|
|
|
2014-06-05 12:22:25 +04:00
|
|
|
/**
|
|
|
|
* Create a drm_plane for a hardware plane
|
|
|
|
*
|
|
|
|
* Creates one drm_plane structure for a hardware plane, and initialises its
|
|
|
|
* properties and formats.
|
|
|
|
*
|
|
|
|
* This function does not add the plane to the list of usable planes in Weston
|
|
|
|
* itself; the caller is responsible for this.
|
|
|
|
*
|
|
|
|
* Call drm_plane_destroy to clean up the plane.
|
|
|
|
*
|
2015-05-19 22:02:41 +03:00
|
|
|
* @sa drm_output_find_special_plane
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device DRM device
|
2020-10-12 19:37:07 +03:00
|
|
|
* @param kplane DRM plane to create
|
2014-06-05 12:22:25 +04:00
|
|
|
*/
|
|
|
|
static struct drm_plane *
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_plane_create(struct drm_device *device, const drmModePlane *kplane)
|
2014-06-05 12:22:25 +04:00
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_backend *b = device->backend;
|
|
|
|
struct weston_compositor *compositor = b->compositor;
|
2021-12-07 18:55:42 +03:00
|
|
|
struct drm_plane *plane, *tmp;
|
2015-05-21 01:01:44 +03:00
|
|
|
drmModeObjectProperties *props;
|
2019-08-29 20:42:00 +03:00
|
|
|
uint64_t *zpos_range_values;
|
2015-05-21 01:01:44 +03:00
|
|
|
|
2021-02-01 21:46:33 +03:00
|
|
|
plane = zalloc(sizeof(*plane));
|
2014-06-05 12:22:25 +04:00
|
|
|
if (!plane) {
|
|
|
|
weston_log("%s: out of memory\n", __func__);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
plane->device = device;
|
2016-11-14 19:57:01 +03:00
|
|
|
plane->state_cur = drm_plane_state_alloc(NULL, plane);
|
|
|
|
plane->state_cur->complete = true;
|
2020-10-12 19:37:07 +03:00
|
|
|
plane->possible_crtcs = kplane->possible_crtcs;
|
|
|
|
plane->plane_id = kplane->plane_id;
|
2014-06-05 12:22:25 +04:00
|
|
|
|
2021-02-01 21:46:33 +03:00
|
|
|
weston_drm_format_array_init(&plane->formats);
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
props = drmModeObjectGetProperties(device->drm.fd, kplane->plane_id,
|
2020-10-12 19:37:07 +03:00
|
|
|
DRM_MODE_OBJECT_PLANE);
|
|
|
|
if (!props) {
|
|
|
|
weston_log("couldn't get plane properties\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2015-05-19 22:02:41 +03:00
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_property_info_populate(device, plane_props, plane->props,
|
2020-10-12 19:37:07 +03:00
|
|
|
WDRM_PLANE__COUNT, props);
|
|
|
|
plane->type =
|
|
|
|
drm_property_get_value(&plane->props[WDRM_PLANE_TYPE],
|
|
|
|
props,
|
|
|
|
WDRM_PLANE_TYPE__COUNT);
|
2019-08-29 20:42:00 +03:00
|
|
|
|
2020-10-12 19:37:07 +03:00
|
|
|
zpos_range_values =
|
|
|
|
drm_property_get_range_values(&plane->props[WDRM_PLANE_ZPOS],
|
|
|
|
props);
|
2017-01-12 20:17:32 +03:00
|
|
|
|
2020-10-12 19:37:07 +03:00
|
|
|
if (zpos_range_values) {
|
|
|
|
plane->zpos_min = zpos_range_values[0];
|
|
|
|
plane->zpos_max = zpos_range_values[1];
|
|
|
|
} else {
|
2019-08-29 20:42:00 +03:00
|
|
|
plane->zpos_min = DRM_PLANE_ZPOS_INVALID_PLANE;
|
2020-10-12 19:37:07 +03:00
|
|
|
plane->zpos_max = DRM_PLANE_ZPOS_INVALID_PLANE;
|
|
|
|
}
|
2021-04-21 17:44:53 +03:00
|
|
|
|
2020-10-12 19:37:07 +03:00
|
|
|
if (drm_plane_populate_formats(plane, kplane, props,
|
2021-11-29 16:21:40 +03:00
|
|
|
device->fb_modifiers) < 0) {
|
2020-10-12 19:37:07 +03:00
|
|
|
drmModeFreeObjectProperties(props);
|
|
|
|
goto err;
|
2015-05-19 22:02:41 +03:00
|
|
|
}
|
|
|
|
|
2020-10-12 19:37:07 +03:00
|
|
|
drmModeFreeObjectProperties(props);
|
|
|
|
|
2015-05-19 22:02:41 +03:00
|
|
|
if (plane->type == WDRM_PLANE_TYPE__COUNT)
|
|
|
|
goto err_props;
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
weston_plane_init(&plane->base, compositor, 0, 0);
|
2021-12-07 18:55:42 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(tmp, &device->plane_list, link) {
|
2021-12-07 18:55:42 +03:00
|
|
|
if (tmp->zpos_max > plane->zpos_max) {
|
|
|
|
wl_list_insert(tmp->link.prev, &plane->link);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (plane->link.next == NULL)
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_insert(&device->plane_list, &plane->link);
|
2014-06-05 12:22:25 +04:00
|
|
|
|
|
|
|
return plane;
|
2015-05-19 22:02:41 +03:00
|
|
|
|
|
|
|
err_props:
|
|
|
|
drm_property_info_free(plane->props, WDRM_PLANE__COUNT);
|
|
|
|
err:
|
2021-02-01 21:46:33 +03:00
|
|
|
weston_drm_format_array_fini(&plane->formats);
|
2015-05-19 22:02:41 +03:00
|
|
|
drm_plane_state_free(plane->state_cur, true);
|
|
|
|
free(plane);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find, or create, a special-purpose plane
|
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device DRM device
|
2015-05-19 22:02:41 +03:00
|
|
|
* @param output Output to use for plane
|
|
|
|
* @param type Type of plane
|
|
|
|
*/
|
|
|
|
static struct drm_plane *
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_output_find_special_plane(struct drm_device *device,
|
|
|
|
struct drm_output *output,
|
2015-05-19 22:02:41 +03:00
|
|
|
enum wdrm_plane_type type)
|
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_backend *b = device->backend;
|
2015-05-19 22:02:41 +03:00
|
|
|
struct drm_plane *plane;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(plane, &device->plane_list, link) {
|
2022-06-13 18:22:22 +03:00
|
|
|
struct weston_output *base;
|
2015-05-19 22:02:41 +03:00
|
|
|
bool found_elsewhere = false;
|
|
|
|
|
|
|
|
if (plane->type != type)
|
|
|
|
continue;
|
|
|
|
if (!drm_plane_is_available(plane, output))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* On some platforms, primary/cursor planes can roam
|
|
|
|
* between different CRTCs, so make sure we don't claim the
|
|
|
|
* same plane for two outputs. */
|
2022-06-13 18:22:22 +03:00
|
|
|
wl_list_for_each(base, &b->compositor->output_list, link) {
|
|
|
|
struct drm_output *tmp = to_drm_output(base);
|
|
|
|
if (!tmp)
|
|
|
|
continue;
|
|
|
|
|
2018-01-16 18:37:33 +03:00
|
|
|
if (tmp->cursor_plane == plane ||
|
|
|
|
tmp->scanout_plane == plane) {
|
2015-05-19 22:02:41 +03:00
|
|
|
found_elsewhere = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_elsewhere)
|
|
|
|
continue;
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
plane->possible_crtcs = (1 << output->crtc->pipe);
|
2015-05-19 22:02:41 +03:00
|
|
|
return plane;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2014-06-05 12:22:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy one DRM plane
|
|
|
|
*
|
|
|
|
* Destroy a DRM plane, removing it from screen and releasing its retained
|
|
|
|
* buffers in the process. The counterpart to drm_plane_create.
|
|
|
|
*
|
|
|
|
* @param plane Plane to deallocate (will be freed)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drm_plane_destroy(struct drm_plane *plane)
|
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_device *device = plane->device;
|
2021-11-29 16:21:40 +03:00
|
|
|
|
2015-05-19 22:02:41 +03:00
|
|
|
if (plane->type == WDRM_PLANE_TYPE_OVERLAY)
|
2021-11-29 16:21:40 +03:00
|
|
|
drmModeSetPlane(device->drm.fd, plane->plane_id,
|
2015-05-19 22:02:41 +03:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
2016-11-14 19:57:01 +03:00
|
|
|
drm_plane_state_free(plane->state_cur, true);
|
2015-05-21 01:01:44 +03:00
|
|
|
drm_property_info_free(plane->props, WDRM_PLANE__COUNT);
|
2014-06-05 12:22:25 +04:00
|
|
|
weston_plane_release(&plane->base);
|
2021-02-01 21:46:33 +03:00
|
|
|
weston_drm_format_array_fini(&plane->formats);
|
2014-06-05 12:22:25 +04:00
|
|
|
wl_list_remove(&plane->link);
|
|
|
|
free(plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise sprites (overlay planes)
|
|
|
|
*
|
|
|
|
* Walk the list of provided DRM planes, and add overlay planes.
|
|
|
|
*
|
|
|
|
* Call destroy_sprites to free these planes.
|
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device DRM device
|
2014-06-05 12:22:25 +04:00
|
|
|
*/
|
|
|
|
static void
|
2021-11-03 14:56:53 +03:00
|
|
|
create_sprites(struct drm_device *device)
|
2014-06-05 12:22:25 +04:00
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_backend *b = device->backend;
|
2014-06-05 12:22:25 +04:00
|
|
|
drmModePlaneRes *kplane_res;
|
|
|
|
drmModePlane *kplane;
|
|
|
|
struct drm_plane *drm_plane;
|
|
|
|
uint32_t i;
|
2021-12-07 18:58:49 +03:00
|
|
|
uint32_t next_plane_idx = 0;
|
2021-11-29 16:21:40 +03:00
|
|
|
kplane_res = drmModeGetPlaneResources(device->drm.fd);
|
|
|
|
|
2014-06-05 12:22:25 +04:00
|
|
|
if (!kplane_res) {
|
|
|
|
weston_log("failed to get plane resources: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < kplane_res->count_planes; i++) {
|
2021-11-29 16:21:40 +03:00
|
|
|
kplane = drmModeGetPlane(device->drm.fd, kplane_res->planes[i]);
|
2014-06-05 12:22:25 +04:00
|
|
|
if (!kplane)
|
|
|
|
continue;
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_plane = drm_plane_create(device, kplane);
|
2014-06-05 12:22:25 +04:00
|
|
|
drmModeFreePlane(kplane);
|
|
|
|
if (!drm_plane)
|
|
|
|
continue;
|
|
|
|
|
2015-05-21 02:00:57 +03:00
|
|
|
if (drm_plane->type == WDRM_PLANE_TYPE_OVERLAY)
|
|
|
|
weston_compositor_stack_plane(b->compositor,
|
|
|
|
&drm_plane->base,
|
|
|
|
&b->compositor->primary_plane);
|
2014-06-05 12:22:25 +04:00
|
|
|
}
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each (drm_plane, &device->plane_list, link)
|
2021-12-07 18:58:49 +03:00
|
|
|
drm_plane->plane_idx = next_plane_idx++;
|
|
|
|
|
2014-06-05 12:22:25 +04:00
|
|
|
drmModeFreePlaneResources(kplane_res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up sprites (overlay planes)
|
|
|
|
*
|
|
|
|
* The counterpart to create_sprites.
|
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device DRM device
|
2014-06-05 12:22:25 +04:00
|
|
|
*/
|
|
|
|
static void
|
2021-11-03 14:56:53 +03:00
|
|
|
destroy_sprites(struct drm_device *device)
|
2014-06-05 12:22:25 +04:00
|
|
|
{
|
|
|
|
struct drm_plane *plane, *next;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each_safe(plane, next, &device->plane_list, link)
|
2014-06-05 12:22:25 +04:00
|
|
|
drm_plane_destroy(plane);
|
|
|
|
}
|
|
|
|
|
2012-03-13 02:40:09 +04:00
|
|
|
/* returns a value between 0-255 range, where higher is brighter */
|
2012-02-29 21:53:50 +04:00
|
|
|
static uint32_t
|
2017-09-04 12:21:24 +03:00
|
|
|
drm_get_backlight(struct drm_head *head)
|
2012-02-29 21:53:50 +04:00
|
|
|
{
|
|
|
|
long brightness, max_brightness, norm;
|
|
|
|
|
2017-09-04 12:21:24 +03:00
|
|
|
brightness = backlight_get_brightness(head->backlight);
|
|
|
|
max_brightness = backlight_get_max_brightness(head->backlight);
|
2012-02-29 21:53:50 +04:00
|
|
|
|
2012-03-13 02:40:09 +04:00
|
|
|
/* convert it on a scale of 0 to 255 */
|
|
|
|
norm = (brightness * 255)/(max_brightness);
|
2012-02-29 21:53:50 +04:00
|
|
|
|
|
|
|
return (uint32_t) norm;
|
|
|
|
}
|
|
|
|
|
2012-03-13 02:40:09 +04:00
|
|
|
/* values accepted are between 0-255 range */
|
2012-02-29 21:53:50 +04:00
|
|
|
static void
|
|
|
|
drm_set_backlight(struct weston_output *output_base, uint32_t value)
|
|
|
|
{
|
2017-09-12 16:14:31 +03:00
|
|
|
struct drm_output *output = to_drm_output(output_base);
|
|
|
|
struct drm_head *head;
|
2012-02-29 21:53:50 +04:00
|
|
|
long max_brightness, new_brightness;
|
|
|
|
|
2012-03-30 19:52:39 +04:00
|
|
|
if (value > 255)
|
2012-02-29 21:53:50 +04:00
|
|
|
return;
|
|
|
|
|
2017-09-12 16:14:31 +03:00
|
|
|
wl_list_for_each(head, &output->base.head_list, base.output_link) {
|
|
|
|
if (!head->backlight)
|
|
|
|
return;
|
2012-02-29 21:53:50 +04:00
|
|
|
|
2017-09-12 16:14:31 +03:00
|
|
|
max_brightness = backlight_get_max_brightness(head->backlight);
|
2012-02-29 21:53:50 +04:00
|
|
|
|
2017-09-12 16:14:31 +03:00
|
|
|
/* get denormalized value */
|
|
|
|
new_brightness = (value * max_brightness) / 255;
|
|
|
|
|
|
|
|
backlight_set_brightness(head->backlight, new_brightness);
|
|
|
|
}
|
2012-02-29 21:53:50 +04:00
|
|
|
}
|
|
|
|
|
2017-11-15 13:51:01 +03:00
|
|
|
static void
|
|
|
|
drm_output_init_backlight(struct drm_output *output)
|
|
|
|
{
|
|
|
|
struct weston_head *base;
|
|
|
|
struct drm_head *head;
|
|
|
|
|
|
|
|
output->base.set_backlight = NULL;
|
|
|
|
|
|
|
|
wl_list_for_each(base, &output->base.head_list, output_link) {
|
|
|
|
head = to_drm_head(base);
|
|
|
|
|
|
|
|
if (head->backlight) {
|
|
|
|
weston_log("Initialized backlight for head '%s', device %s\n",
|
|
|
|
head->base.name, head->backlight->path);
|
|
|
|
|
|
|
|
if (!output->base.set_backlight) {
|
|
|
|
output->base.set_backlight = drm_set_backlight;
|
|
|
|
output->base.backlight_current =
|
|
|
|
drm_get_backlight(head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
/**
|
|
|
|
* Power output on or off
|
|
|
|
*
|
|
|
|
* The DPMS/power level of an output is used to switch it on or off. This
|
|
|
|
* is DRM's hook for doing so, which can called either as part of repaint,
|
|
|
|
* or independently of the repaint loop.
|
|
|
|
*
|
|
|
|
* If we are called as part of repaint, we simply set the relevant bit in
|
|
|
|
* state and return.
|
2018-01-31 11:50:48 +03:00
|
|
|
*
|
|
|
|
* This function is never called on a virtual output.
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
*/
|
2012-02-29 21:53:50 +04:00
|
|
|
static void
|
|
|
|
drm_set_dpms(struct weston_output *output_base, enum dpms_enum level)
|
|
|
|
{
|
2016-08-05 16:54:18 +03:00
|
|
|
struct drm_output *output = to_drm_output(output_base);
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_pending_state *pending_state = device->repaint_data;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
struct drm_output_state *state;
|
2015-06-18 09:49:02 +03:00
|
|
|
int ret;
|
2012-02-29 21:53:50 +04:00
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
assert(output);
|
2018-01-31 11:50:48 +03:00
|
|
|
assert(!output->virtual);
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
if (output->state_cur->dpms == level)
|
2012-02-29 21:53:50 +04:00
|
|
|
return;
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
/* If we're being called during the repaint loop, then this is
|
|
|
|
* simple: discard any previously-generated state, and create a new
|
|
|
|
* state where we disable everything. When we come to flush, this
|
|
|
|
* will be applied.
|
|
|
|
*
|
|
|
|
* However, we need to be careful: we can be called whilst another
|
|
|
|
* output is in its repaint cycle (pending_state exists), but our
|
|
|
|
* output still has an incomplete state application outstanding.
|
|
|
|
* In that case, we need to wait until that completes. */
|
|
|
|
if (pending_state && !output->state_last) {
|
|
|
|
/* The repaint loop already sets DPMS on; we don't need to
|
|
|
|
* explicitly set it on here, as it will already happen
|
|
|
|
* whilst applying the repaint state. */
|
|
|
|
if (level == WESTON_DPMS_ON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
state = drm_pending_state_get_output(pending_state, output);
|
|
|
|
if (state)
|
|
|
|
drm_output_state_free(state);
|
|
|
|
state = drm_output_get_disable_state(pending_state, output);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* As we throw everything away when disabling, just send us back through
|
|
|
|
* a repaint cycle. */
|
|
|
|
if (level == WESTON_DPMS_ON) {
|
|
|
|
if (output->dpms_off_pending)
|
2019-12-09 04:50:55 +03:00
|
|
|
output->dpms_off_pending = false;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
weston_output_schedule_repaint(output_base);
|
2015-06-18 09:49:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
/* If we've already got a request in the pipeline, then we need to
|
|
|
|
* park our DPMS request until that request has quiesced. */
|
|
|
|
if (output->state_last) {
|
2019-12-09 04:50:55 +03:00
|
|
|
output->dpms_off_pending = true;
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-03 14:56:31 +03:00
|
|
|
pending_state = drm_pending_state_alloc(device);
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
drm_output_get_disable_state(pending_state, output);
|
|
|
|
ret = drm_pending_state_apply_sync(pending_state);
|
|
|
|
if (ret != 0)
|
|
|
|
weston_log("drm_set_dpms: couldn't disable output?\n");
|
2012-02-29 21:53:50 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 17:29:49 +04:00
|
|
|
static const char * const connector_type_names[] = {
|
2015-08-19 15:25:57 +03:00
|
|
|
[DRM_MODE_CONNECTOR_Unknown] = "Unknown",
|
|
|
|
[DRM_MODE_CONNECTOR_VGA] = "VGA",
|
|
|
|
[DRM_MODE_CONNECTOR_DVII] = "DVI-I",
|
|
|
|
[DRM_MODE_CONNECTOR_DVID] = "DVI-D",
|
|
|
|
[DRM_MODE_CONNECTOR_DVIA] = "DVI-A",
|
|
|
|
[DRM_MODE_CONNECTOR_Composite] = "Composite",
|
|
|
|
[DRM_MODE_CONNECTOR_SVIDEO] = "SVIDEO",
|
|
|
|
[DRM_MODE_CONNECTOR_LVDS] = "LVDS",
|
|
|
|
[DRM_MODE_CONNECTOR_Component] = "Component",
|
|
|
|
[DRM_MODE_CONNECTOR_9PinDIN] = "DIN",
|
|
|
|
[DRM_MODE_CONNECTOR_DisplayPort] = "DP",
|
|
|
|
[DRM_MODE_CONNECTOR_HDMIA] = "HDMI-A",
|
|
|
|
[DRM_MODE_CONNECTOR_HDMIB] = "HDMI-B",
|
|
|
|
[DRM_MODE_CONNECTOR_TV] = "TV",
|
|
|
|
[DRM_MODE_CONNECTOR_eDP] = "eDP",
|
|
|
|
[DRM_MODE_CONNECTOR_VIRTUAL] = "Virtual",
|
|
|
|
[DRM_MODE_CONNECTOR_DSI] = "DSI",
|
2018-08-20 18:11:38 +03:00
|
|
|
[DRM_MODE_CONNECTOR_DPI] = "DPI",
|
2012-07-27 01:57:15 +04:00
|
|
|
};
|
|
|
|
|
2017-04-03 13:33:26 +03:00
|
|
|
/** Create a name given a DRM connector
|
|
|
|
*
|
|
|
|
* \param con The DRM connector whose type and id form the name.
|
|
|
|
* \return A newly allocate string, or NULL on error. Must be free()'d
|
|
|
|
* after use.
|
|
|
|
*
|
|
|
|
* The name does not identify the DRM display device.
|
|
|
|
*/
|
2014-06-04 17:29:49 +04:00
|
|
|
static char *
|
|
|
|
make_connector_name(const drmModeConnector *con)
|
|
|
|
{
|
2017-04-03 13:33:26 +03:00
|
|
|
char *name;
|
2015-08-19 15:25:57 +03:00
|
|
|
const char *type_name = NULL;
|
2017-04-03 13:33:26 +03:00
|
|
|
int ret;
|
2014-06-04 17:29:49 +04:00
|
|
|
|
|
|
|
if (con->connector_type < ARRAY_LENGTH(connector_type_names))
|
|
|
|
type_name = connector_type_names[con->connector_type];
|
2015-08-19 15:25:57 +03:00
|
|
|
|
|
|
|
if (!type_name)
|
|
|
|
type_name = "UNNAMED";
|
|
|
|
|
2017-04-03 13:33:26 +03:00
|
|
|
ret = asprintf(&name, "%s-%d", type_name, con->connector_type_id);
|
|
|
|
if (ret < 0)
|
|
|
|
return NULL;
|
2014-06-04 17:29:49 +04:00
|
|
|
|
2017-04-03 13:33:26 +03:00
|
|
|
return name;
|
2014-06-04 17:29:49 +04:00
|
|
|
}
|
|
|
|
|
2013-01-25 17:13:05 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
drm_output_init_pixman(struct drm_output *output, struct drm_backend *b)
|
2013-01-25 17:13:05 +04:00
|
|
|
{
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2013-09-19 01:56:35 +04:00
|
|
|
int w = output->base.current_mode->width;
|
|
|
|
int h = output->base.current_mode->height;
|
2016-06-20 14:18:45 +03:00
|
|
|
uint32_t format = output->gbm_format;
|
|
|
|
uint32_t pixman_format;
|
2013-01-25 17:13:05 +04:00
|
|
|
unsigned int i;
|
2020-03-06 15:46:30 +03:00
|
|
|
const struct pixman_renderer_output_options options = {
|
|
|
|
.use_shadow = b->use_pixman_shadow,
|
|
|
|
};
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2016-06-20 14:18:45 +03:00
|
|
|
switch (format) {
|
2019-07-08 01:30:44 +03:00
|
|
|
case DRM_FORMAT_XRGB8888:
|
2016-06-20 14:18:45 +03:00
|
|
|
pixman_format = PIXMAN_x8r8g8b8;
|
|
|
|
break;
|
2019-07-08 01:30:44 +03:00
|
|
|
case DRM_FORMAT_RGB565:
|
2016-06-20 14:18:45 +03:00
|
|
|
pixman_format = PIXMAN_r5g6b5;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
weston_log("Unsupported pixman format 0x%x\n", format);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2016-06-20 14:18:45 +03:00
|
|
|
/* FIXME error checking */
|
2013-01-25 17:13:05 +04:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
|
2021-11-03 12:16:10 +03:00
|
|
|
output->dumb[i] = drm_fb_create_dumb(device, w, h, format);
|
2013-01-25 17:13:05 +04:00
|
|
|
if (!output->dumb[i])
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
output->image[i] =
|
2016-06-20 14:18:45 +03:00
|
|
|
pixman_image_create_bits(pixman_format, w, h,
|
2013-01-25 17:13:05 +04:00
|
|
|
output->dumb[i]->map,
|
2016-11-17 20:54:00 +03:00
|
|
|
output->dumb[i]->strides[0]);
|
2013-01-25 17:13:05 +04:00
|
|
|
if (!output->image[i])
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2020-03-06 15:46:30 +03:00
|
|
|
if (pixman_renderer_output_create(&output->base, &options) < 0)
|
2018-04-23 12:44:58 +03:00
|
|
|
goto err;
|
compositor-drm: Add aspect-ratio parsing support
The flag bits 19-22 of the connector modes, provide the aspect-ratio
information. This information can be stored in flags bits of the
weston mode structure, so that it can used for setting a mode with a
particular aspect-ratio.
Currently, DRM layer supports aspect-ratio with atomic-modesetting by
default. For legacy modeset path, the user-space needs to set the
drm client cap for aspect-ratio, if it wants aspect-ratio information
in modes.
This patch:
- preserves aspect-ratio flags from kernel video modes and
accommodates it in wayland mode.
- uses aspect-ratio to pick the appropriate mode during modeset.
- changes the mode format in configuration file weston.ini to
accommodate aspect-ratio information as:
WIDTHxHEIGHT@REFRESH-RATE ASPECT-RATIO
The aspect-ratio can take the following values :
4:3, 16:9, 64:27, 256:135.
v2: As per recommendation from Pekka Paalanen, Quentin Glidic,
Daniel Stone, dropped the aspect-ratio info from wayland protocol,
thereby avoiding exposure of aspect-ratio to the client.
v3: As suggested by Pekka Paalanen, added aspect_ratio field to store
aspect-ratio information from the drm. Also added drm client
capability for aspect-ratio, as recommended by Daniel Vetter.
v4: Minor modifications and fixes as suggested by Pekka Paalanen.
v5: Rebased, fixed some styling issues, and added aspect-ratio
information while printing weston_modes.
v6: Moved the man pages changes to a different patch. Minor
reorganization of code as suggested by Pekka Paalanen.
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
[Pekka: replace ARRAY_SIZE with ARRAY_LENGTH]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2097-03-18 21:54:57 +03:00
|
|
|
|
2018-04-23 12:44:58 +03:00
|
|
|
weston_log("DRM: output %s %s shadow framebuffer.\n", output->base.name,
|
|
|
|
b->use_pixman_shadow ? "uses" : "does not use");
|
2013-01-25 17:13:05 +04:00
|
|
|
|
|
|
|
pixman_region32_init_rect(&output->previous_damage,
|
2013-05-28 18:23:36 +04:00
|
|
|
output->base.x, output->base.y, output->base.width, output->base.height);
|
2013-01-25 17:13:05 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
|
|
|
|
if (output->dumb[i])
|
2017-04-04 19:54:26 +03:00
|
|
|
drm_fb_unref(output->dumb[i]);
|
2013-01-25 17:13:05 +04:00
|
|
|
if (output->image[i])
|
|
|
|
pixman_image_unref(output->image[i]);
|
|
|
|
|
|
|
|
output->dumb[i] = NULL;
|
|
|
|
output->image[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_output_fini_pixman(struct drm_output *output)
|
|
|
|
{
|
2018-01-16 18:37:33 +03:00
|
|
|
struct drm_backend *b = to_drm_backend(output->base.compositor);
|
2013-01-25 17:13:05 +04:00
|
|
|
unsigned int i;
|
|
|
|
|
2018-01-16 18:37:33 +03:00
|
|
|
/* Destroying the Pixman surface will destroy all our buffers,
|
|
|
|
* regardless of refcount. Ensure we destroy them here. */
|
|
|
|
if (!b->shutting_down &&
|
|
|
|
output->scanout_plane->state_cur->fb &&
|
|
|
|
output->scanout_plane->state_cur->fb->type == BUFFER_PIXMAN_DUMB) {
|
2020-05-18 15:22:49 +03:00
|
|
|
drm_plane_reset_state(output->scanout_plane);
|
2018-01-16 18:37:33 +03:00
|
|
|
}
|
|
|
|
|
2013-01-25 17:13:05 +04:00
|
|
|
pixman_renderer_output_destroy(&output->base);
|
|
|
|
pixman_region32_fini(&output->previous_damage);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
|
|
|
|
pixman_image_unref(output->image[i]);
|
2017-04-04 19:54:26 +03:00
|
|
|
drm_fb_unref(output->dumb[i]);
|
2013-01-25 17:13:05 +04:00
|
|
|
output->dumb[i] = NULL;
|
|
|
|
output->image[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 21:56:42 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
setup_output_seat_constraint(struct drm_backend *b,
|
2013-06-25 21:56:42 +04:00
|
|
|
struct weston_output *output,
|
|
|
|
const char *s)
|
|
|
|
{
|
|
|
|
if (strcmp(s, "") != 0) {
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_pointer *pointer;
|
2013-06-25 21:56:42 +04:00
|
|
|
struct udev_seat *seat;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
seat = udev_seat_get_named(&b->input, s);
|
2015-07-15 21:00:35 +03:00
|
|
|
if (!seat)
|
|
|
|
return;
|
|
|
|
|
|
|
|
seat->base.output = output;
|
2013-06-25 21:56:42 +04:00
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
pointer = weston_seat_get_pointer(&seat->base);
|
|
|
|
if (pointer)
|
|
|
|
weston_pointer_clamp(pointer,
|
|
|
|
&pointer->x,
|
|
|
|
&pointer->y);
|
2013-06-25 21:56:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
static int
|
|
|
|
drm_output_attach_head(struct weston_output *output_base,
|
|
|
|
struct weston_head *head_base)
|
|
|
|
{
|
2017-12-08 15:45:00 +03:00
|
|
|
struct drm_backend *b = to_drm_backend(output_base->compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2017-12-08 15:45:00 +03:00
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
if (wl_list_length(&output_base->head_list) >= MAX_CLONED_CONNECTORS)
|
|
|
|
return -1;
|
|
|
|
|
2017-12-08 15:45:00 +03:00
|
|
|
if (!output_base->enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* XXX: ensure the configuration will work.
|
|
|
|
* This is actually impossible without major infrastructure
|
|
|
|
* work. */
|
|
|
|
|
|
|
|
/* Need to go through modeset to add connectors. */
|
|
|
|
/* XXX: Ideally we'd do this per-output, not globally. */
|
|
|
|
/* XXX: Doing it globally, what guarantees another output's update
|
|
|
|
* will not clear the flag before this output is updated?
|
|
|
|
*/
|
2021-11-29 16:21:40 +03:00
|
|
|
device->state_invalid = true;
|
2017-12-08 15:45:00 +03:00
|
|
|
|
|
|
|
weston_output_schedule_repaint(output_base);
|
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-29 15:33:33 +03:00
|
|
|
static void
|
|
|
|
drm_output_detach_head(struct weston_output *output_base,
|
|
|
|
struct weston_head *head_base)
|
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(output_base->compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2017-11-29 15:33:33 +03:00
|
|
|
|
|
|
|
if (!output_base->enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Need to go through modeset to drop connectors that should no longer
|
|
|
|
* be driven. */
|
|
|
|
/* XXX: Ideally we'd do this per-output, not globally. */
|
2021-11-29 16:21:40 +03:00
|
|
|
device->state_invalid = true;
|
2017-11-29 15:33:33 +03:00
|
|
|
|
|
|
|
weston_output_schedule_repaint(output_base);
|
|
|
|
}
|
|
|
|
|
2019-07-09 01:50:30 +03:00
|
|
|
int
|
2016-04-30 01:40:34 +03:00
|
|
|
parse_gbm_format(const char *s, uint32_t default_value, uint32_t *gbm_format)
|
2014-03-07 22:05:50 +04:00
|
|
|
{
|
2018-09-26 14:33:36 +03:00
|
|
|
const struct pixel_format_info *pinfo;
|
2014-03-07 22:05:50 +04:00
|
|
|
|
2018-09-26 14:33:36 +03:00
|
|
|
if (s == NULL) {
|
2016-04-30 01:40:34 +03:00
|
|
|
*gbm_format = default_value;
|
2018-09-26 14:33:36 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pinfo = pixel_format_get_info_by_drm_name(s);
|
|
|
|
if (!pinfo) {
|
2014-03-07 22:05:50 +04:00
|
|
|
weston_log("fatal: unrecognized pixel format: %s\n", s);
|
2018-09-26 14:33:36 +03:00
|
|
|
|
|
|
|
return -1;
|
2014-03-07 22:05:50 +04:00
|
|
|
}
|
|
|
|
|
2018-09-26 14:33:36 +03:00
|
|
|
/* GBM formats and DRM formats are identical. */
|
|
|
|
*gbm_format = pinfo->format;
|
|
|
|
|
|
|
|
return 0;
|
2014-03-07 22:05:50 +04:00
|
|
|
}
|
|
|
|
|
2014-06-04 17:43:06 +04:00
|
|
|
static int
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_head_read_current_setup(struct drm_head *head, struct drm_device *device)
|
2014-06-04 17:43:06 +04:00
|
|
|
{
|
2021-11-29 16:21:40 +03:00
|
|
|
int drm_fd = device->drm.fd;
|
2020-06-17 17:09:47 +03:00
|
|
|
drmModeConnector *conn = head->connector.conn;
|
2014-06-04 17:43:06 +04:00
|
|
|
drmModeEncoder *encoder;
|
|
|
|
drmModeCrtc *crtc;
|
|
|
|
|
|
|
|
/* Get the current mode on the crtc that's currently driving
|
|
|
|
* this connector. */
|
2020-06-17 17:09:47 +03:00
|
|
|
encoder = drmModeGetEncoder(drm_fd, conn->encoder_id);
|
2014-06-04 17:43:06 +04:00
|
|
|
if (encoder != NULL) {
|
2017-11-20 14:31:06 +03:00
|
|
|
head->inherited_crtc_id = encoder->crtc_id;
|
|
|
|
|
2014-06-04 17:43:06 +04:00
|
|
|
crtc = drmModeGetCrtc(drm_fd, encoder->crtc_id);
|
|
|
|
drmModeFreeEncoder(encoder);
|
2017-11-20 14:31:06 +03:00
|
|
|
|
2014-06-04 17:43:06 +04:00
|
|
|
if (crtc == NULL)
|
|
|
|
return -1;
|
|
|
|
if (crtc->mode_valid)
|
2017-11-28 15:33:52 +03:00
|
|
|
head->inherited_mode = crtc->mode;
|
2014-06-04 17:43:06 +04:00
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
static void
|
|
|
|
drm_output_set_gbm_format(struct weston_output *base,
|
|
|
|
const char *gbm_format)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
|
|
|
|
2022-03-04 18:08:52 +03:00
|
|
|
if (parse_gbm_format(gbm_format,
|
|
|
|
DRM_FORMAT_INVALID, &output->gbm_format) == -1)
|
|
|
|
output->gbm_format = DRM_FORMAT_INVALID;
|
2016-09-30 15:11:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_output_set_seat(struct weston_output *base,
|
|
|
|
const char *seat)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
|
|
|
struct drm_backend *b = to_drm_backend(base->compositor);
|
|
|
|
|
|
|
|
setup_output_seat_constraint(b, &output->base,
|
|
|
|
seat ? seat : "");
|
|
|
|
}
|
|
|
|
|
2021-07-21 17:45:14 +03:00
|
|
|
static void
|
|
|
|
drm_output_set_max_bpc(struct weston_output *base, unsigned max_bpc)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
|
|
|
|
|
|
|
assert(output);
|
|
|
|
assert(!output->base.enabled);
|
|
|
|
|
|
|
|
output->max_bpc = max_bpc;
|
|
|
|
}
|
|
|
|
|
2017-09-05 16:37:03 +03:00
|
|
|
static int
|
|
|
|
drm_output_init_gamma_size(struct drm_output *output)
|
|
|
|
{
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2017-09-05 16:37:03 +03:00
|
|
|
drmModeCrtc *crtc;
|
|
|
|
|
|
|
|
assert(output->base.compositor);
|
2020-08-13 20:12:28 +03:00
|
|
|
assert(output->crtc);
|
2021-11-29 16:21:40 +03:00
|
|
|
crtc = drmModeGetCrtc(device->drm.fd, output->crtc->crtc_id);
|
2017-09-05 16:37:03 +03:00
|
|
|
if (!crtc)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
output->base.gamma_size = crtc->gamma_size;
|
|
|
|
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-20 14:31:06 +03:00
|
|
|
static uint32_t
|
2020-06-17 17:09:47 +03:00
|
|
|
drm_connector_get_possible_crtcs_mask(struct drm_connector *connector)
|
2017-11-20 14:31:06 +03:00
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_device *device = connector->device;
|
2017-11-20 14:31:06 +03:00
|
|
|
uint32_t possible_crtcs = 0;
|
2020-06-17 17:09:47 +03:00
|
|
|
drmModeConnector *conn = connector->conn;
|
2017-11-20 14:31:06 +03:00
|
|
|
drmModeEncoder *encoder;
|
|
|
|
int i;
|
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
for (i = 0; i < conn->count_encoders; i++) {
|
2021-11-29 16:21:40 +03:00
|
|
|
encoder = drmModeGetEncoder(device->drm.fd,
|
2020-06-17 17:09:47 +03:00
|
|
|
conn->encoders[i]);
|
2017-11-20 14:31:06 +03:00
|
|
|
if (!encoder)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
possible_crtcs |= encoder->possible_crtcs;
|
|
|
|
drmModeFreeEncoder(encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return possible_crtcs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Pick a CRTC that might be able to drive all attached connectors
|
|
|
|
*
|
|
|
|
* @param output The output whose attached heads to include.
|
2020-08-13 20:12:28 +03:00
|
|
|
* @return CRTC object to pick, or NULL on failure or not found.
|
2017-11-20 14:31:06 +03:00
|
|
|
*/
|
2020-08-13 20:12:28 +03:00
|
|
|
static struct drm_crtc *
|
|
|
|
drm_output_pick_crtc(struct drm_output *output)
|
2017-11-20 14:31:06 +03:00
|
|
|
{
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
|
|
|
struct drm_backend *backend = device->backend;
|
|
|
|
struct weston_compositor *compositor = backend->compositor;
|
2017-11-20 14:31:06 +03:00
|
|
|
struct weston_head *base;
|
|
|
|
struct drm_head *head;
|
2020-08-13 20:12:28 +03:00
|
|
|
struct drm_crtc *crtc;
|
|
|
|
struct drm_crtc *best_crtc = NULL;
|
|
|
|
struct drm_crtc *fallback_crtc = NULL;
|
|
|
|
struct drm_crtc *existing_crtc[32];
|
2017-11-20 14:31:06 +03:00
|
|
|
uint32_t possible_crtcs = 0xffffffff;
|
2020-08-13 20:12:28 +03:00
|
|
|
unsigned n = 0;
|
2017-11-20 14:31:06 +03:00
|
|
|
uint32_t crtc_id;
|
2020-08-13 20:12:28 +03:00
|
|
|
unsigned int i;
|
2017-11-28 17:11:00 +03:00
|
|
|
bool match;
|
2017-11-20 14:31:06 +03:00
|
|
|
|
|
|
|
/* This algorithm ignores drmModeEncoder::possible_clones restriction,
|
|
|
|
* because it is more often set wrong than not in the kernel. */
|
|
|
|
|
|
|
|
/* Accumulate a mask of possible crtcs and find existing routings. */
|
|
|
|
wl_list_for_each(base, &output->base.head_list, output_link) {
|
|
|
|
head = to_drm_head(base);
|
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
possible_crtcs &=
|
|
|
|
drm_connector_get_possible_crtcs_mask(&head->connector);
|
2017-11-20 14:31:06 +03:00
|
|
|
|
|
|
|
crtc_id = head->inherited_crtc_id;
|
|
|
|
if (crtc_id > 0 && n < ARRAY_LENGTH(existing_crtc))
|
2021-11-03 14:56:53 +03:00
|
|
|
existing_crtc[n++] = drm_crtc_find(device, crtc_id);
|
2017-11-20 14:31:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a crtc that could drive each connector individually at least,
|
|
|
|
* and prefer existing routings. */
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(crtc, &device->crtc_list, link) {
|
2017-11-20 14:31:06 +03:00
|
|
|
|
|
|
|
/* Could the crtc not drive each connector? */
|
2020-08-13 20:12:28 +03:00
|
|
|
if (!(possible_crtcs & (1 << crtc->pipe)))
|
2017-11-20 14:31:06 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Is the crtc already in use? */
|
2020-08-13 20:12:28 +03:00
|
|
|
if (crtc->output)
|
2017-11-20 14:31:06 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Try to preserve the existing CRTC -> connector routing;
|
|
|
|
* it makes initialisation faster, and also since we have a
|
|
|
|
* very dumb picking algorithm, may preserve a better
|
|
|
|
* choice. */
|
2020-08-13 20:12:28 +03:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (existing_crtc[i] == crtc)
|
|
|
|
return crtc;
|
2017-11-20 14:31:06 +03:00
|
|
|
}
|
|
|
|
|
2017-11-28 17:11:00 +03:00
|
|
|
/* Check if any other head had existing routing to this CRTC.
|
|
|
|
* If they did, this is not the best CRTC as it might be needed
|
|
|
|
* for another output we haven't enabled yet. */
|
|
|
|
match = false;
|
2021-11-03 18:36:17 +03:00
|
|
|
wl_list_for_each(base, &compositor->head_list, compositor_link) {
|
2017-11-28 17:11:00 +03:00
|
|
|
head = to_drm_head(base);
|
2021-03-11 13:04:32 +03:00
|
|
|
if (!head)
|
|
|
|
continue;
|
2017-11-28 17:11:00 +03:00
|
|
|
|
|
|
|
if (head->base.output == &output->base)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (weston_head_is_enabled(&head->base))
|
|
|
|
continue;
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
if (head->inherited_crtc_id == crtc->crtc_id) {
|
2017-11-28 17:11:00 +03:00
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match)
|
2020-08-13 20:12:28 +03:00
|
|
|
best_crtc = crtc;
|
2017-11-28 17:11:00 +03:00
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
fallback_crtc = crtc;
|
2017-11-20 14:31:06 +03:00
|
|
|
}
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
if (best_crtc)
|
|
|
|
return best_crtc;
|
2017-11-20 14:31:06 +03:00
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
if (fallback_crtc)
|
|
|
|
return fallback_crtc;
|
2017-11-28 17:11:00 +03:00
|
|
|
|
2017-11-20 14:31:06 +03:00
|
|
|
/* Likely possible_crtcs was empty due to asking for clones,
|
|
|
|
* but since the DRM documentation says the kernel lies, let's
|
|
|
|
* pick one crtc anyway. Trial and error is the only way to
|
|
|
|
* be sure if something doesn't work. */
|
|
|
|
|
|
|
|
/* First pick any existing assignment. */
|
2020-08-13 20:12:28 +03:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
crtc = existing_crtc[i];
|
|
|
|
if (!crtc->output)
|
|
|
|
return crtc;
|
2017-11-20 14:31:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise pick any available crtc. */
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(crtc, &device->crtc_list, link) {
|
2020-08-13 20:12:28 +03:00
|
|
|
if (!crtc->output)
|
|
|
|
return crtc;
|
|
|
|
}
|
2017-11-20 14:31:06 +03:00
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create an "empty" drm_crtc. It will only set its ID, pipe and props. After
|
|
|
|
* all, it adds the object to the DRM-backend CRTC list.
|
|
|
|
*/
|
|
|
|
static struct drm_crtc *
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_crtc_create(struct drm_device *device, uint32_t crtc_id, uint32_t pipe)
|
2020-08-13 20:12:28 +03:00
|
|
|
{
|
|
|
|
struct drm_crtc *crtc;
|
|
|
|
drmModeObjectPropertiesPtr props;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
props = drmModeObjectGetProperties(device->drm.fd, crtc_id,
|
2020-08-13 20:12:28 +03:00
|
|
|
DRM_MODE_OBJECT_CRTC);
|
|
|
|
if (!props) {
|
|
|
|
weston_log("failed to get CRTC properties\n");
|
|
|
|
return NULL;
|
2017-11-20 14:31:06 +03:00
|
|
|
}
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
crtc = zalloc(sizeof(*crtc));
|
|
|
|
if (!crtc)
|
|
|
|
goto ret;
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_property_info_populate(device, crtc_props, crtc->props_crtc,
|
2020-08-13 20:12:28 +03:00
|
|
|
WDRM_CRTC__COUNT, props);
|
2021-11-03 14:56:53 +03:00
|
|
|
crtc->device = device;
|
2020-08-13 20:12:28 +03:00
|
|
|
crtc->crtc_id = crtc_id;
|
|
|
|
crtc->pipe = pipe;
|
|
|
|
crtc->output = NULL;
|
|
|
|
|
|
|
|
/* Add it to the last position of the DRM-backend CRTC list */
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_insert(device->crtc_list.prev, &crtc->link);
|
2020-08-13 20:12:28 +03:00
|
|
|
|
|
|
|
ret:
|
|
|
|
drmModeFreeObjectProperties(props);
|
|
|
|
return crtc;
|
2017-11-20 14:31:06 +03:00
|
|
|
}
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
/** Destroy a drm_crtc object that was created with drm_crtc_create(). It will
|
|
|
|
* also remove it from the DRM-backend CRTC list.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drm_crtc_destroy(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
/* TODO: address the issue below to be able to remove the comment
|
|
|
|
* from the assert.
|
|
|
|
*
|
|
|
|
* https://gitlab.freedesktop.org/wayland/weston/-/issues/421
|
|
|
|
*/
|
|
|
|
|
|
|
|
//assert(!crtc->output);
|
|
|
|
|
|
|
|
wl_list_remove(&crtc->link);
|
|
|
|
drm_property_info_free(crtc->props_crtc, WDRM_CRTC__COUNT);
|
|
|
|
free(crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Find all CRTCs of the fd and create drm_crtc objects for them.
|
2017-09-05 16:11:15 +03:00
|
|
|
*
|
2020-08-13 20:12:28 +03:00
|
|
|
* The CRTCs are saved in a list of the drm_backend and will keep there until
|
|
|
|
* the fd gets closed.
|
2017-09-05 16:11:15 +03:00
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device The DRM device structure.
|
2020-10-13 17:25:20 +03:00
|
|
|
* @param resources The DRM resources, it is taken with drmModeGetResources
|
2020-08-13 20:12:28 +03:00
|
|
|
* @return 0 on success (at least one CRTC in the list), -1 on failure.
|
|
|
|
*/
|
|
|
|
static int
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_backend_create_crtc_list(struct drm_device *device, drmModeRes *resources)
|
2020-08-13 20:12:28 +03:00
|
|
|
{
|
|
|
|
struct drm_crtc *crtc, *crtc_tmp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Iterate through all CRTCs */
|
|
|
|
for (i = 0; i < resources->count_crtcs; i++) {
|
|
|
|
|
|
|
|
/* Let's create an object for the CRTC and add it to the list */
|
2021-11-03 14:56:53 +03:00
|
|
|
crtc = drm_crtc_create(device, resources->crtcs[i], i);
|
2020-08-13 20:12:28 +03:00
|
|
|
if (!crtc)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each_safe(crtc, crtc_tmp, &device->crtc_list, link)
|
2020-08-13 20:12:28 +03:00
|
|
|
drm_crtc_destroy(crtc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
|
|
|
|
/** Populates scanout and cursor planes for the output. Also sets the topology
|
|
|
|
* of the planes by adding them to the plane stacking list.
|
2017-09-05 16:11:15 +03:00
|
|
|
*/
|
|
|
|
static int
|
2020-08-13 22:44:02 +03:00
|
|
|
drm_output_init_planes(struct drm_output *output)
|
2017-09-05 16:11:15 +03:00
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(output->base.compositor);
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2017-09-05 16:11:15 +03:00
|
|
|
|
|
|
|
output->scanout_plane =
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_output_find_special_plane(device, output,
|
2017-09-05 16:11:15 +03:00
|
|
|
WDRM_PLANE_TYPE_PRIMARY);
|
|
|
|
if (!output->scanout_plane) {
|
|
|
|
weston_log("Failed to find primary plane for output %s\n",
|
|
|
|
output->base.name);
|
2020-08-13 20:12:28 +03:00
|
|
|
return -1;
|
2017-09-05 16:11:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
weston_compositor_stack_plane(b->compositor,
|
|
|
|
&output->scanout_plane->base,
|
|
|
|
&b->compositor->primary_plane);
|
|
|
|
|
2017-09-05 16:11:15 +03:00
|
|
|
/* Failing to find a cursor plane is not fatal, as we'll fall back
|
|
|
|
* to software cursor. */
|
|
|
|
output->cursor_plane =
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_output_find_special_plane(device, output,
|
2017-09-05 16:11:15 +03:00
|
|
|
WDRM_PLANE_TYPE_CURSOR);
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
if (output->cursor_plane)
|
|
|
|
weston_compositor_stack_plane(b->compositor,
|
|
|
|
&output->cursor_plane->base,
|
|
|
|
NULL);
|
|
|
|
else
|
2021-11-29 16:21:40 +03:00
|
|
|
device->cursors_are_broken = true;
|
2017-09-08 13:32:40 +03:00
|
|
|
|
2017-09-05 16:11:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
/** The opposite of drm_output_init_planes(). First of all it removes the planes
|
2020-10-12 19:37:07 +03:00
|
|
|
* from the plane stacking list. After all it sets the planes of the output as NULL.
|
2017-09-05 16:11:15 +03:00
|
|
|
*/
|
|
|
|
static void
|
2020-08-13 22:44:02 +03:00
|
|
|
drm_output_deinit_planes(struct drm_output *output)
|
2017-09-05 16:11:15 +03:00
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(output->base.compositor);
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
2017-09-05 16:11:15 +03:00
|
|
|
|
2020-05-18 15:26:01 +03:00
|
|
|
/* If the compositor is already shutting down, the planes have already
|
|
|
|
* been destroyed. */
|
|
|
|
if (!b->shutting_down) {
|
2020-09-16 15:04:04 +03:00
|
|
|
wl_list_remove(&output->scanout_plane->base.link);
|
|
|
|
wl_list_init(&output->scanout_plane->base.link);
|
|
|
|
|
|
|
|
if (output->cursor_plane) {
|
|
|
|
wl_list_remove(&output->cursor_plane->base.link);
|
|
|
|
wl_list_init(&output->cursor_plane->base.link);
|
|
|
|
/* Turn off hardware cursor */
|
2021-11-29 16:21:40 +03:00
|
|
|
drmModeSetCursor(device->drm.fd, output->crtc->crtc_id, 0, 0, 0);
|
2020-09-16 15:04:04 +03:00
|
|
|
}
|
|
|
|
|
2020-10-12 19:37:07 +03:00
|
|
|
/* With universal planes, the planes are allocated at startup,
|
|
|
|
* freed at shutdown, and live on the plane list in between.
|
|
|
|
* We want the planes to continue to exist and be freed up
|
|
|
|
* for other outputs.
|
|
|
|
*/
|
|
|
|
if (output->cursor_plane)
|
|
|
|
drm_plane_reset_state(output->cursor_plane);
|
|
|
|
if (output->scanout_plane)
|
|
|
|
drm_plane_reset_state(output->scanout_plane);
|
2017-09-05 16:11:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
output->cursor_plane = NULL;
|
|
|
|
output->scanout_plane = NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-12 20:48:36 +03:00
|
|
|
static struct weston_drm_format_array *
|
2021-11-29 16:12:27 +03:00
|
|
|
get_scanout_formats(struct drm_device *device)
|
2021-10-12 20:48:36 +03:00
|
|
|
{
|
2021-11-29 16:12:27 +03:00
|
|
|
struct weston_compositor *ec = device->backend->compositor;
|
2021-10-12 20:48:36 +03:00
|
|
|
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 */
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each(plane, &device->plane_list, link) {
|
2021-10-12 20:48:36 +03:00
|
|
|
/* 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);
|
2021-12-06 19:52:19 +03:00
|
|
|
free(scanout_formats);
|
2021-10-12 20:48:36 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
/** Pick a CRTC and reserve it for the output.
|
|
|
|
*
|
|
|
|
* On failure, the output remains without a CRTC.
|
|
|
|
*
|
|
|
|
* @param output The output with no CRTC associated.
|
|
|
|
* @return 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
drm_output_attach_crtc(struct drm_output *output)
|
|
|
|
{
|
|
|
|
output->crtc = drm_output_pick_crtc(output);
|
|
|
|
if (!output->crtc) {
|
|
|
|
weston_log("Output '%s': No available CRTCs.\n",
|
|
|
|
output->base.name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve the CRTC for the output */
|
|
|
|
output->crtc->output = output;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Release reservation of the CRTC.
|
|
|
|
*
|
|
|
|
* Make the CRTC free to be reserved and used by another output.
|
|
|
|
*
|
|
|
|
* @param output The output that will release its CRTC.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drm_output_detach_crtc(struct drm_output *output)
|
|
|
|
{
|
|
|
|
struct drm_crtc *crtc = output->crtc;
|
2017-09-08 13:32:40 +03:00
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
crtc->output = NULL;
|
|
|
|
output->crtc = NULL;
|
2017-09-05 16:11:15 +03:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
static int
|
|
|
|
drm_output_enable(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
2021-11-03 18:36:17 +03:00
|
|
|
struct drm_device *device = output->device;
|
|
|
|
struct drm_backend *b = device->backend;
|
2017-09-08 13:32:40 +03:00
|
|
|
int ret;
|
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
assert(output);
|
2018-01-31 11:50:48 +03:00
|
|
|
assert(!output->virtual);
|
|
|
|
|
2022-03-04 18:08:52 +03:00
|
|
|
if (output->gbm_format == DRM_FORMAT_INVALID) {
|
|
|
|
if (output->base.eotf_mode != WESTON_EOTF_MODE_SDR)
|
|
|
|
output->gbm_format = DRM_FORMAT_XRGB2101010;
|
|
|
|
else
|
|
|
|
output->gbm_format = b->gbm_format;
|
|
|
|
}
|
|
|
|
|
2020-08-13 20:12:28 +03:00
|
|
|
ret = drm_output_attach_crtc(output);
|
2017-09-08 13:32:40 +03:00
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
ret = drm_output_init_planes(output);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_crtc;
|
|
|
|
|
2017-09-08 13:32:40 +03:00
|
|
|
if (drm_output_init_gamma_size(output) < 0)
|
2020-08-13 22:44:02 +03:00
|
|
|
goto err_planes;
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2017-03-07 16:27:54 +03:00
|
|
|
if (b->pageflip_timeout)
|
|
|
|
drm_output_pageflip_timer_create(output);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
|
|
|
if (drm_output_init_pixman(output, b) < 0) {
|
2013-01-25 17:13:05 +04:00
|
|
|
weston_log("Failed to init output pixman state\n");
|
2020-08-13 22:44:02 +03:00
|
|
|
goto err_planes;
|
2013-01-25 17:13:05 +04:00
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
} else if (drm_output_init_egl(output, b) < 0) {
|
2012-12-14 19:37:29 +04:00
|
|
|
weston_log("Failed to init output gl state\n");
|
2020-08-13 22:44:02 +03:00
|
|
|
goto err_planes;
|
2012-10-21 21:29:26 +04:00
|
|
|
}
|
2012-05-03 19:39:35 +04:00
|
|
|
|
2017-11-15 13:51:01 +03:00
|
|
|
drm_output_init_backlight(output);
|
2012-02-29 21:53:50 +04:00
|
|
|
|
2013-04-06 01:07:11 +04:00
|
|
|
output->base.start_repaint_loop = drm_output_start_repaint_loop;
|
2012-01-26 08:32:28 +04:00
|
|
|
output->base.repaint = drm_output_repaint;
|
2012-02-23 18:45:49 +04:00
|
|
|
output->base.assign_planes = drm_assign_planes;
|
2012-02-29 21:53:50 +04:00
|
|
|
output->base.set_dpms = drm_set_dpms;
|
2012-04-17 13:20:48 +04:00
|
|
|
output->base.switch_mode = drm_output_switch_mode;
|
2013-05-02 00:52:12 +04:00
|
|
|
output->base.set_gamma = drm_output_set_gamma;
|
|
|
|
|
2017-11-15 14:37:18 +03:00
|
|
|
weston_log("Output %s (crtc %d) video modes:\n",
|
2020-08-13 20:12:28 +03:00
|
|
|
output->base.name, output->crtc->crtc_id);
|
2017-11-15 14:37:18 +03:00
|
|
|
drm_output_print_modes(output);
|
2012-06-09 00:45:33 +04:00
|
|
|
|
2010-06-11 20:56:24 +04:00
|
|
|
return 0;
|
2011-12-08 20:05:45 +04:00
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
err_planes:
|
|
|
|
drm_output_deinit_planes(output);
|
|
|
|
err_crtc:
|
2020-08-13 20:12:28 +03:00
|
|
|
drm_output_detach_crtc(output);
|
2016-09-30 15:11:05 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_output_deinit(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
|
|
|
struct drm_backend *b = to_drm_backend(base->compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2022-06-22 09:58:21 +03:00
|
|
|
struct drm_pending_state *pending;
|
|
|
|
|
|
|
|
if (!b->shutting_down) {
|
|
|
|
pending = drm_pending_state_alloc(device);
|
|
|
|
drm_output_get_disable_state(pending, output);
|
|
|
|
drm_pending_state_apply_sync(pending);
|
|
|
|
}
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2016-11-04 20:24:06 +03:00
|
|
|
if (b->use_pixman)
|
2016-09-30 15:11:05 +03:00
|
|
|
drm_output_fini_pixman(output);
|
2016-11-04 20:24:06 +03:00
|
|
|
else
|
|
|
|
drm_output_fini_egl(output);
|
2011-12-08 20:05:45 +04:00
|
|
|
|
2020-08-13 22:44:02 +03:00
|
|
|
drm_output_deinit_planes(output);
|
2020-08-13 20:12:28 +03:00
|
|
|
drm_output_detach_crtc(output);
|
2021-07-14 15:01:48 +03:00
|
|
|
|
|
|
|
if (output->hdr_output_metadata_blob_id) {
|
2021-11-29 16:21:40 +03:00
|
|
|
drmModeDestroyPropertyBlob(device->drm.fd,
|
2021-07-14 15:01:48 +03:00
|
|
|
output->hdr_output_metadata_blob_id);
|
|
|
|
output->hdr_output_metadata_blob_id = 0;
|
|
|
|
}
|
2016-09-30 15:11:05 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
void
|
2016-09-30 15:11:05 +03:00
|
|
|
drm_output_destroy(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_device *device = output->device;
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
assert(output);
|
2018-01-31 11:50:48 +03:00
|
|
|
assert(!output->virtual);
|
|
|
|
|
2019-06-17 13:23:25 +03:00
|
|
|
if (output->page_flip_pending || output->atomic_complete_pending) {
|
2019-12-09 04:50:55 +03:00
|
|
|
output->destroy_pending = true;
|
2016-09-30 15:11:05 +03:00
|
|
|
weston_log("destroy output while page flip pending\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-14 13:09:44 +03:00
|
|
|
drm_output_set_cursor_view(output, NULL);
|
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
if (output->base.enabled)
|
|
|
|
drm_output_deinit(&output->base);
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_mode_list_destroy(device, &output->base.mode_list);
|
2016-10-10 00:48:16 +03:00
|
|
|
|
2017-03-07 16:27:54 +03:00
|
|
|
if (output->pageflip_timer)
|
|
|
|
wl_event_source_remove(output->pageflip_timer);
|
|
|
|
|
2017-08-16 12:07:14 +03:00
|
|
|
weston_output_release(&output->base);
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2016-11-11 22:11:49 +03:00
|
|
|
assert(!output->state_last);
|
|
|
|
drm_output_state_free(output->state_cur);
|
|
|
|
|
2021-07-14 15:01:48 +03:00
|
|
|
assert(output->hdr_output_metadata_blob_id == 0);
|
|
|
|
|
2011-12-08 20:05:45 +04:00
|
|
|
free(output);
|
2016-09-30 15:11:05 +03:00
|
|
|
}
|
2012-03-12 02:27:41 +04:00
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
static int
|
|
|
|
drm_output_disable(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct drm_output *output = to_drm_output(base);
|
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
assert(output);
|
2018-01-31 11:50:48 +03:00
|
|
|
assert(!output->virtual);
|
|
|
|
|
2019-06-17 13:23:25 +03:00
|
|
|
if (output->page_flip_pending || output->atomic_complete_pending) {
|
2019-12-09 04:50:55 +03:00
|
|
|
output->disable_pending = true;
|
2016-09-30 15:11:05 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
compositor-drm: Move repaint state application to flush
Split repaint into two stages, as implied by the grouped-repaint
interface: drm_output_repaint generates the repaint state only, and
drm_repaint_flush applies it.
This also moves DPMS into output state. Previously, the usual way to
DPMS off was that repaint would be called and apply its state, followed
by set_dpms being called afterwards to push the DPMS state separately.
As this happens before the repaint_flush hook, with no change to DPMS we
would set DPMS off, then immediately re-enable the output by posting the
repaint. Not ideal.
Moving DPMS application at the same time complicates this patch, but I
couldn't find a way to split it; if we keep set_dpms before begin_flush
then we break DPMS off, or if we try to move DPMS to output state before
using the repaint flush, we get stuck as the repaint hook generates an
asynchronous state update, followed immediately by set_dpms generating a
synchronous state update.
In drm_output_update_complete, the *_pending flags are cleared
before any of the pending actions are taken; this ensures that the
actions cannot recurse.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-08 20:46:10 +03:00
|
|
|
weston_log("Disabling output %s\n", output->base.name);
|
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
if (output->base.enabled)
|
|
|
|
drm_output_deinit(&output->base);
|
|
|
|
|
2019-12-09 04:50:55 +03:00
|
|
|
output->disable_pending = false;
|
2016-09-30 15:11:05 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
/*
|
|
|
|
* This function converts the protection status from drm values to
|
|
|
|
* weston_hdcp_protection status. The drm values as read from the connector
|
|
|
|
* properties "Content Protection" and "HDCP Content Type" need to be converted
|
|
|
|
* to appropriate weston values, that can be sent to a client application.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_weston_protection_from_drm(enum wdrm_content_protection_state protection,
|
|
|
|
enum wdrm_hdcp_content_type type,
|
|
|
|
enum weston_hdcp_protection *weston_protection)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (protection >= WDRM_CONTENT_PROTECTION__COUNT)
|
|
|
|
return -1;
|
|
|
|
if (protection == WDRM_CONTENT_PROTECTION_DESIRED ||
|
|
|
|
protection == WDRM_CONTENT_PROTECTION_UNDESIRED) {
|
|
|
|
*weston_protection = WESTON_HDCP_DISABLE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (type >= WDRM_HDCP_CONTENT_TYPE__COUNT)
|
|
|
|
return -1;
|
|
|
|
if (type == WDRM_HDCP_CONTENT_TYPE0) {
|
|
|
|
*weston_protection = WESTON_HDCP_ENABLE_TYPE_0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (type == WDRM_HDCP_CONTENT_TYPE1) {
|
|
|
|
*weston_protection = WESTON_HDCP_ENABLE_TYPE_1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current content-protection status for a given head.
|
|
|
|
*
|
|
|
|
* @param head drm_head, whose protection is to be retrieved
|
|
|
|
* @return protection status in case of success, -1 otherwise
|
|
|
|
*/
|
|
|
|
static enum weston_hdcp_protection
|
2020-08-18 23:35:05 +03:00
|
|
|
drm_head_get_current_protection(struct drm_head *head)
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
{
|
2020-08-18 23:35:05 +03:00
|
|
|
drmModeObjectProperties *props = head->connector.props_drm;
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
struct drm_property_info *info;
|
|
|
|
enum wdrm_content_protection_state protection;
|
|
|
|
enum wdrm_hdcp_content_type type;
|
|
|
|
enum weston_hdcp_protection weston_hdcp = WESTON_HDCP_DISABLE;
|
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
info = &head->connector.props[WDRM_CONNECTOR_CONTENT_PROTECTION];
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
protection = drm_property_get_value(info, props,
|
|
|
|
WDRM_CONTENT_PROTECTION__COUNT);
|
|
|
|
|
|
|
|
if (protection == WDRM_CONTENT_PROTECTION__COUNT)
|
|
|
|
return WESTON_HDCP_DISABLE;
|
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
info = &head->connector.props[WDRM_CONNECTOR_HDCP_CONTENT_TYPE];
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
type = drm_property_get_value(info, props,
|
|
|
|
WDRM_HDCP_CONTENT_TYPE__COUNT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In case of platforms supporting HDCP1.4, only property
|
|
|
|
* 'Content Protection' is exposed and not the 'HDCP Content Type'
|
|
|
|
* for such cases HDCP Type 0 should be considered as the content-type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (type == WDRM_HDCP_CONTENT_TYPE__COUNT)
|
|
|
|
type = WDRM_HDCP_CONTENT_TYPE0;
|
|
|
|
|
|
|
|
if (get_weston_protection_from_drm(protection, type,
|
|
|
|
&weston_hdcp) == -1) {
|
|
|
|
weston_log("Invalid drm protection:%d type:%d, for head:%s connector-id:%d\n",
|
|
|
|
protection, type, head->base.name,
|
2020-06-17 17:09:47 +03:00
|
|
|
head->connector.connector_id);
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
return WESTON_HDCP_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return weston_hdcp;
|
|
|
|
}
|
|
|
|
|
2020-08-18 23:35:05 +03:00
|
|
|
static int
|
|
|
|
drm_connector_update_properties(struct drm_connector *connector)
|
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_device *device = connector->device;
|
2020-08-18 23:35:05 +03:00
|
|
|
drmModeObjectProperties *props;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
props = drmModeObjectGetProperties(device->drm.fd,
|
2020-08-18 23:35:05 +03:00
|
|
|
connector->connector_id,
|
|
|
|
DRM_MODE_OBJECT_CONNECTOR);
|
|
|
|
if (!props) {
|
|
|
|
weston_log("Error: failed to get connector properties\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connector->props_drm)
|
|
|
|
drmModeFreeObjectProperties(connector->props_drm);
|
|
|
|
connector->props_drm = props;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-31 16:18:48 +03:00
|
|
|
/** Replace connector data and monitor information
|
|
|
|
*
|
2020-06-17 17:09:47 +03:00
|
|
|
* @param connector The drm_connector object to be updated.
|
|
|
|
* @param conn The connector data to be owned by the drm_connector, must match
|
|
|
|
* the current drm_connector ID.
|
2017-08-31 16:18:48 +03:00
|
|
|
* @return 0 on success, -1 on failure.
|
|
|
|
*
|
|
|
|
* Takes ownership of @c connector on success, not on failure.
|
|
|
|
*/
|
|
|
|
static int
|
2020-06-17 17:09:47 +03:00
|
|
|
drm_connector_assign_connector_info(struct drm_connector *connector,
|
|
|
|
drmModeConnector *conn)
|
2017-08-31 16:18:48 +03:00
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_device *device = connector->device;
|
|
|
|
|
2020-09-09 19:12:35 +03:00
|
|
|
assert(connector->conn != conn);
|
2020-06-17 17:09:47 +03:00
|
|
|
assert(connector->connector_id == conn->connector_id);
|
2017-08-31 16:18:48 +03:00
|
|
|
|
2020-08-18 23:35:05 +03:00
|
|
|
if (drm_connector_update_properties(connector) < 0)
|
2017-08-31 16:18:48 +03:00
|
|
|
return -1;
|
|
|
|
|
2020-09-09 19:12:35 +03:00
|
|
|
if (connector->conn)
|
2020-06-17 17:09:47 +03:00
|
|
|
drmModeFreeConnector(connector->conn);
|
|
|
|
connector->conn = conn;
|
2017-08-31 16:18:48 +03:00
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
drm_property_info_free(connector->props, WDRM_CONNECTOR__COUNT);
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_property_info_populate(device, connector_props, connector->props,
|
2020-08-18 23:35:05 +03:00
|
|
|
WDRM_CONNECTOR__COUNT, connector->props_drm);
|
2017-08-31 16:18:48 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-09 19:12:35 +03:00
|
|
|
static void
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_connector_init(struct drm_device *device, struct drm_connector *connector,
|
2020-06-17 17:09:47 +03:00
|
|
|
uint32_t connector_id)
|
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
connector->device = device;
|
2020-06-17 17:09:47 +03:00
|
|
|
connector->connector_id = connector_id;
|
2020-09-09 19:12:35 +03:00
|
|
|
connector->conn = NULL;
|
2020-08-18 23:35:05 +03:00
|
|
|
connector->props_drm = NULL;
|
2020-06-17 17:09:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_connector_fini(struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
drmModeFreeConnector(connector->conn);
|
2020-08-18 23:35:05 +03:00
|
|
|
drmModeFreeObjectProperties(connector->props_drm);
|
2020-06-17 17:09:47 +03:00
|
|
|
drm_property_info_free(connector->props, WDRM_CONNECTOR__COUNT);
|
|
|
|
}
|
|
|
|
|
2017-11-09 16:10:11 +03:00
|
|
|
static void
|
|
|
|
drm_head_log_info(struct drm_head *head, const char *msg)
|
|
|
|
{
|
2021-07-12 17:30:06 +03:00
|
|
|
char *eotf_list;
|
|
|
|
|
2017-11-09 16:10:11 +03:00
|
|
|
if (head->base.connected) {
|
|
|
|
weston_log("DRM: head '%s' %s, connector %d is connected, "
|
|
|
|
"EDID make '%s', model '%s', serial '%s'\n",
|
2020-06-17 17:09:47 +03:00
|
|
|
head->base.name, msg, head->connector.connector_id,
|
2017-11-09 16:10:11 +03:00
|
|
|
head->base.make, head->base.model,
|
|
|
|
head->base.serial_number ?: "");
|
2021-07-12 17:30:06 +03:00
|
|
|
eotf_list = weston_eotf_mask_to_str(head->base.supported_eotf_mask);
|
|
|
|
if (eotf_list) {
|
|
|
|
weston_log_continue(STAMP_SPACE
|
|
|
|
"Supported EOTF modes: %s\n",
|
|
|
|
eotf_list);
|
|
|
|
}
|
|
|
|
free(eotf_list);
|
2017-11-09 16:10:11 +03:00
|
|
|
} else {
|
|
|
|
weston_log("DRM: head '%s' %s, connector %d is disconnected.\n",
|
2020-06-17 17:09:47 +03:00
|
|
|
head->base.name, msg, head->connector.connector_id);
|
2017-11-09 16:10:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 15:48:07 +03:00
|
|
|
/** Update connector and monitor information
|
|
|
|
*
|
|
|
|
* @param head The head to update.
|
2020-09-09 19:12:35 +03:00
|
|
|
* @param conn The DRM connector object.
|
|
|
|
* @returns 0 on success, -1 on failure.
|
2017-09-08 15:48:07 +03:00
|
|
|
*
|
2020-09-09 19:12:35 +03:00
|
|
|
* Updates monitor information and connection status. This may schedule a
|
|
|
|
* heads changed call to the user.
|
2020-09-15 21:30:35 +03:00
|
|
|
*
|
|
|
|
* Takes ownership of @c connector on success, not on failure.
|
2017-09-08 15:48:07 +03:00
|
|
|
*/
|
2020-09-09 19:12:35 +03:00
|
|
|
static int
|
|
|
|
drm_head_update_info(struct drm_head *head, drmModeConnector *conn)
|
2017-09-08 15:48:07 +03:00
|
|
|
{
|
2020-09-09 19:12:35 +03:00
|
|
|
int ret;
|
2017-09-08 15:48:07 +03:00
|
|
|
|
2020-09-09 19:12:35 +03:00
|
|
|
ret = drm_connector_assign_connector_info(&head->connector, conn);
|
2017-11-09 16:10:11 +03:00
|
|
|
|
2020-09-15 06:11:02 +03:00
|
|
|
update_head_from_connector(head);
|
|
|
|
weston_head_set_content_protection_status(&head->base,
|
|
|
|
drm_head_get_current_protection(head));
|
|
|
|
|
2017-11-09 16:10:11 +03:00
|
|
|
if (head->base.device_changed)
|
|
|
|
drm_head_log_info(head, "updated");
|
2020-09-09 19:12:35 +03:00
|
|
|
|
|
|
|
return ret;
|
2017-09-08 15:48:07 +03:00
|
|
|
}
|
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
/** Update writeback connector
|
|
|
|
*
|
|
|
|
* @param writeback The writeback to update.
|
|
|
|
* @param conn DRM connector object.
|
|
|
|
* @returns 0 on success, -1 on failure.
|
|
|
|
*
|
|
|
|
* Takes ownership of @c connector on success, not on failure.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
drm_writeback_update_info(struct drm_writeback *writeback, drmModeConnector *conn)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_connector_assign_connector_info(&writeback->connector, conn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
/**
|
|
|
|
* Create a Weston head for a connector
|
|
|
|
*
|
|
|
|
* Given a DRM connector, create a matching drm_head structure and add it
|
|
|
|
* to Weston's head list.
|
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device DRM device structure
|
2020-09-09 19:12:35 +03:00
|
|
|
* @param conn DRM connector object
|
2017-08-28 16:27:20 +03:00
|
|
|
* @param drm_device udev device pointer
|
2020-09-09 19:12:35 +03:00
|
|
|
* @returns 0 on success, -1 on failure
|
2020-09-15 21:30:35 +03:00
|
|
|
*
|
|
|
|
* Takes ownership of @c connector on success, not on failure.
|
2017-08-28 16:27:20 +03:00
|
|
|
*/
|
2020-09-09 19:12:35 +03:00
|
|
|
static int
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_head_create(struct drm_device *device, drmModeConnector *conn,
|
2017-08-28 16:27:20 +03:00
|
|
|
struct udev_device *drm_device)
|
|
|
|
{
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_backend *backend = device->backend;
|
2017-08-28 16:27:20 +03:00
|
|
|
struct drm_head *head;
|
|
|
|
char *name;
|
2020-06-17 17:09:47 +03:00
|
|
|
int ret;
|
2017-08-28 16:27:20 +03:00
|
|
|
|
|
|
|
head = zalloc(sizeof *head);
|
|
|
|
if (!head)
|
2020-09-09 19:12:35 +03:00
|
|
|
return -1;
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_connector_init(device, &head->connector, conn->connector_id);
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
name = make_connector_name(conn);
|
2017-08-28 16:27:20 +03:00
|
|
|
if (!name)
|
2020-09-09 19:12:35 +03:00
|
|
|
goto err;
|
2017-08-28 16:27:20 +03:00
|
|
|
|
|
|
|
weston_head_init(&head->base, name);
|
|
|
|
free(name);
|
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
head->base.backend_id = drm_head_destroy;
|
|
|
|
|
2020-09-15 06:11:02 +03:00
|
|
|
ret = drm_head_update_info(head, conn);
|
2020-06-17 17:09:47 +03:00
|
|
|
if (ret < 0)
|
2020-09-15 06:11:02 +03:00
|
|
|
goto err_update;
|
2017-09-04 12:21:24 +03:00
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
head->backlight = backlight_init(drm_device, conn->connector_type);
|
2017-08-31 16:18:48 +03:00
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
if (conn->connector_type == DRM_MODE_CONNECTOR_LVDS ||
|
|
|
|
conn->connector_type == DRM_MODE_CONNECTOR_eDP)
|
2017-08-31 16:18:48 +03:00
|
|
|
weston_head_set_internal(&head->base);
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
if (drm_head_read_current_setup(head, device) < 0) {
|
2017-09-11 14:06:11 +03:00
|
|
|
weston_log("Failed to retrieve current mode from connector %d.\n",
|
2020-06-17 17:09:47 +03:00
|
|
|
head->connector.connector_id);
|
2017-11-28 15:33:52 +03:00
|
|
|
/* Not fatal. */
|
2017-09-11 14:06:11 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
weston_compositor_add_head(backend->compositor, &head->base);
|
2017-11-09 16:10:11 +03:00
|
|
|
drm_head_log_info(head, "found");
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2020-09-09 19:12:35 +03:00
|
|
|
return 0;
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2020-09-15 06:11:02 +03:00
|
|
|
err_update:
|
2017-08-31 16:18:48 +03:00
|
|
|
weston_head_release(&head->base);
|
2020-06-17 17:09:47 +03:00
|
|
|
err:
|
2020-09-09 19:12:35 +03:00
|
|
|
drm_connector_fini(&head->connector);
|
2017-08-28 16:27:20 +03:00
|
|
|
free(head);
|
2020-09-09 19:12:35 +03:00
|
|
|
return -1;
|
2017-08-28 16:27:20 +03:00
|
|
|
}
|
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
void
|
|
|
|
drm_head_destroy(struct weston_head *base)
|
2017-08-28 16:27:20 +03:00
|
|
|
{
|
2021-03-11 13:04:32 +03:00
|
|
|
struct drm_head *head = to_drm_head(base);
|
|
|
|
|
|
|
|
assert(head);
|
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
weston_head_release(&head->base);
|
2017-09-04 12:21:24 +03:00
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
drm_connector_fini(&head->connector);
|
2017-08-31 16:18:48 +03:00
|
|
|
|
2017-09-04 12:21:24 +03:00
|
|
|
if (head->backlight)
|
|
|
|
backlight_destroy(head->backlight);
|
|
|
|
|
2017-08-28 16:27:20 +03:00
|
|
|
free(head);
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
/**
|
|
|
|
* Create a Weston output structure
|
|
|
|
*
|
2017-09-08 15:48:07 +03:00
|
|
|
* Create an "empty" drm_output. This is the implementation of
|
|
|
|
* weston_backend::create_output.
|
2016-09-30 15:11:05 +03:00
|
|
|
*
|
2017-09-08 15:48:07 +03:00
|
|
|
* Creating an output is usually followed by drm_output_attach_head()
|
|
|
|
* and drm_output_enable() to make use of it.
|
|
|
|
*
|
|
|
|
* @param compositor The compositor instance.
|
|
|
|
* @param name Name for the new output.
|
|
|
|
* @returns The output, or NULL on failure.
|
2016-09-30 15:11:05 +03:00
|
|
|
*/
|
2017-09-08 15:48:07 +03:00
|
|
|
static struct weston_output *
|
|
|
|
drm_output_create(struct weston_compositor *compositor, const char *name)
|
2016-09-30 15:11:05 +03:00
|
|
|
{
|
2017-09-08 15:48:07 +03:00
|
|
|
struct drm_backend *b = to_drm_backend(compositor);
|
2021-11-03 14:56:53 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2016-09-30 15:11:05 +03:00
|
|
|
struct drm_output *output;
|
|
|
|
|
|
|
|
output = zalloc(sizeof *output);
|
|
|
|
if (output == NULL)
|
2017-09-08 15:48:07 +03:00
|
|
|
return NULL;
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
output->device = device;
|
2020-08-13 20:12:28 +03:00
|
|
|
output->crtc = NULL;
|
|
|
|
|
2021-07-21 17:45:14 +03:00
|
|
|
output->max_bpc = 16;
|
2022-03-04 18:08:52 +03:00
|
|
|
output->gbm_format = DRM_FORMAT_INVALID;
|
2019-07-09 23:02:00 +03:00
|
|
|
#ifdef BUILD_DRM_GBM
|
2018-01-31 11:50:15 +03:00
|
|
|
output->gbm_bo_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
|
2019-07-09 23:02:00 +03:00
|
|
|
#endif
|
2018-07-20 21:00:06 +03:00
|
|
|
|
2017-09-08 15:48:07 +03:00
|
|
|
weston_output_init(&output->base, compositor, name);
|
2017-08-31 16:18:48 +03:00
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
output->base.enable = drm_output_enable;
|
|
|
|
output->base.destroy = drm_output_destroy;
|
|
|
|
output->base.disable = drm_output_disable;
|
2017-08-28 16:27:20 +03:00
|
|
|
output->base.attach_head = drm_output_attach_head;
|
2017-11-29 15:33:33 +03:00
|
|
|
output->base.detach_head = drm_output_detach_head;
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2019-12-09 04:50:55 +03:00
|
|
|
output->destroy_pending = false;
|
|
|
|
output->disable_pending = false;
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2017-03-24 16:39:24 +03:00
|
|
|
output->state_cur = drm_output_state_alloc(output, NULL);
|
2017-04-03 14:42:51 +03:00
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
weston_compositor_add_pending_output(&output->base, b->compositor);
|
|
|
|
|
2017-09-08 15:48:07 +03:00
|
|
|
return &output->base;
|
2010-06-11 20:56:24 +04:00
|
|
|
}
|
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
/**
|
|
|
|
* Create a Weston writeback for a writeback connector
|
|
|
|
*
|
|
|
|
* Given a DRM connector of type writeback, create a matching drm_writeback
|
|
|
|
* structure and add it to Weston's writeback list.
|
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device DRM device structure
|
2020-09-09 21:23:49 +03:00
|
|
|
* @param conn DRM connector object of type writeback
|
|
|
|
* @returns 0 on success, -1 on failure
|
|
|
|
*
|
|
|
|
* Takes ownership of @c connector on success, not on failure.
|
|
|
|
*/
|
|
|
|
static int
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_writeback_create(struct drm_device *device, drmModeConnector *conn)
|
2020-09-09 21:23:49 +03:00
|
|
|
{
|
|
|
|
struct drm_writeback *writeback;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
writeback = zalloc(sizeof *writeback);
|
|
|
|
assert(writeback);
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
writeback->device = device;
|
2020-09-09 21:23:49 +03:00
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_connector_init(device, &writeback->connector, conn->connector_id);
|
2020-09-09 21:23:49 +03:00
|
|
|
|
|
|
|
ret = drm_writeback_update_info(writeback, conn);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_insert(&device->writeback_connector_list, &writeback->link);
|
2020-09-09 21:23:49 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
drm_connector_fini(&writeback->connector);
|
|
|
|
free(writeback);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_writeback_destroy(struct drm_writeback *writeback)
|
|
|
|
{
|
|
|
|
drm_connector_fini(&writeback->connector);
|
|
|
|
wl_list_remove(&writeback->link);
|
|
|
|
|
|
|
|
free(writeback);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Given the DRM connector object of a connector, create drm_head or
|
|
|
|
* drm_writeback object (depending on the type of connector) for it.
|
2020-09-14 23:41:41 +03:00
|
|
|
*
|
2020-09-09 21:23:49 +03:00
|
|
|
* The object is then added to the DRM-backend list of heads or writebacks.
|
2020-09-14 23:41:41 +03:00
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device The DRM device structure
|
2020-09-14 23:41:41 +03:00
|
|
|
* @param conn The DRM connector object
|
|
|
|
* @param drm_device udev device pointer
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
static int
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_backend_add_connector(struct drm_device *device, drmModeConnector *conn,
|
2020-09-14 23:41:41 +03:00
|
|
|
struct udev_device *drm_device)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
if (conn->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) {
|
2021-11-03 14:56:53 +03:00
|
|
|
ret = drm_writeback_create(device, conn);
|
2020-09-09 21:23:49 +03:00
|
|
|
if (ret < 0)
|
|
|
|
weston_log("DRM: failed to create writeback for connector %d.\n",
|
|
|
|
conn->connector_id);
|
|
|
|
} else {
|
2021-11-03 14:56:53 +03:00
|
|
|
ret = drm_head_create(device, conn, drm_device);
|
2020-09-09 21:23:49 +03:00
|
|
|
if (ret < 0)
|
|
|
|
weston_log("DRM: failed to create head for connector %d.\n",
|
|
|
|
conn->connector_id);
|
|
|
|
}
|
2020-09-14 23:41:41 +03:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
/** Find all connectors of the fd and create drm_head or drm_writeback objects
|
|
|
|
* (depending on the type of connector they are) for each of them
|
|
|
|
*
|
|
|
|
* These objects are added to the DRM-backend lists of heads and writebacks.
|
|
|
|
*
|
2021-11-03 14:56:53 +03:00
|
|
|
* @param device The DRM device structure
|
2020-09-09 21:23:49 +03:00
|
|
|
* @param drm_device udev device pointer
|
2020-10-13 17:25:20 +03:00
|
|
|
* @param resources The DRM resources, it is taken with drmModeGetResources
|
2020-09-09 21:23:49 +03:00
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*/
|
2010-06-11 20:56:24 +04:00
|
|
|
static int
|
2021-11-03 14:56:53 +03:00
|
|
|
drm_backend_discover_connectors(struct drm_device *device,
|
|
|
|
struct udev_device *drm_device,
|
2020-10-13 17:25:20 +03:00
|
|
|
drmModeRes *resources)
|
2010-06-11 20:56:24 +04:00
|
|
|
{
|
2020-09-09 19:12:35 +03:00
|
|
|
drmModeConnector *conn;
|
|
|
|
int i, ret;
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
device->min_width = resources->min_width;
|
|
|
|
device->max_width = resources->max_width;
|
|
|
|
device->min_height = resources->min_height;
|
|
|
|
device->max_height = resources->max_height;
|
2012-08-09 23:18:28 +04:00
|
|
|
|
2010-06-11 20:56:24 +04:00
|
|
|
for (i = 0; i < resources->count_connectors; i++) {
|
2017-09-08 15:48:07 +03:00
|
|
|
uint32_t connector_id = resources->connectors[i];
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
conn = drmModeGetConnector(device->drm.fd, connector_id);
|
2020-09-09 19:12:35 +03:00
|
|
|
if (!conn)
|
|
|
|
continue;
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
ret = drm_backend_add_connector(device, conn, drm_device);
|
2020-09-14 23:41:41 +03:00
|
|
|
if (ret < 0)
|
2020-09-09 19:12:35 +03:00
|
|
|
drmModeFreeConnector(conn);
|
2010-06-11 20:56:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-14 23:19:12 +03:00
|
|
|
static bool
|
|
|
|
resources_has_connector(drmModeRes *resources, uint32_t connector_id)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < resources->count_connectors; i++) {
|
|
|
|
if (resources->connectors[i] == connector_id)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-15 17:08:41 +03:00
|
|
|
static void
|
2022-03-08 17:47:04 +03:00
|
|
|
drm_backend_update_connectors(struct drm_device *device,
|
|
|
|
struct udev_device *drm_device)
|
2011-03-15 17:08:41 +03:00
|
|
|
{
|
2022-03-08 17:47:04 +03:00
|
|
|
struct drm_backend *b = device->backend;
|
2011-03-15 17:08:41 +03:00
|
|
|
drmModeRes *resources;
|
2020-09-09 19:12:35 +03:00
|
|
|
drmModeConnector *conn;
|
2020-09-09 21:23:49 +03:00
|
|
|
struct weston_head *base, *base_next;
|
2017-08-31 15:41:57 +03:00
|
|
|
struct drm_head *head;
|
2020-09-09 21:23:49 +03:00
|
|
|
struct drm_writeback *writeback, *writeback_next;
|
2020-06-17 17:09:47 +03:00
|
|
|
uint32_t connector_id;
|
2020-09-09 19:12:35 +03:00
|
|
|
int i, ret;
|
2011-03-15 17:08:41 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
resources = drmModeGetResources(device->drm.fd);
|
2011-03-15 17:08:41 +03:00
|
|
|
if (!resources) {
|
2012-06-07 20:01:59 +04:00
|
|
|
weston_log("drmModeGetResources failed\n");
|
2011-03-15 17:08:41 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-08 15:48:07 +03:00
|
|
|
/* collect new connectors that have appeared, e.g. MST */
|
2011-03-15 17:08:41 +03:00
|
|
|
for (i = 0; i < resources->count_connectors; i++) {
|
2020-06-17 17:09:47 +03:00
|
|
|
connector_id = resources->connectors[i];
|
2011-08-30 13:38:26 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
conn = drmModeGetConnector(device->drm.fd, connector_id);
|
2020-09-09 19:12:35 +03:00
|
|
|
if (!conn)
|
|
|
|
continue;
|
|
|
|
|
2017-09-08 15:48:07 +03:00
|
|
|
head = drm_head_find_by_connector(b, connector_id);
|
2020-09-09 21:23:49 +03:00
|
|
|
writeback = drm_writeback_find_by_connector(b, connector_id);
|
|
|
|
|
|
|
|
/* Connector can't be owned by both a head and a writeback, so
|
|
|
|
* one of the searches must fail. */
|
|
|
|
assert(head == NULL || writeback == NULL);
|
|
|
|
|
2020-09-14 23:41:41 +03:00
|
|
|
if (head)
|
2020-09-09 19:12:35 +03:00
|
|
|
ret = drm_head_update_info(head, conn);
|
2020-09-09 21:23:49 +03:00
|
|
|
else if (writeback)
|
|
|
|
ret = drm_writeback_update_info(writeback, conn);
|
2020-09-14 23:41:41 +03:00
|
|
|
else
|
2021-11-03 14:56:53 +03:00
|
|
|
ret = drm_backend_add_connector(b->drm, conn, drm_device);
|
2020-09-14 23:41:41 +03:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
drmModeFreeConnector(conn);
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
/* Destroy head objects of connectors (except writeback connectors) that
|
|
|
|
* have disappeared. */
|
|
|
|
wl_list_for_each_safe(base, base_next,
|
2017-08-31 15:41:57 +03:00
|
|
|
&b->compositor->head_list, compositor_link) {
|
|
|
|
head = to_drm_head(base);
|
2021-03-11 13:04:32 +03:00
|
|
|
if (!head)
|
|
|
|
continue;
|
2020-06-17 17:09:47 +03:00
|
|
|
connector_id = head->connector.connector_id;
|
2016-09-30 15:11:05 +03:00
|
|
|
|
2022-03-08 17:47:04 +03:00
|
|
|
if (head->connector.device != device)
|
|
|
|
continue;
|
|
|
|
|
2020-09-14 23:19:12 +03:00
|
|
|
if (resources_has_connector(resources, connector_id))
|
2017-02-09 17:06:31 +03:00
|
|
|
continue;
|
|
|
|
|
2017-09-08 15:48:07 +03:00
|
|
|
weston_log("DRM: head '%s' (connector %d) disappeared.\n",
|
2020-06-17 17:09:47 +03:00
|
|
|
head->base.name, connector_id);
|
2021-03-11 13:04:32 +03:00
|
|
|
drm_head_destroy(base);
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
2017-02-09 17:06:31 +03:00
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
/* Destroy writeback objects of writeback connectors that have
|
|
|
|
* disappeared. */
|
|
|
|
wl_list_for_each_safe(writeback, writeback_next,
|
2021-11-29 16:21:40 +03:00
|
|
|
&b->drm->writeback_connector_list, link) {
|
2020-09-09 21:23:49 +03:00
|
|
|
connector_id = writeback->connector.connector_id;
|
|
|
|
|
|
|
|
if (resources_has_connector(resources, connector_id))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
weston_log("DRM: writeback connector (connector %d) disappeared.\n",
|
|
|
|
connector_id);
|
|
|
|
drm_writeback_destroy(writeback);
|
|
|
|
}
|
|
|
|
|
2017-02-09 17:06:31 +03:00
|
|
|
drmModeFreeResources(resources);
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
|
|
|
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
static enum wdrm_connector_property
|
2020-06-17 17:09:47 +03:00
|
|
|
drm_connector_find_property_by_id(struct drm_connector *connector,
|
|
|
|
uint32_t property_id)
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
enum wdrm_connector_property prop = WDRM_CONNECTOR__COUNT;
|
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
if (!connector || !property_id)
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
return WDRM_CONNECTOR__COUNT;
|
|
|
|
|
|
|
|
for (i = 0; i < WDRM_CONNECTOR__COUNT; i++)
|
2020-06-17 17:09:47 +03:00
|
|
|
if (connector->props[i].prop_id == property_id) {
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
prop = (enum wdrm_connector_property) i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drm_backend_update_conn_props(struct drm_backend *b,
|
|
|
|
uint32_t connector_id,
|
|
|
|
uint32_t property_id)
|
|
|
|
{
|
|
|
|
struct drm_head *head;
|
|
|
|
enum wdrm_connector_property conn_prop;
|
|
|
|
|
|
|
|
head = drm_head_find_by_connector(b, connector_id);
|
|
|
|
if (!head) {
|
|
|
|
weston_log("DRM: failed to find head for connector id: %d.\n",
|
|
|
|
connector_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-17 17:09:47 +03:00
|
|
|
conn_prop = drm_connector_find_property_by_id(&head->connector, property_id);
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (conn_prop >= WDRM_CONNECTOR__COUNT)
|
|
|
|
return;
|
|
|
|
|
2020-08-18 23:35:05 +03:00
|
|
|
if (drm_connector_update_properties(&head->connector) < 0)
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
return;
|
2020-08-18 23:35:05 +03:00
|
|
|
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (conn_prop == WDRM_CONNECTOR_CONTENT_PROTECTION) {
|
|
|
|
weston_head_set_content_protection_status(&head->base,
|
2020-08-18 23:35:05 +03:00
|
|
|
drm_head_get_current_protection(head));
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 17:08:41 +03:00
|
|
|
static int
|
2022-03-08 17:47:04 +03:00
|
|
|
udev_event_is_hotplug(struct drm_device *device, struct udev_device *udev_device)
|
2011-03-15 17:08:41 +03:00
|
|
|
{
|
2012-03-11 23:05:21 +04:00
|
|
|
const char *sysnum;
|
2012-03-11 23:05:22 +04:00
|
|
|
const char *val;
|
2012-03-11 23:05:21 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
sysnum = udev_device_get_sysnum(udev_device);
|
|
|
|
if (!sysnum || atoi(sysnum) != device->drm.id)
|
2012-03-11 23:05:21 +04:00
|
|
|
return 0;
|
2011-08-30 13:38:26 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
val = udev_device_get_property_value(udev_device, "HOTPLUG");
|
2012-03-11 23:05:22 +04:00
|
|
|
if (!val)
|
2011-03-15 17:08:41 +03:00
|
|
|
return 0;
|
|
|
|
|
2012-03-11 23:05:22 +04:00
|
|
|
return strcmp(val, "1") == 0;
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
|
|
|
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
static int
|
|
|
|
udev_event_is_conn_prop_change(struct drm_backend *b,
|
2021-11-29 16:21:40 +03:00
|
|
|
struct udev_device *udev_device,
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
uint32_t *connector_id,
|
|
|
|
uint32_t *property_id)
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
int id;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
val = udev_device_get_property_value(udev_device, "CONNECTOR");
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (!val || !safe_strtoint(val, &id))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
*connector_id = id;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
val = udev_device_get_property_value(udev_device, "PROPERTY");
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (!val || !safe_strtoint(val, &id))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
*property_id = id;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-04-22 20:27:57 +04:00
|
|
|
static int
|
2011-03-15 17:08:41 +03:00
|
|
|
udev_drm_event(int fd, uint32_t mask, void *data)
|
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct drm_backend *b = data;
|
2011-03-15 17:08:41 +03:00
|
|
|
struct udev_device *event;
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
uint32_t conn_id, prop_id;
|
2011-03-15 17:08:41 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
event = udev_monitor_receive_device(b->udev_monitor);
|
2011-08-30 13:38:26 +04:00
|
|
|
|
2022-03-08 17:47:04 +03:00
|
|
|
if (udev_event_is_hotplug(b->drm, event)) {
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (udev_event_is_conn_prop_change(b, event, &conn_id, &prop_id))
|
|
|
|
drm_backend_update_conn_props(b, conn_id, prop_id);
|
|
|
|
else
|
2022-03-08 17:47:04 +03:00
|
|
|
drm_backend_update_connectors(b->drm, event);
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
}
|
2011-03-15 17:08:41 +03:00
|
|
|
|
|
|
|
udev_device_unref(event);
|
2011-04-22 20:27:57 +04:00
|
|
|
|
|
|
|
return 1;
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
|
|
|
|
2010-12-02 00:52:15 +03:00
|
|
|
static void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
drm_destroy(struct weston_compositor *ec)
|
2010-12-02 00:52:15 +03:00
|
|
|
{
|
2016-08-05 16:54:18 +03:00
|
|
|
struct drm_backend *b = to_drm_backend(ec);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2017-08-28 16:27:20 +03:00
|
|
|
struct weston_head *base, *next;
|
2020-08-13 20:12:28 +03:00
|
|
|
struct drm_crtc *crtc, *crtc_tmp;
|
2020-09-09 21:23:49 +03:00
|
|
|
struct drm_writeback *writeback, *writeback_tmp;
|
2010-12-02 00:52:15 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_input_destroy(&b->input);
|
2012-03-29 00:36:09 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_event_source_remove(b->udev_drm_source);
|
|
|
|
wl_event_source_remove(b->drm_source);
|
2012-03-29 00:36:09 +04:00
|
|
|
|
2017-10-05 18:27:21 +03:00
|
|
|
b->shutting_down = true;
|
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
destroy_sprites(b->drm);
|
2013-05-10 20:36:04 +04:00
|
|
|
|
2019-12-18 21:52:18 +03:00
|
|
|
weston_log_scope_destroy(b->debug);
|
2018-07-20 12:21:28 +03:00
|
|
|
b->debug = NULL;
|
2013-10-25 17:26:32 +04:00
|
|
|
weston_compositor_shutdown(ec);
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_for_each_safe(crtc, crtc_tmp, &b->drm->crtc_list, link)
|
2020-08-13 20:12:28 +03:00
|
|
|
drm_crtc_destroy(crtc);
|
|
|
|
|
2021-03-11 13:04:32 +03:00
|
|
|
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
|
|
|
|
if (to_drm_head(base))
|
|
|
|
drm_head_destroy(base);
|
|
|
|
}
|
2017-08-28 16:27:20 +03:00
|
|
|
|
2020-09-09 21:23:49 +03:00
|
|
|
wl_list_for_each_safe(writeback, writeback_tmp,
|
2021-11-29 16:21:40 +03:00
|
|
|
&b->drm->writeback_connector_list, link)
|
2020-09-09 21:23:49 +03:00
|
|
|
drm_writeback_destroy(writeback);
|
|
|
|
|
2019-07-09 23:02:00 +03:00
|
|
|
#ifdef BUILD_DRM_GBM
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->gbm)
|
|
|
|
gbm_device_destroy(b->gbm);
|
2019-07-09 23:02:00 +03:00
|
|
|
#endif
|
2013-01-25 17:13:05 +04:00
|
|
|
|
2017-12-07 17:06:05 +03:00
|
|
|
udev_monitor_unref(b->udev_monitor);
|
2017-09-13 16:48:01 +03:00
|
|
|
udev_unref(b->udev);
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
weston_launcher_close(ec->launcher, device->drm.fd);
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_launcher_destroy(ec->launcher);
|
2010-12-02 00:52:15 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
free(device->drm.filename);
|
2022-06-25 05:27:42 +03:00
|
|
|
free(device);
|
2014-10-11 19:27:30 +04:00
|
|
|
free(b);
|
2010-12-02 00:52:15 +03:00
|
|
|
}
|
|
|
|
|
2011-05-06 23:15:37 +04:00
|
|
|
static void
|
2013-09-18 03:02:57 +04:00
|
|
|
session_notify(struct wl_listener *listener, void *data)
|
2011-05-06 23:15:37 +04:00
|
|
|
{
|
2013-09-18 03:02:57 +04:00
|
|
|
struct weston_compositor *compositor = data;
|
2016-08-05 16:54:18 +03:00
|
|
|
struct drm_backend *b = to_drm_backend(compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2022-06-13 18:22:22 +03:00
|
|
|
struct weston_output *output;
|
2011-05-06 23:15:37 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (compositor->session_active) {
|
2013-09-18 03:02:57 +04:00
|
|
|
weston_log("activating session\n");
|
2016-11-05 11:10:13 +03:00
|
|
|
weston_compositor_wake(compositor);
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
weston_compositor_damage_all(compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
device->state_invalid = true;
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_input_enable(&b->input);
|
2013-09-18 03:02:57 +04:00
|
|
|
} else {
|
|
|
|
weston_log("deactivating session\n");
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_input_disable(&b->input);
|
2012-04-10 08:08:45 +04:00
|
|
|
|
2013-03-29 16:01:56 +04:00
|
|
|
weston_compositor_offscreen(compositor);
|
2011-05-06 23:38:28 +04:00
|
|
|
|
2012-01-18 20:50:31 +04:00
|
|
|
/* If we have a repaint scheduled (either from a
|
|
|
|
* pending pageflip or the idle handler), make sure we
|
|
|
|
* cancel that so we don't try to pageflip when we're
|
2013-03-29 16:01:56 +04:00
|
|
|
* vt switched away. The OFFSCREEN state will prevent
|
2017-01-01 17:46:35 +03:00
|
|
|
* further attempts at repainting. When we switch
|
2012-01-18 20:50:31 +04:00
|
|
|
* back, we schedule a repaint, which will process
|
|
|
|
* pending frame callbacks. */
|
|
|
|
|
2022-06-13 18:22:22 +03:00
|
|
|
wl_list_for_each(output, &compositor->output_list, link)
|
|
|
|
if (to_drm_output(output))
|
|
|
|
output->repaint_needed = false;
|
2015-05-21 02:00:57 +03:00
|
|
|
}
|
2011-05-06 23:15:37 +04:00
|
|
|
}
|
|
|
|
|
2019-06-13 18:55:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle KMS GPU being added/removed
|
|
|
|
*
|
|
|
|
* If the device being added/removed is the KMS device, we activate/deactivate
|
|
|
|
* the compositor session.
|
|
|
|
*
|
|
|
|
* @param compositor The compositor instance.
|
2021-11-29 16:21:40 +03:00
|
|
|
* @param devnum The device being added/removed.
|
2019-06-13 18:55:44 +03:00
|
|
|
* @param added Whether the device is being added (or removed)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
drm_device_changed(struct weston_compositor *compositor,
|
2021-11-29 16:21:40 +03:00
|
|
|
dev_t devnum, bool added)
|
2019-06-13 18:55:44 +03:00
|
|
|
{
|
|
|
|
struct drm_backend *b = to_drm_backend(compositor);
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2019-06-13 18:55:44 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
if (device->drm.fd < 0 || device->drm.devnum != devnum ||
|
2019-07-02 18:31:22 +03:00
|
|
|
compositor->session_active == added)
|
2019-06-13 18:55:44 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
compositor->session_active = added;
|
|
|
|
wl_signal_emit(&compositor->session_signal, compositor);
|
|
|
|
}
|
|
|
|
|
2016-12-19 19:48:20 +03:00
|
|
|
/**
|
|
|
|
* Determines whether or not a device is capable of modesetting. If successful,
|
|
|
|
* sets b->drm.fd and b->drm.filename to the opened device.
|
|
|
|
*/
|
|
|
|
static bool
|
2021-11-04 12:50:38 +03:00
|
|
|
drm_device_is_kms(struct drm_backend *b, struct drm_device *device,
|
|
|
|
struct udev_device *udev_device)
|
2016-12-19 19:48:20 +03:00
|
|
|
{
|
2021-11-29 16:21:40 +03:00
|
|
|
struct weston_compositor *compositor = b->compositor;
|
|
|
|
const char *filename = udev_device_get_devnode(udev_device);
|
|
|
|
const char *sysnum = udev_device_get_sysnum(udev_device);
|
|
|
|
dev_t devnum = udev_device_get_devnum(udev_device);
|
2016-12-19 19:48:20 +03:00
|
|
|
drmModeRes *res;
|
2018-11-23 15:02:07 +03:00
|
|
|
int id = -1, fd;
|
2016-12-19 19:48:20 +03:00
|
|
|
|
|
|
|
if (!filename)
|
|
|
|
return false;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
fd = weston_launcher_open(compositor->launcher, filename, O_RDWR);
|
2016-12-19 19:48:20 +03:00
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
res = drmModeGetResources(fd);
|
|
|
|
if (!res)
|
|
|
|
goto out_fd;
|
|
|
|
|
|
|
|
if (res->count_crtcs <= 0 || res->count_connectors <= 0 ||
|
|
|
|
res->count_encoders <= 0)
|
|
|
|
goto out_res;
|
|
|
|
|
|
|
|
if (sysnum)
|
|
|
|
id = atoi(sysnum);
|
|
|
|
if (!sysnum || id < 0) {
|
|
|
|
weston_log("couldn't get sysnum for device %s\n", filename);
|
|
|
|
goto out_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can be called successfully on multiple devices; if we have,
|
|
|
|
* clean up old entries. */
|
2021-11-29 16:21:40 +03:00
|
|
|
if (device->drm.fd >= 0)
|
|
|
|
weston_launcher_close(compositor->launcher, device->drm.fd);
|
|
|
|
free(device->drm.filename);
|
2016-12-19 19:48:20 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
device->drm.fd = fd;
|
|
|
|
device->drm.id = id;
|
|
|
|
device->drm.filename = strdup(filename);
|
|
|
|
device->drm.devnum = devnum;
|
2016-12-19 19:48:20 +03:00
|
|
|
|
2017-03-28 13:44:04 +03:00
|
|
|
drmModeFreeResources(res);
|
|
|
|
|
2016-12-19 19:48:20 +03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
out_res:
|
|
|
|
drmModeFreeResources(res);
|
|
|
|
out_fd:
|
|
|
|
weston_launcher_close(b->compositor->launcher, fd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-29 22:21:16 +04:00
|
|
|
/*
|
|
|
|
* Find primary GPU
|
|
|
|
* Some systems may have multiple DRM devices attached to a single seat. This
|
|
|
|
* function loops over all devices and tries to find a PCI device with the
|
|
|
|
* boot_vga sysfs attribute set to 1.
|
|
|
|
* If no such device is found, the first DRM device reported by udev is used.
|
2016-12-19 19:48:20 +03:00
|
|
|
* Devices are also vetted to make sure they are are capable of modesetting,
|
|
|
|
* rather than pure render nodes (GPU with no display), or pure
|
|
|
|
* memory-allocation devices (VGEM).
|
2012-10-29 22:21:16 +04:00
|
|
|
*/
|
|
|
|
static struct udev_device*
|
2014-10-11 19:27:30 +04:00
|
|
|
find_primary_gpu(struct drm_backend *b, const char *seat)
|
2012-10-29 22:21:16 +04:00
|
|
|
{
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2012-10-29 22:21:16 +04:00
|
|
|
struct udev_enumerate *e;
|
|
|
|
struct udev_list_entry *entry;
|
|
|
|
const char *path, *device_seat, *id;
|
2021-11-29 16:21:40 +03:00
|
|
|
struct udev_device *dev, *drm_device, *pci;
|
2012-10-29 22:21:16 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
e = udev_enumerate_new(b->udev);
|
2012-10-29 22:21:16 +04:00
|
|
|
udev_enumerate_add_match_subsystem(e, "drm");
|
|
|
|
udev_enumerate_add_match_sysname(e, "card[0-9]*");
|
|
|
|
|
|
|
|
udev_enumerate_scan_devices(e);
|
|
|
|
drm_device = NULL;
|
|
|
|
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
|
2016-12-19 19:48:20 +03:00
|
|
|
bool is_boot_vga = false;
|
|
|
|
|
2012-10-29 22:21:16 +04:00
|
|
|
path = udev_list_entry_get_name(entry);
|
2021-11-29 16:21:40 +03:00
|
|
|
dev = udev_device_new_from_syspath(b->udev, path);
|
|
|
|
if (!dev)
|
2012-10-29 22:21:16 +04:00
|
|
|
continue;
|
2021-11-29 16:21:40 +03:00
|
|
|
device_seat = udev_device_get_property_value(dev, "ID_SEAT");
|
2012-10-29 22:21:16 +04:00
|
|
|
if (!device_seat)
|
|
|
|
device_seat = default_seat;
|
|
|
|
if (strcmp(device_seat, seat)) {
|
2021-11-29 16:21:40 +03:00
|
|
|
udev_device_unref(dev);
|
2012-10-29 22:21:16 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
pci = udev_device_get_parent_with_subsystem_devtype(dev,
|
2012-10-29 22:21:16 +04:00
|
|
|
"pci", NULL);
|
|
|
|
if (pci) {
|
|
|
|
id = udev_device_get_sysattr_value(pci, "boot_vga");
|
2016-12-19 19:48:20 +03:00
|
|
|
if (id && !strcmp(id, "1"))
|
|
|
|
is_boot_vga = true;
|
2012-10-29 22:21:16 +04:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:48:20 +03:00
|
|
|
/* If we already have a modesetting-capable device, and this
|
|
|
|
* device isn't our boot-VGA device, we aren't going to use
|
|
|
|
* it. */
|
|
|
|
if (!is_boot_vga && drm_device) {
|
2021-11-29 16:21:40 +03:00
|
|
|
udev_device_unref(dev);
|
2016-12-19 19:48:20 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure this device is actually capable of modesetting;
|
2021-11-29 16:21:40 +03:00
|
|
|
* if this call succeeds, device->drm.{fd,filename} will be set,
|
2016-12-19 19:48:20 +03:00
|
|
|
* and any old values freed. */
|
2021-11-04 12:50:38 +03:00
|
|
|
if (!drm_device_is_kms(b, b->drm, dev)) {
|
2021-11-29 16:21:40 +03:00
|
|
|
udev_device_unref(dev);
|
2016-12-19 19:48:20 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There can only be one boot_vga device, and we try to use it
|
|
|
|
* at all costs. */
|
|
|
|
if (is_boot_vga) {
|
|
|
|
if (drm_device)
|
|
|
|
udev_device_unref(drm_device);
|
2021-11-29 16:21:40 +03:00
|
|
|
drm_device = dev;
|
2016-12-19 19:48:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Per the (!is_boot_vga && drm_device) test above, we only
|
|
|
|
* trump existing saved devices with boot-VGA devices, so if
|
|
|
|
* we end up here, this must be the first device we've seen. */
|
|
|
|
assert(!drm_device);
|
2021-11-29 16:21:40 +03:00
|
|
|
drm_device = dev;
|
2012-10-29 22:21:16 +04:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:48:20 +03:00
|
|
|
/* If we're returning a device to use, we must have an open FD for
|
|
|
|
* it. */
|
2021-11-29 16:21:40 +03:00
|
|
|
assert(!!drm_device == (device->drm.fd >= 0));
|
2016-12-19 19:48:20 +03:00
|
|
|
|
2012-10-29 22:21:16 +04:00
|
|
|
udev_enumerate_unref(e);
|
|
|
|
return drm_device;
|
|
|
|
}
|
|
|
|
|
2017-03-28 18:04:27 +03:00
|
|
|
static struct udev_device *
|
2021-11-04 12:50:38 +03:00
|
|
|
open_specific_drm_device(struct drm_backend *b, struct drm_device *device,
|
|
|
|
const char *name)
|
2017-03-28 18:04:27 +03:00
|
|
|
{
|
2021-11-29 16:21:40 +03:00
|
|
|
struct udev_device *udev_device;
|
2017-03-28 18:04:27 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
udev_device = udev_device_new_from_subsystem_sysname(b->udev, "drm", name);
|
|
|
|
if (!udev_device) {
|
2017-03-28 18:04:27 +03:00
|
|
|
weston_log("ERROR: could not open DRM device '%s'\n", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-04 12:50:38 +03:00
|
|
|
if (!drm_device_is_kms(b, device, udev_device)) {
|
2021-11-29 16:21:40 +03:00
|
|
|
udev_device_unref(udev_device);
|
2017-03-28 18:04:27 +03:00
|
|
|
weston_log("ERROR: DRM device '%s' is not a KMS device.\n", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we're returning a device to use, we must have an open FD for
|
|
|
|
* it. */
|
2021-11-29 16:21:40 +03:00
|
|
|
assert(device->drm.fd >= 0);
|
2017-03-28 18:04:27 +03:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
return udev_device;
|
2017-03-28 18:04:27 +03:00
|
|
|
}
|
|
|
|
|
2012-10-31 19:55:46 +04:00
|
|
|
static void
|
2017-11-16 19:20:57 +03:00
|
|
|
planes_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
|
|
|
uint32_t key, void *data)
|
2012-10-31 19:55:46 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct drm_backend *b = data;
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2012-10-31 19:55:46 +04:00
|
|
|
|
2012-11-22 17:56:59 +04:00
|
|
|
switch (key) {
|
|
|
|
case KEY_C:
|
2021-11-29 16:21:40 +03:00
|
|
|
device->cursors_are_broken ^= true;
|
2012-11-22 17:56:59 +04:00
|
|
|
break;
|
|
|
|
case KEY_V:
|
compositor-drm: Only assign planes with atomic
Without atomic modesetting, we have no way to know whether or not our
desired configuration is usable. It might fail for a number of reasons:
scaling limits, bandwidth limits, global resource (e.g. decompression)
unit contention, or really just anything.
Not only this, but there is no good way to ensure that our configuration
actually lands together in the same refresh cycle - hence the 'atomic'
in atomic modesetting. Some drivers implement a synchronously blocking
drmModeSetPlane, whereas others return immediately. Using overlay planes
can thus decimate your framerate.
The pre-atomic API is not extensible either, so we need numerous out
clauses: fail if we're cropping or scaling (sometimes), or changing
formats, or fencing, or ...
Now we've had atomic support stable for a couple of releases, just
remove support for doing anything more fancy than displaying our
composited output and a cursor with drivers which don't support atomic
modesetting.
Support for using overlay planes was already disabled by default when
using the legacy API, and required a debug key combination to toggle it
on by flipping the sprites_are_broken variable. We can ensure that we
never try to use it on legacy by simply ignoring the hotkey when in
legacy mode.
Signed-off-by: Daniel Stone <daniels@collabora.com>
2019-06-17 13:13:20 +03:00
|
|
|
/* We don't support overlay-plane usage with legacy KMS. */
|
2021-11-29 16:21:40 +03:00
|
|
|
if (device->atomic_modeset)
|
|
|
|
device->sprites_are_broken ^= true;
|
2012-11-22 17:56:59 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-11-21 17:11:37 +04:00
|
|
|
}
|
|
|
|
|
2013-08-31 01:28:22 +04:00
|
|
|
#ifdef BUILD_VAAPI_RECORDER
|
2014-05-09 16:57:38 +04:00
|
|
|
static void
|
|
|
|
recorder_destroy(struct drm_output *output)
|
|
|
|
{
|
|
|
|
vaapi_recorder_destroy(output->recorder);
|
|
|
|
output->recorder = NULL;
|
|
|
|
|
2019-07-08 09:16:42 +03:00
|
|
|
weston_output_disable_planes_decr(&output->base);
|
2014-05-09 16:57:38 +04:00
|
|
|
|
|
|
|
wl_list_remove(&output->recorder_frame_listener.link);
|
|
|
|
weston_log("[libva recorder] done\n");
|
|
|
|
}
|
|
|
|
|
2013-08-23 18:15:48 +04:00
|
|
|
static void
|
|
|
|
recorder_frame_notify(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct drm_output *output;
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device;
|
2013-08-23 18:15:48 +04:00
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
output = container_of(listener, struct drm_output,
|
|
|
|
recorder_frame_listener);
|
2021-11-03 14:56:53 +03:00
|
|
|
device = output->device;
|
2013-08-23 18:15:48 +04:00
|
|
|
|
|
|
|
if (!output->recorder)
|
|
|
|
return;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
ret = drmPrimeHandleToFD(device->drm.fd,
|
2016-11-17 20:54:00 +03:00
|
|
|
output->scanout_plane->state_cur->fb->handles[0],
|
2013-08-23 18:15:48 +04:00
|
|
|
DRM_CLOEXEC, &fd);
|
|
|
|
if (ret) {
|
|
|
|
weston_log("[libva recorder] "
|
|
|
|
"failed to create prime fd for front buffer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-09 16:57:38 +04:00
|
|
|
ret = vaapi_recorder_frame(output->recorder, fd,
|
2016-11-17 20:54:00 +03:00
|
|
|
output->scanout_plane->state_cur->fb->strides[0]);
|
2014-05-09 16:57:38 +04:00
|
|
|
if (ret < 0) {
|
2019-04-27 00:57:31 +03:00
|
|
|
weston_log("[libva recorder] aborted: %s\n", strerror(errno));
|
2014-05-09 16:57:38 +04:00
|
|
|
recorder_destroy(output);
|
|
|
|
}
|
2013-08-23 18:15:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2014-10-11 19:27:30 +04:00
|
|
|
create_recorder(struct drm_backend *b, int width, int height,
|
2013-08-23 18:15:48 +04:00
|
|
|
const char *filename)
|
|
|
|
{
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device = b->drm;
|
2013-08-23 18:15:48 +04:00
|
|
|
int fd;
|
|
|
|
drm_magic_t magic;
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
fd = open(device->drm.filename, O_RDWR | O_CLOEXEC);
|
2013-08-23 18:15:48 +04:00
|
|
|
if (fd < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
drmGetMagic(fd, &magic);
|
2021-11-29 16:21:40 +03:00
|
|
|
drmAuthMagic(device->drm.fd, magic);
|
2013-08-23 18:15:48 +04:00
|
|
|
|
|
|
|
return vaapi_recorder_create(fd, width, height, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-16 19:20:57 +03:00
|
|
|
recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
|
|
|
uint32_t key, void *data)
|
2013-08-23 18:15:48 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct drm_backend *b = data;
|
2022-06-13 18:22:22 +03:00
|
|
|
struct weston_output *base_output;
|
2013-08-23 18:15:48 +04:00
|
|
|
struct drm_output *output;
|
|
|
|
int width, height;
|
|
|
|
|
2022-06-13 18:22:22 +03:00
|
|
|
wl_list_for_each(base_output, &b->compositor->output_list, link) {
|
|
|
|
output = to_drm_output(base_output);
|
|
|
|
if (output)
|
|
|
|
break;
|
|
|
|
}
|
2013-08-23 18:15:48 +04:00
|
|
|
|
|
|
|
if (!output->recorder) {
|
2019-10-20 19:25:42 +03:00
|
|
|
if (output->gbm_format != DRM_FORMAT_XRGB8888) {
|
2014-05-06 17:49:06 +04:00
|
|
|
weston_log("failed to start vaapi recorder: "
|
|
|
|
"output format not supported\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
width = output->base.current_mode->width;
|
|
|
|
height = output->base.current_mode->height;
|
2013-08-23 18:15:48 +04:00
|
|
|
|
|
|
|
output->recorder =
|
2014-10-11 19:27:30 +04:00
|
|
|
create_recorder(b, width, height, "capture.h264");
|
2013-08-23 18:15:48 +04:00
|
|
|
if (!output->recorder) {
|
|
|
|
weston_log("failed to create vaapi recorder\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-08 09:16:42 +03:00
|
|
|
weston_output_disable_planes_incr(&output->base);
|
2013-08-23 18:15:48 +04:00
|
|
|
|
|
|
|
output->recorder_frame_listener.notify = recorder_frame_notify;
|
|
|
|
wl_signal_add(&output->base.frame_signal,
|
|
|
|
&output->recorder_frame_listener);
|
|
|
|
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
|
|
|
|
weston_log("[libva recorder] initialized\n");
|
|
|
|
} else {
|
2014-05-09 16:57:38 +04:00
|
|
|
recorder_destroy(output);
|
2013-08-23 18:15:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void
|
2017-11-16 19:20:57 +03:00
|
|
|
recorder_binding(struct weston_keyboard *keyboard, const struct timespec *time,
|
|
|
|
uint32_t key, void *data)
|
2013-08-23 18:15:48 +04:00
|
|
|
{
|
|
|
|
weston_log("Compiled without libva support\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-19 17:22:04 +04:00
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
static const struct weston_drm_output_api api = {
|
|
|
|
drm_output_set_mode,
|
|
|
|
drm_output_set_gbm_format,
|
|
|
|
drm_output_set_seat,
|
2021-07-21 17:45:14 +03:00
|
|
|
drm_output_set_max_bpc,
|
2016-09-30 15:11:05 +03:00
|
|
|
};
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
static struct drm_backend *
|
|
|
|
drm_backend_create(struct weston_compositor *compositor,
|
2016-04-30 01:40:34 +03:00
|
|
|
struct weston_drm_backend_config *config)
|
2010-06-11 20:56:24 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct drm_backend *b;
|
2021-11-29 16:21:40 +03:00
|
|
|
struct drm_device *device;
|
2012-10-29 22:21:16 +04:00
|
|
|
struct udev_device *drm_device;
|
2010-06-11 20:56:24 +04:00
|
|
|
struct wl_event_loop *loop;
|
2016-04-30 01:40:34 +03:00
|
|
|
const char *seat_id = default_seat;
|
2018-06-29 15:17:46 +03:00
|
|
|
const char *session_seat;
|
2021-10-12 20:48:36 +03:00
|
|
|
struct weston_drm_format_array *scanout_formats;
|
2020-10-13 17:25:20 +03:00
|
|
|
drmModeRes *res;
|
2016-09-30 15:11:05 +03:00
|
|
|
int ret;
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2018-06-29 15:17:46 +03:00
|
|
|
session_seat = getenv("XDG_SEAT");
|
|
|
|
if (session_seat)
|
|
|
|
seat_id = session_seat;
|
|
|
|
|
|
|
|
if (config->seat_id)
|
|
|
|
seat_id = config->seat_id;
|
|
|
|
|
2012-06-09 00:45:33 +04:00
|
|
|
weston_log("initializing drm backend\n");
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b = zalloc(sizeof *b);
|
|
|
|
if (b == NULL)
|
2010-06-14 19:54:00 +04:00
|
|
|
return NULL;
|
2012-06-22 17:04:36 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
device = zalloc(sizeof *device);
|
|
|
|
if (device == NULL)
|
|
|
|
return NULL;
|
|
|
|
device->state_invalid = true;
|
|
|
|
device->drm.fd = -1;
|
|
|
|
device->backend = b;
|
|
|
|
|
|
|
|
b->drm = device;
|
2016-12-19 19:48:20 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->compositor = compositor;
|
2016-04-30 01:40:34 +03:00
|
|
|
b->use_pixman = config->use_pixman;
|
2017-03-07 16:27:54 +03:00
|
|
|
b->pageflip_timeout = config->pageflip_timeout;
|
2018-04-23 12:44:58 +03:00
|
|
|
b->use_pixman_shadow = config->use_pixman_shadow;
|
2013-10-17 03:31:42 +04:00
|
|
|
|
2019-12-26 22:23:43 +03:00
|
|
|
b->debug = weston_compositor_add_log_scope(compositor, "drm-backend",
|
|
|
|
"Debug messages from DRM/KMS backend\n",
|
|
|
|
NULL, NULL, NULL);
|
2018-07-20 12:21:28 +03:00
|
|
|
|
2017-08-30 11:29:49 +03:00
|
|
|
compositor->backend = &b->base;
|
|
|
|
|
2019-07-08 01:30:44 +03:00
|
|
|
if (parse_gbm_format(config->gbm_format, DRM_FORMAT_XRGB8888, &b->gbm_format) < 0)
|
2016-04-30 01:40:34 +03:00
|
|
|
goto err_compositor;
|
2013-10-17 03:31:42 +04:00
|
|
|
|
2021-07-23 19:36:56 +03:00
|
|
|
/* Check if we run drm-backend using a compatible launcher */
|
2022-03-02 19:51:15 +03:00
|
|
|
compositor->launcher = weston_launcher_connect(compositor, seat_id, true);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (compositor->launcher == NULL) {
|
2021-07-23 19:36:56 +03:00
|
|
|
weston_log("fatal: your system should either provide the "
|
|
|
|
"logind D-Bus API, or use seatd.\n");
|
2013-03-27 21:39:28 +04:00
|
|
|
goto err_compositor;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->udev = udev_new();
|
|
|
|
if (b->udev == NULL) {
|
2012-06-07 20:01:59 +04:00
|
|
|
weston_log("failed to initialize udev context\n");
|
2013-09-19 10:00:17 +04:00
|
|
|
goto err_launcher;
|
2010-06-11 20:56:24 +04:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->session_listener.notify = session_notify;
|
|
|
|
wl_signal_add(&compositor->session_signal, &b->session_listener);
|
2012-01-15 23:29:09 +04:00
|
|
|
|
2017-03-28 18:04:27 +03:00
|
|
|
if (config->specific_device)
|
2021-11-04 12:50:38 +03:00
|
|
|
drm_device = open_specific_drm_device(b, device,
|
|
|
|
config->specific_device);
|
2017-03-28 18:04:27 +03:00
|
|
|
else
|
|
|
|
drm_device = find_primary_gpu(b, seat_id);
|
2011-07-16 05:28:38 +04:00
|
|
|
if (drm_device == NULL) {
|
2012-06-07 20:01:59 +04:00
|
|
|
weston_log("no drm device found\n");
|
2013-09-19 10:00:17 +04:00
|
|
|
goto err_udev;
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2021-11-03 14:56:53 +03:00
|
|
|
if (init_kms_caps(device) < 0) {
|
2013-01-25 17:13:02 +04:00
|
|
|
weston_log("failed to initialize kms\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
|
|
|
if (init_pixman(b) < 0) {
|
2013-01-25 17:13:05 +04:00
|
|
|
weston_log("failed to initialize pixman renderer\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
|
|
|
} else {
|
2014-10-11 19:27:30 +04:00
|
|
|
if (init_egl(b) < 0) {
|
2013-01-25 17:13:05 +04:00
|
|
|
weston_log("failed to initialize egl\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
2010-06-11 20:56:24 +04:00
|
|
|
}
|
2011-01-15 00:20:21 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->base.destroy = drm_destroy;
|
2017-02-10 21:06:04 +03:00
|
|
|
b->base.repaint_begin = drm_repaint_begin;
|
|
|
|
b->base.repaint_flush = drm_repaint_flush;
|
|
|
|
b->base.repaint_cancel = drm_repaint_cancel;
|
2017-08-28 16:27:20 +03:00
|
|
|
b->base.create_output = drm_output_create;
|
2019-06-13 18:55:44 +03:00
|
|
|
b->base.device_changed = drm_device_changed;
|
2019-11-11 01:27:17 +03:00
|
|
|
b->base.can_scanout_dmabuf = drm_can_scanout_dmabuf;
|
2011-04-20 13:02:58 +04:00
|
|
|
|
2016-01-12 13:21:47 +03:00
|
|
|
weston_setup_vt_switch_bindings(compositor);
|
2012-04-10 08:11:50 +04:00
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
res = drmModeGetResources(b->drm->drm.fd);
|
2020-10-13 17:25:20 +03:00
|
|
|
if (!res) {
|
|
|
|
weston_log("Failed to get drmModeRes\n");
|
|
|
|
goto err_udev_dev;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_init(&b->drm->crtc_list);
|
2021-11-03 14:56:53 +03:00
|
|
|
if (drm_backend_create_crtc_list(b->drm, res) == -1) {
|
2020-08-13 20:12:28 +03:00
|
|
|
weston_log("Failed to create CRTC list for DRM-backend\n");
|
2020-10-13 17:25:20 +03:00
|
|
|
goto err_create_crtc_list;
|
2020-08-13 20:12:28 +03:00
|
|
|
}
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_init(&device->plane_list);
|
2021-11-03 14:56:53 +03:00
|
|
|
create_sprites(b->drm);
|
2012-02-23 18:45:49 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (udev_input_init(&b->input,
|
2016-06-02 21:48:12 +03:00
|
|
|
compositor, b->udev, seat_id,
|
|
|
|
config->configure_device) < 0) {
|
2014-04-17 14:08:45 +04:00
|
|
|
weston_log("failed to create input devices\n");
|
|
|
|
goto err_sprite;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_list_init(&b->drm->writeback_connector_list);
|
2021-11-03 14:56:53 +03:00
|
|
|
if (drm_backend_discover_connectors(b->drm, drm_device, res) < 0) {
|
2021-11-29 16:21:40 +03:00
|
|
|
weston_log("Failed to create heads for %s\n", b->drm->drm.filename);
|
2014-04-17 14:08:45 +04:00
|
|
|
goto err_udev_input;
|
2010-06-14 19:54:00 +04:00
|
|
|
}
|
|
|
|
|
2020-10-13 17:25:20 +03:00
|
|
|
drmModeFreeResources(res);
|
|
|
|
|
2019-10-29 18:29:37 +03:00
|
|
|
/* 'compute' faked zpos values in case HW doesn't expose any */
|
|
|
|
drm_backend_create_faked_zpos(b);
|
|
|
|
|
2014-04-03 04:53:46 +04:00
|
|
|
/* A this point we have some idea of whether or not we have a working
|
|
|
|
* cursor plane. */
|
2021-11-29 16:21:40 +03:00
|
|
|
if (!device->cursors_are_broken)
|
2014-10-11 19:27:30 +04:00
|
|
|
compositor->capabilities |= WESTON_CAP_CURSOR_PLANE;
|
2014-04-03 04:53:46 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
|
|
|
b->drm_source =
|
2021-11-29 16:21:40 +03:00
|
|
|
wl_event_loop_add_fd(loop, b->drm->drm.fd,
|
|
|
|
WL_EVENT_READABLE, on_drm_input, b->drm);
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->udev_monitor = udev_monitor_new_from_netlink(b->udev, "udev");
|
|
|
|
if (b->udev_monitor == NULL) {
|
2017-01-01 17:46:35 +03:00
|
|
|
weston_log("failed to initialize udev monitor\n");
|
2012-06-22 17:04:37 +04:00
|
|
|
goto err_drm_source;
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(b->udev_monitor,
|
2011-03-15 17:08:41 +03:00
|
|
|
"drm", NULL);
|
2014-10-11 19:27:30 +04:00
|
|
|
b->udev_drm_source =
|
2011-08-30 13:38:26 +04:00
|
|
|
wl_event_loop_add_fd(loop,
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_monitor_get_fd(b->udev_monitor),
|
|
|
|
WL_EVENT_READABLE, udev_drm_event, b);
|
2011-03-15 17:08:41 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (udev_monitor_enable_receiving(b->udev_monitor) < 0) {
|
2012-06-07 20:01:59 +04:00
|
|
|
weston_log("failed to enable udev-monitor receiving\n");
|
2012-06-22 17:04:37 +04:00
|
|
|
goto err_udev_monitor;
|
2011-03-15 17:08:41 +03:00
|
|
|
}
|
|
|
|
|
2012-06-22 17:04:37 +04:00
|
|
|
udev_device_unref(drm_device);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_O,
|
|
|
|
planes_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_C,
|
|
|
|
planes_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_V,
|
|
|
|
planes_binding, b);
|
|
|
|
weston_compositor_add_debug_binding(compositor, KEY_Q,
|
|
|
|
recorder_binding, b);
|
2012-10-31 19:55:46 +04:00
|
|
|
|
2014-06-12 16:12:48 +04:00
|
|
|
if (compositor->renderer->import_dmabuf) {
|
|
|
|
if (linux_dmabuf_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing dmabuf "
|
|
|
|
"support failed.\n");
|
2021-10-12 20:48:36 +03:00
|
|
|
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 */
|
2021-11-29 16:12:27 +03:00
|
|
|
scanout_formats = get_scanout_formats(b->drm);
|
2021-10-12 20:48:36 +03:00
|
|
|
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);
|
2021-12-06 19:52:19 +03:00
|
|
|
free(scanout_formats);
|
2021-10-12 20:48:36 +03:00
|
|
|
if (ret < 0)
|
|
|
|
goto err_udev_monitor;
|
|
|
|
}
|
2019-11-16 20:22:48 +03:00
|
|
|
if (weston_direct_display_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing direct-display "
|
|
|
|
"support failed.\n");
|
2014-06-12 16:12:48 +04:00
|
|
|
}
|
|
|
|
|
libweston: Support zwp_surface_synchronization_v1.set_acquire_fence
Implement the set_acquire_fence request of the
zwp_surface_synchronization_v1 interface.
The implementation uses the acquire fence in two ways:
1. If the associated buffer is used as GL render source, an
EGLSyncKHR is created from the fence and used to synchronize
access.
2. If the associated buffer is used as a plane framebuffer,
the acquire fence is treated as an in-fence for the atomic
commit operation. If in-fences are not supported and the buffer
has an acquire fence, we don't consider it for plane placement.
If the used compositor/renderer doesn't support explicit
synchronization, we don't advertise the protocol at all. Currently only
the DRM and X11 backends when using the GL renderer advertise the
protocol for production use.
Issues for discussion
---------------------
a. Currently, a server-side wait of EGLSyncKHR is performed before
using the EGLImage/texture during rendering. Unfortunately, it's not clear
from the specs whether this is generally safe to do, or we need to
sync before glEGLImageTargetTexture2DOES. The exception is
TEXTURE_EXTERNAL_OES where the spec mentions it's enough to sync
and then glBindTexture for any changes to take effect.
Changes in v5:
- Meson support.
- Make explicit sync server error reporting more generic, supporting
all explicit sync related interfaces not just
wp_linux_surface_synchronization.
- Fix typo in warning for missing EGL_KHR_wait_sync extension.
- Support minor version 2 of the explicit sync protocol (i.e., support
fences for opaque EGL buffers).
Changes in v4:
- Introduce and use fd_clear and and fd_move helpers.
- Don't check for a valid buffer when updating surface acquire fence fd
from state.
- Assert that pending state acquire fence fd is always clear
after a commit.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to just the
renderer.
- Check for EGL_KHR_wait_sync before using eglWaitSyncKHR.
- Dup the acquire fence before passing to EGL.
Changes in v3:
- Keep acquire_fence_fd in surface instead of buffer.
- Clarify that WESTON_CAP_EXPLICIT_SYNC applies to both backend and
renderer.
- Move comment about non-ownership of in_fence_fd to struct
drm_plane_state definition.
- Assert that we don't try to use planes with in-fences when using the
legacy KMS API.
- Remove unnecessary info from wayland error messages.
- Handle acquire fence for subsurface commits.
- Guard against self-update in fd_update.
- Disconnect the client if acquire fence EGLSyncKHR creation or wait
fails.
- Use updated protocol interface names.
- User correct format specifier for resource ids.
- Advertise protocol for X11 backend with GL renderer.
Changes in v2:
- Remove sync file wait fallbacks.
- Raise UNSUPPORTED_BUFFER error at commit if we have an acquire
fence, but the committed buffer is not a valid linux_dmabuf.
- Don't put buffers with in-fences on planes that don't support
in-fences.
- Don't advertise explicit sync protocol if backend does not
support explicit sync.
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2018-10-19 12:14:11 +03:00
|
|
|
if (compositor->capabilities & WESTON_CAP_EXPLICIT_SYNC) {
|
|
|
|
if (linux_explicit_synchronization_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing explicit "
|
|
|
|
" synchronization support failed.\n");
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:21:40 +03:00
|
|
|
if (device->atomic_modeset)
|
backend-drm: Add support for content-protection
Currently drm-layer supports HDCP1.4 using connector property:
Content Protection. This property if available for a platform, can be
read and set for requesting content-protection.
Also, the patch series [1] adds HDCP2.2 support in drm, and patch [2]
adds support to send udev events for change in connector properties,
made by the kernel.
This patch adds these HDCP connector properties in weston, and exposes
the content-protection support to the client for drm-backend.
It adds the enums to represent 'Content Protection' and 'Content Type'
connector properties exposed by drm layer. It adds a member
'protection' in drm_output_state, to store the desired protection
from the weston_output in the drm-backend output-repaint cycle. This
is then used to write the HDCP connector properties for the drm_heads
attached to the drm_output.
The kernel sends uevents to the user-space for any change made by it
in the "Content Protection" connector property. No event is sent in
case of change in the property made by the user-space.
It means, when there is a change of the property value from "DESIRED"
to "ENABLE" i.e. successful authentication by the kernel, a uevent
will be generated, but in case of userspace requesting for disabling
the protection by writing "UNDESIRED" into the property, no uevent
will be generated.
This patch also adds support for handling new udev events for HDCP
connector property changes. Any such change, triggers change in the
weston_head's current_protection.
[1] https://patchwork.freedesktop.org/series/57233/#rev7
[2] https://patchwork.freedesktop.org/patch/303903/?series=57233&rev=7
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
2019-05-14 16:06:08 +03:00
|
|
|
if (weston_compositor_enable_content_protection(compositor) < 0)
|
|
|
|
weston_log("Error: initializing content-protection "
|
|
|
|
"support failed.\n");
|
|
|
|
|
2016-09-30 15:11:05 +03:00
|
|
|
ret = weston_plugin_api_register(compositor, WESTON_DRM_OUTPUT_API_NAME,
|
|
|
|
&api, sizeof(api));
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
weston_log("Failed to register output API.\n");
|
|
|
|
goto err_udev_monitor;
|
|
|
|
}
|
|
|
|
|
2019-07-09 01:50:30 +03:00
|
|
|
ret = drm_backend_init_virtual_output_api(compositor);
|
2018-01-31 11:50:48 +03:00
|
|
|
if (ret < 0) {
|
|
|
|
weston_log("Failed to register virtual output API.\n");
|
|
|
|
goto err_udev_monitor;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
return b;
|
2012-06-22 17:04:37 +04:00
|
|
|
|
|
|
|
err_udev_monitor:
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_event_source_remove(b->udev_drm_source);
|
|
|
|
udev_monitor_unref(b->udev_monitor);
|
2012-06-22 17:04:37 +04:00
|
|
|
err_drm_source:
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_event_source_remove(b->drm_source);
|
2014-04-17 14:08:45 +04:00
|
|
|
err_udev_input:
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_input_destroy(&b->input);
|
2012-09-07 04:51:00 +04:00
|
|
|
err_sprite:
|
2021-11-03 14:56:53 +03:00
|
|
|
destroy_sprites(b->drm);
|
2020-10-13 17:25:20 +03:00
|
|
|
err_create_crtc_list:
|
|
|
|
drmModeFreeResources(res);
|
2012-06-22 17:04:37 +04:00
|
|
|
err_udev_dev:
|
|
|
|
udev_device_unref(drm_device);
|
|
|
|
err_udev:
|
2014-10-11 19:27:30 +04:00
|
|
|
udev_unref(b->udev);
|
2020-07-30 14:47:32 +03:00
|
|
|
err_launcher:
|
|
|
|
weston_launcher_destroy(compositor->launcher);
|
2012-06-22 17:04:37 +04:00
|
|
|
err_compositor:
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_shutdown(compositor);
|
2021-04-01 00:12:00 +03:00
|
|
|
#ifdef BUILD_DRM_GBM
|
|
|
|
if (b->gbm)
|
|
|
|
gbm_device_destroy(b->gbm);
|
|
|
|
#endif
|
2014-10-11 19:27:30 +04:00
|
|
|
free(b);
|
2012-06-22 17:04:37 +04:00
|
|
|
return NULL;
|
2010-06-11 20:56:24 +04:00
|
|
|
}
|
2011-05-03 06:09:20 +04:00
|
|
|
|
2016-04-30 01:40:34 +03:00
|
|
|
static void
|
|
|
|
config_init_to_defaults(struct weston_drm_backend_config *config)
|
|
|
|
{
|
2018-04-23 12:44:58 +03:00
|
|
|
config->use_pixman_shadow = true;
|
2016-04-30 01:40:34 +03:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
WL_EXPORT int
|
2016-12-02 16:08:44 +03:00
|
|
|
weston_backend_init(struct weston_compositor *compositor,
|
|
|
|
struct weston_backend_config *config_base)
|
2011-05-03 06:09:20 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct drm_backend *b;
|
2016-04-30 01:40:34 +03:00
|
|
|
struct weston_drm_backend_config config = {{ 0, }};
|
2012-03-12 05:05:57 +04:00
|
|
|
|
2016-04-30 01:40:34 +03:00
|
|
|
if (config_base == NULL ||
|
|
|
|
config_base->struct_version != WESTON_DRM_BACKEND_CONFIG_VERSION ||
|
|
|
|
config_base->struct_size > sizeof(struct weston_drm_backend_config)) {
|
|
|
|
weston_log("drm backend config structure is invalid\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-17 03:15:11 +04:00
|
|
|
|
2016-04-30 01:40:34 +03:00
|
|
|
config_init_to_defaults(&config);
|
|
|
|
memcpy(&config, config_base, config_base->struct_size);
|
2011-05-03 06:09:20 +04:00
|
|
|
|
2016-04-30 01:40:34 +03:00
|
|
|
b = drm_backend_create(compositor, &config);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b == NULL)
|
|
|
|
return -1;
|
2016-04-30 01:40:34 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
return 0;
|
2011-05-03 06:09:20 +04:00
|
|
|
}
|