aboutsummaryrefslogtreecommitdiff
path: root/kms/server/kms_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'kms/server/kms_server.c')
-rw-r--r--kms/server/kms_server.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/kms/server/kms_server.c b/kms/server/kms_server.c
index b4f3378..6d46f8a 100644
--- a/kms/server/kms_server.c
+++ b/kms/server/kms_server.c
@@ -19,12 +19,12 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_mode.h>
+#include <drm_fourcc.h>
#define MAX_CONNECTORS 32
typedef struct {
int drmfd;
- drmModePlaneResPtr planes;
} gsr_drm;
typedef struct {
@@ -288,21 +288,31 @@ static int drm_prime_handles_to_fds(gsr_drm *drm, drmModeFB2Ptr drmfb, int *fb_f
return GSR_KMS_MAX_DMA_BUFS;
}
-static int kms_get_fb(gsr_drm *drm, gsr_kms_response *response, connector_to_crtc_map *c2crtc_map) {
+static int kms_get_fb(gsr_drm *drm, gsr_kms_response *response) {
int result = -1;
response->result = KMS_RESULT_OK;
response->err_msg[0] = '\0';
response->num_items = 0;
- for(uint32_t i = 0; i < drm->planes->count_planes && response->num_items < GSR_KMS_MAX_ITEMS; ++i) {
+ connector_to_crtc_map c2crtc_map;
+ c2crtc_map.num_maps = 0;
+ map_crtc_to_connector_ids(drm, &c2crtc_map);
+
+ drmModePlaneResPtr planes = drmModeGetPlaneResources(drm->drmfd);
+ if(!planes) {
+ fprintf(stderr, "kms server error: failed to get plane resources, error: %s\n", strerror(errno));
+ goto done;
+ }
+
+ for(uint32_t i = 0; i < planes->count_planes && response->num_items < GSR_KMS_MAX_ITEMS; ++i) {
drmModePlanePtr plane = NULL;
drmModeFB2Ptr drmfb = NULL;
- plane = drmModeGetPlane(drm->drmfd, drm->planes->planes[i]);
+ plane = drmModeGetPlane(drm->drmfd, planes->planes[i]);
if(!plane) {
response->result = KMS_RESULT_FAILED_TO_GET_PLANE;
- snprintf(response->err_msg, sizeof(response->err_msg), "failed to get drm plane with id %u, error: %s\n", drm->planes->planes[i], strerror(errno));
+ snprintf(response->err_msg, sizeof(response->err_msg), "failed to get drm plane with id %u, error: %s\n", planes->planes[i], strerror(errno));
fprintf(stderr, "kms server error: %s\n", response->err_msg);
goto next;
}
@@ -345,7 +355,7 @@ static int kms_get_fb(gsr_drm *drm, gsr_kms_response *response, connector_to_crt
const int item_index = response->num_items;
- const connector_crtc_pair *crtc_pair = get_connector_pair_by_crtc_id(c2crtc_map, plane->crtc_id);
+ const connector_crtc_pair *crtc_pair = get_connector_pair_by_crtc_id(&c2crtc_map, plane->crtc_id);
if(crtc_pair && crtc_pair->hdr_metadata_blob_id) {
response->items[item_index].has_hdr_metadata = get_hdr_metadata(drm->drmfd, crtc_pair->hdr_metadata_blob_id, &response->items[item_index].hdr_metadata);
} else {
@@ -362,7 +372,7 @@ static int kms_get_fb(gsr_drm *drm, gsr_kms_response *response, connector_to_crt
response->items[item_index].width = drmfb->width;
response->items[item_index].height = drmfb->height;
response->items[item_index].pixel_format = drmfb->pixel_format;
- response->items[item_index].modifier = drmfb->modifier;
+ response->items[item_index].modifier = drmfb->flags & DRM_MODE_FB_MODIFIERS ? drmfb->modifier : DRM_FORMAT_MOD_INVALID;
response->items[item_index].connector_id = crtc_pair ? crtc_pair->connector_id : 0;
response->items[item_index].is_cursor = property_mask & PLANE_PROPERTY_IS_CURSOR;
if(property_mask & PLANE_PROPERTY_IS_CURSOR) {
@@ -388,6 +398,11 @@ static int kms_get_fb(gsr_drm *drm, gsr_kms_response *response, connector_to_crt
drmModeFreePlane(plane);
}
+ done:
+
+ if(planes)
+ drmModeFreePlaneResources(planes);
+
if(response->num_items > 0)
response->result = KMS_RESULT_OK;
@@ -498,7 +513,6 @@ int main(int argc, char **argv) {
int socket_fd = 0;
gsr_drm drm;
drm.drmfd = 0;
- drm.planes = NULL;
if(argc != 3) {
fprintf(stderr, "usage: gsr-kms-server <domain_socket_path> <card_path>\n");
@@ -531,17 +545,6 @@ int main(int argc, char **argv) {
fprintf(stderr, "kms server warning: drmSetClientCap DRM_CLIENT_CAP_ATOMIC failed, error: %s. The wrong monitor may be captured as a result\n", strerror(errno));
}
- drm.planes = drmModeGetPlaneResources(drm.drmfd);
- if(!drm.planes) {
- fprintf(stderr, "kms server error: failed to get plane resources, error: %s\n", strerror(errno));
- res = 2;
- goto done;
- }
-
- connector_to_crtc_map c2crtc_map;
- c2crtc_map.num_maps = 0;
- map_crtc_to_connector_ids(&drm, &c2crtc_map);
-
fprintf(stderr, "kms server info: connecting to the client\n");
bool connected = false;
const double connect_timeout_sec = 5.0;
@@ -641,7 +644,7 @@ int main(int argc, char **argv) {
response.version = GSR_KMS_PROTOCOL_VERSION;
response.num_items = 0;
- if(kms_get_fb(&drm, &response, &c2crtc_map) == 0) {
+ if(kms_get_fb(&drm, &response) == 0) {
if(send_msg_to_client(socket_fd, &response) == -1)
fprintf(stderr, "kms server error: failed to respond to client KMS_REQUEST_TYPE_GET_KMS request\n");
} else {
@@ -680,8 +683,6 @@ int main(int argc, char **argv) {
}
done:
- if(drm.planes)
- drmModeFreePlaneResources(drm.planes);
if(drm.drmfd > 0)
close(drm.drmfd);
if(socket_fd > 0)