grdev.c revision 2eec67acbb00593e414549a7e5b35eb7dd776b1b
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <libudev.h>
#include <stdbool.h>
#include <stdlib.h>
#include <systemd/sd-event.h>
#include "grdev.h"
#include "grdev-internal.h"
#include "hashmap.h"
#include "login-shared.h"
#include "macro.h"
#include "util.h"
/*
* Displays
*/
if (!tile)
return NULL;
return tile;
}
for (_i = tile_leftmost(_root); _i && ((_next = tile_leftmost(_i->children_by_node_next) ? : _i->parent), true); _i = _next)
grdev_tile *t;
if (display) {
TILE_FOREACH(tile, t) {
if (t->type == GRDEV_TILE_LEAF) {
}
}
}
}
grdev_tile *parent, *t;
if (!parent) {
return;
}
if (display) {
TILE_FOREACH(tile, t) {
if (t->type == GRDEV_TILE_LEAF) {
}
}
}
/* Tile trees are driven by leafs. Internal nodes have no owner, thus,
* we must take care to not leave them around. Therefore, whenever we
* unlink any part of a tree, we also destroy the parent, in case it's
* now stale.
* Parents are stale if they have no children and either have no display
* or if they are intermediate nodes (i.e, they have a parent).
* This means, you can easily create trees, but you can never partially
* move or destruct them so far. They're always reduced to minimal form
* if you cut them. This might change later, but so far we didn't need
* partial destruction or the ability to move whole trees. */
}
if (!tile)
return -ENOMEM;
return 0;
}
int r;
if (r < 0)
return r;
if (out)
return 0;
}
int r;
if (r < 0)
return r;
return 0;
}
if (!tile)
return NULL;
case GRDEV_TILE_LEAF:
break;
case GRDEV_TILE_NODE:
break;
}
return NULL;
}
}
int r;
if (!display)
return -ENOMEM;
return -ENOMEM;
if (r < 0)
return r;
if (r < 0)
return r;
if (out)
return 0;
}
if (!display)
return NULL;
}
return NULL;
}
}
}
}
assert_return(display, 0);
}
assert_return(display, 0);
}
}
grdev_tile *t;
if (t->type == GRDEV_TILE_LEAF)
}
}
grdev_tile *t;
if (t->type == GRDEV_TILE_LEAF)
}
}
const grdev_display_target *grdev_display_next_target(grdev_display *display, const grdev_display_target *prev) {
if (prev) {
} else {
idx = 0;
}
continue;
/* find suitable back-buffer */
continue;
continue;
}
return target;
}
return NULL;
}
}
assert(c);
assert(l);
t = &c->target;
/* rotate child */
x = t->x;
y = t->y;
switch (l->rotate) {
case GRDEV_ROTATE_0:
break;
case GRDEV_ROTATE_90:
t->y = x;
break;
case GRDEV_ROTATE_180:
break;
case GRDEV_ROTATE_270:
t->x = y;
break;
}
/* flip child */
if (l->flip & GRDEV_FLIP_HORIZONTAL)
if (l->flip & GRDEV_FLIP_VERTICAL)
/* move child */
t->x += l->x;
t->y += l->y;
}
/* depth-first with children before parent */
tile;
grdev_pipe *p;
/* We're at a leaf and no parent has been cached, yet.
* Copy the pipe information into the target cache and
* update our global pipe-caches if required. */
zero(*c);
c->pipe = p;
/* all new tiles are incomplete due to geometry changes */
c->incomplete = true;
display_cache_apply(c, tile);
} else {
grdev_tile *child, *l;
/* We're now at a node with all its children already
* computed (depth-first, child before parent). We
* first need to know the size of our tile, then we
* recurse into all leafs and update their cache. */
}
TILE_FOREACH(tile, l)
if (l->type == GRDEV_TILE_LEAF)
}
}
}
size_t n;
void *t;
int r;
return false;
return false;
if (!n) {
r = -ENOMEM;
goto out;
}
if (!t) {
r = -ENOMEM;
goto out;
}
}
r = 0;
out:
if (r < 0)
log_debug_errno(r, "grdev: %s/%s: cannot cache pipes: %m",
return true;
}
/*
* Pipes
*/
}
return 0;
}
int r;
return -ENOMEM;
if (n_fbs > 0) {
return -ENOMEM;
}
if (r < 0)
return r;
0,
10 * USEC_PER_MSEC,
pipe);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
if (!pipe)
return NULL;
return NULL;
}
}
}
}
}
/* grdev_pipe_ready() is used by backends to notify about pipe state
* changed. If a pipe is ready, it can be fully used by us (available,
* enabled and accessible). Backends can disable pipes at any time
* (like for async revocation), but can only enable them from parent
* context. Otherwise, we might call user-callbacks recursively. */
return;
/* runtime events for unused pipes are not interesting */
if (running)
else
}
}
/* if pipe is unused, ignore any frame events */
return;
grdev_pipe_schedule(pipe, 0);
}
int r;
if (!frames) {
return;
}
if (r < 0)
goto error;
if (r < 0)
goto error;
if (r < 0)
goto error;
return;
log_debug_errno(r, "grdev: %s/%s/%s: cannot schedule vsync timer: %m",
}
/*
* Cards
*/
}
int r;
return -ENOMEM;
return -ENOMEM;
if (r < 0)
return r;
return 0;
}
if (!card)
return NULL;
return NULL;
}
}
}
}
}
}
/*
* Sessions
*/
}
grdev_event event = {
.display_add = {
},
};
}
grdev_event event = {
.display_remove = {
},
};
}
grdev_event event = {
.display_change = {
},
};
}
grdev_event event = {
.display_frame = {
},
};
}
/* Cards are not exposed to users, but managed internally. Cards are
* enabled if the session is enabled, and will track that state. The
* backend can probe the card at any time, but only if enabled. It
* will then add pipes according to hardware state.
* That is, the card may create pipes as soon as we enable it here. */
}
/* As cards are not exposed, it can never be accessed by outside
* users and we can simply remove it. Disabling the card does not
* necessarily drop all pipes of the card. This is usually deferred
* to card destruction (as pipes are cached as long as FDs remain
* open). Therefore, the card destruction might cause pipes, and thus
* visible displays, to be removed. */
}
/* Displays are the main entity for public API users. We create them
* independent of card backends and they wrap any underlying display
* architecture. Displays are public at all times, thus, may be entered
* by outside users at any time. */
}
/* Displays are public, so we have to be careful when removing them.
* We first tell users about their removal, disable them and then drop
* them. We now, after the notification, no external access will
* happen. Therefore, we can release the tiles afterwards safely. */
}
}
bool changed;
} else if (changed) {
}
}
return;
else
}
unsigned int flags,
const char *name,
void *userdata) {
int r;
if (!session)
return -ENOMEM;
return -ENOMEM;
r = sd_bus_path_encode("/org/freedesktop/login1/session",
if (r < 0)
return r;
}
return -ENOMEM;
if (!session->display_map)
return -ENOMEM;
if (r < 0)
return r;
return 0;
}
if (!session)
return NULL;
return NULL;
}
}
}
}
}
}
return;
}
return;
}
int r;
if (devnum == 0)
if (card)
return;
if (r < 0) {
log_debug_errno(r, "grdev: %s: cannot add DRM device for %s: %m",
return;
}
}
if (devnum == 0)
if (!card)
return;
}
struct udev_device *p;
if (devnum == 0)
continue;
if (card)
break;
}
if (!card)
return;
}
Iterator i, j;
int r;
/*
* Whenever backends add or remove pipes, we set session->modified and
* require them to pin the session while modifying it. On release, we
* reconfigure the device and re-assign displays to all modified pipes.
*
* So far, we configure each pipe as a separate display. We do not
* support user-configuration, nor have we gotten any reports from
* users with multi-pipe monitors (4k on DP-1.2 MST and so on). Until
* we get reports, we keep the logic to a minimum.
*/
/* create new displays for all unconfigured pipes */
continue;
continue;
log_debug("grdev: %s/%s: occupied display for pipe %s",
continue;
} else if (!display) {
if (r < 0) {
log_debug_errno(r, "grdev: %s/%s: cannot create display for pipe %s: %m",
continue;
}
}
}
}
/* update displays */
}
return session;
}
if (!session)
return NULL;
return NULL;
}
/*
* Contexts
*/
if (!context)
return -ENOMEM;
if (sysbus)
if (!context->session_map)
return -ENOMEM;
return 0;
}
}
return context;
}
if (!context)
return NULL;
return NULL;
}