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:
Simon Ser 2019-09-08 17:41:25 +03:00
parent 66bedbc854
commit d90d7bdc36
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 42 additions and 0 deletions

View file

@ -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) {

View file

@ -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 */

View file

@ -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;