Skip to content

Commit

Permalink
[WPE] Fix DRM initialization in nxp-imx6qp-sdb board
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268487

Reviewed by Carlos Garcia Campos.

This patch is generic but fixes the DRM initialization for NXP imx6qp
Sabre Development boards:

* Removes the check for the valid connector in the chooseConnector().
  The encoder Id can be zero if the connector is not currently bound
  to an encoder or if the encoder+crtc is already used by another
  connector.

* Modifies the chooseCrtcForConnector() logic. We implement a more
  robust mechanism by checking the encoder->possible_crtcs in case of
  no active crtc was found.

Credits to Jani Hautakangas <jani@igalia.com>.

Related-To: Igalia/cog#590
Related-To: #23654
Related-To: #23657

* Source/WebKit/WPEPlatform/wpe/drm/WPEDisplayDRM.cpp:
(chooseConnector):
(chooseCrtcForConnector):

Canonical link: https://commits.webkit.org/273898@main
  • Loading branch information
psaavedra committed Feb 1, 2024
1 parent 52bbfea commit 5a6315f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Source/WebKit/WPEPlatform/wpe/drm/WPEDisplayDRM.cpp
Expand Up @@ -138,7 +138,7 @@ static std::unique_ptr<WPE::DRM::Connector> chooseConnector(int fd, drmModeRes*
{
for (int i = 0; i < resources->count_connectors; ++i) {
WPE::DRM::UniquePtr<drmModeConnector> connector(drmModeGetConnector(fd, resources->connectors[i]));
if (!connector || connector->connection != DRM_MODE_CONNECTED || connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK || !connector->encoder_id)
if (!connector || connector->connection != DRM_MODE_CONNECTED || connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
continue;

if (auto conn = WPE::DRM::Connector::create(fd, connector.get()))
Expand All @@ -151,16 +151,29 @@ static std::unique_ptr<WPE::DRM::Connector> chooseConnector(int fd, drmModeRes*

static std::unique_ptr<WPE::DRM::Crtc> chooseCrtcForConnector(int fd, drmModeRes* resources, const WPE::DRM::Connector& connector, GError** error)
{
// Try the currently connected encoder+crtc.
WPE::DRM::UniquePtr<drmModeEncoder> encoder(drmModeGetEncoder(fd, connector.encoderID()));
if (!encoder) {
g_set_error_literal(error, WPE_DISPLAY_ERROR, WPE_DISPLAY_ERROR_CONNECTION_FAILED, "Failed to get the connector encoder");
return nullptr;
if (encoder) {
for (int i = 0; i < resources->count_crtcs; ++i) {
if (resources->crtcs[i] == encoder->crtc_id) {
WPE::DRM::UniquePtr<drmModeCrtc> drmCrtc(drmModeGetCrtc(fd, resources->crtcs[i]));
return WPE::DRM::Crtc::create(fd, drmCrtc.get(), i);
}
}
}

for (int i = 0; i < resources->count_crtcs; ++i) {
if (resources->crtcs[i] == encoder->crtc_id) {
WPE::DRM::UniquePtr<drmModeCrtc> drmCrtc(drmModeGetCrtc(fd, resources->crtcs[i]));
return WPE::DRM::Crtc::create(fd, drmCrtc.get(), i);
// If no active crtc was found, pick the first possible crtc, then try the first possible for crtc.
for (int i = 0; i < resources->count_encoders; ++i) {
WPE::DRM::UniquePtr<drmModeEncoder> encoder(drmModeGetEncoder(fd, resources->encoders[i]));
if (!encoder)
continue;

for (int j = 0; j < resources->count_crtcs; ++j) {
const uint32_t crtcMask = 1 << j;
if (encoder->possible_crtcs & crtcMask) {
WPE::DRM::UniquePtr<drmModeCrtc> drmCrtc(drmModeGetCrtc(fd, resources->crtcs[j]));
return WPE::DRM::Crtc::create(fd, drmCrtc.get(), j);
}
}
}

Expand Down

0 comments on commit 5a6315f

Please sign in to comment.