diff --git a/driver/modeset.c b/driver/modeset.c index ec25382..ef57ad8 100644 --- a/driver/modeset.c +++ b/driver/modeset.c @@ -3,86 +3,6 @@ #include atomic_int saved_state_guard = 0; -void modeset_enum_planes(int fd, uint32_t* numPlanes, modeset_plane* planes) -{ - drmModePlaneResPtr planesPtr = drmModeGetPlaneResources(fd); - - uint32_t numDisplays; - modeset_display displays[16]; - modeset_enum_displays(controlFd, &numDisplays, displays); - - uint32_t tmpNumPlanes = 0; - modeset_plane tmpPlanes[32]; - - for(uint32_t c = 0; c < planesPtr->count_planes; ++c) - { - tmpPlanes[tmpNumPlanes].plane = drmModeGetPlane(fd, planesPtr->planes[c]); - tmpPlanes[tmpNumPlanes].currentConnectorID = 0; - - if(tmpPlanes[tmpNumPlanes].plane->crtc_id) - { - for(uint32_t d = 0; d < numDisplays; ++d) - { - drmModeConnectorPtr connPtr = drmModeGetConnector(fd, displays[d].connectorID); - - drmModeEncoderPtr encPtr = drmModeGetEncoder(fd, connPtr->encoder_id); - - uint32_t connID = connPtr->connector_id; - uint32_t crtcID = encPtr->crtc_id; - - drmModeFreeConnector(connPtr); - drmModeFreeEncoder(encPtr); - - if(crtcID == tmpPlanes[tmpNumPlanes].plane->crtc_id) - { - tmpPlanes[tmpNumPlanes].currentConnectorID = connID; - break; - } - } - } - - tmpPlanes[tmpNumPlanes].numPossibleConnectors = 0; - - for(uint32_t d = 0; d < numDisplays; ++d) - { - drmModeConnectorPtr connPtr = drmModeGetConnector(fd, displays[d].connectorID); - - for(uint32_t e = 0; e < connPtr->count_encoders; ++e) - { - drmModeEncoderPtr encPtr = drmModeGetEncoder(fd, connPtr->encoders[e]); - - uint32_t possibleCrtcs = encPtr->possible_crtcs; - - drmModeFreeEncoder(encPtr); - - if(possibleCrtcs & tmpPlanes[tmpNumPlanes].plane->possible_crtcs) - { - tmpPlanes[tmpNumPlanes].possibleConnectors[tmpPlanes[tmpNumPlanes].numPossibleConnectors] = connPtr->connector_id; - tmpPlanes[tmpNumPlanes].numPossibleConnectors++; - break; - } - } - - drmModeFreeConnector(connPtr); - } - - tmpNumPlanes++; - - assert(tmpNumPlanes < 32); - } - - drmModeFreePlaneResources(planesPtr); - - *numPlanes = tmpNumPlanes; - - memcpy(planes, tmpPlanes, tmpNumPlanes * sizeof(modeset_plane)); - - for(uint32_t c = 0; c < tmpNumPlanes; ++c) - { - memcpy(planes[c].possibleConnectors, tmpPlanes[c].possibleConnectors, tmpPlanes[c].numPossibleConnectors * sizeof(uint32_t)); - } -} - void modeset_enum_displays(int fd, uint32_t* numDisplays, modeset_display* displays) { drmModeResPtr resPtr = drmModeGetResources(fd); @@ -143,12 +63,34 @@ void modeset_enum_modes_for_display(int fd, uint32_t display, uint32_t* numModes for(uint32_t c = 0; c < connPtr->count_modes; ++c) { + uint32_t found = 0; + for(uint32_t d = 0; d < tmpNumModes; ++d) + { + if(tmpModes[d].refreshRate == connPtr->modes[c].vrefresh && + tmpModes[d].resWidth == connPtr->modes[c].hdisplay && + tmpModes[d].resHeight == connPtr->modes[c].vdisplay) + { + found = 1; + break; + } + } + + if(found) + { + //skip modes that have lower "clock" + //but otherwise same resolution and vrefresh + continue; + } + tmpModes[tmpNumModes].connectorID = display; tmpModes[tmpNumModes].modeID = c; tmpModes[tmpNumModes].refreshRate = connPtr->modes[c].vrefresh; tmpModes[tmpNumModes].resWidth = connPtr->modes[c].hdisplay; tmpModes[tmpNumModes].resHeight = connPtr->modes[c].vdisplay; + //explained here: + // https://01.org/linuxgraphics/gfx-docs/drm/API-struct-drm-display-mode.html + // char* typestr = 0; // switch(connPtr->modes[c].type) // { diff --git a/driver/modeset.h b/driver/modeset.h index b265e29..0f52a1e 100644 --- a/driver/modeset.h +++ b/driver/modeset.h @@ -56,7 +56,6 @@ typedef struct modeset_saved_state { modeset_saved_state modeset_saved_states[32]; -void modeset_enum_planes(int fd, uint32_t* numPlanes, modeset_plane* planes); void modeset_enum_displays(int fd, uint32_t* numDisplays, modeset_display* displays); void modeset_enum_modes_for_display(int fd, uint32_t display, uint32_t* numModes, modeset_display_mode* modes); void modeset_create_surface_for_mode(int fd, uint32_t display, uint32_t mode, modeset_display_surface* surface);