mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2024-12-27 21:59:24 +01:00
Check plane is compatible with CRTC
This allows us to rule out some potential solutions. Closes: https://github.com/emersion/libhwc/issues/2
This commit is contained in:
parent
66bedbc854
commit
d90d7bdc36
3 changed files with 42 additions and 0 deletions
23
display.c
23
display.c
|
@ -70,6 +70,7 @@ static void plane_destroy(struct hwc_plane *plane)
|
|||
struct hwc_display *hwc_display_create(int drm_fd)
|
||||
{
|
||||
struct hwc_display *display;
|
||||
drmModeRes *drm_res;
|
||||
drmModePlaneRes *drm_plane_res;
|
||||
uint32_t i;
|
||||
|
||||
|
@ -86,6 +87,24 @@ struct hwc_display *hwc_display_create(int drm_fd)
|
|||
hwc_list_init(&display->planes);
|
||||
hwc_list_init(&display->outputs);
|
||||
|
||||
drm_res = drmModeGetResources(drm_fd);
|
||||
if (drm_res == NULL) {
|
||||
hwc_display_destroy(display);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
display->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
|
||||
if (display->crtcs == NULL) {
|
||||
drmModeFreeResources(drm_res);
|
||||
hwc_display_destroy(display);
|
||||
return NULL;
|
||||
}
|
||||
display->crtcs_len = drm_res->count_crtcs;
|
||||
memcpy(display->crtcs, drm_res->crtcs,
|
||||
drm_res->count_crtcs * sizeof(uint32_t));
|
||||
|
||||
drmModeFreeResources(drm_res);
|
||||
|
||||
/* TODO: allow users to choose which layers to hand over */
|
||||
drm_plane_res = drmModeGetPlaneResources(drm_fd);
|
||||
if (drm_plane_res == NULL) {
|
||||
|
@ -112,6 +131,7 @@ void hwc_display_destroy(struct hwc_display *display)
|
|||
hwc_list_for_each_safe(plane, tmp, &display->planes, link) {
|
||||
plane_destroy(plane);
|
||||
}
|
||||
free(display->crtcs);
|
||||
free(display);
|
||||
}
|
||||
|
||||
|
@ -222,6 +242,9 @@ bool output_choose_layers(struct hwc_output *output, struct plane_alloc *alloc,
|
|||
if (plane->layer != NULL) {
|
||||
goto skip;
|
||||
}
|
||||
if ((plane->possible_crtcs & (1 << output->crtc_index)) == 0) {
|
||||
goto skip;
|
||||
}
|
||||
|
||||
hwc_list_for_each(layer, &output->layers, link) {
|
||||
if (layer->plane != NULL) {
|
||||
|
|
|
@ -9,11 +9,15 @@ struct hwc_display {
|
|||
|
||||
struct hwc_list planes; /* hwc_plane.link */
|
||||
struct hwc_list outputs; /* hwc_output.link */
|
||||
|
||||
uint32_t *crtcs;
|
||||
size_t crtcs_len;
|
||||
};
|
||||
|
||||
struct hwc_output {
|
||||
struct hwc_display *display;
|
||||
uint32_t crtc_id;
|
||||
size_t crtc_index;
|
||||
struct hwc_list link; /* hwc_display.outputs */
|
||||
|
||||
struct hwc_list layers; /* hwc_layer.link */
|
||||
|
|
15
output.c
15
output.c
|
@ -1,11 +1,25 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "private.h"
|
||||
|
||||
struct hwc_output *hwc_output_create(struct hwc_display *display,
|
||||
uint32_t crtc_id)
|
||||
{
|
||||
struct hwc_output *output;
|
||||
ssize_t crtc_index;
|
||||
size_t i;
|
||||
|
||||
crtc_index = -1;
|
||||
for (i = 0; i < display->crtcs_len; i++) {
|
||||
if (display->crtcs[i] == crtc_id) {
|
||||
crtc_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (crtc_index < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
output = calloc(1, sizeof(*output));
|
||||
if (output == NULL) {
|
||||
|
@ -13,6 +27,7 @@ struct hwc_output *hwc_output_create(struct hwc_display *display,
|
|||
}
|
||||
output->display = display;
|
||||
output->crtc_id = crtc_id;
|
||||
output->crtc_index = crtc_index;
|
||||
hwc_list_init(&output->layers);
|
||||
hwc_list_insert(&display->outputs, &output->link);
|
||||
return output;
|
||||
|
|
Loading…
Reference in a new issue