Skip to content

Commit

Permalink
(#3751) disconnected display outputs do not show up in DisplaySink::f…
Browse files Browse the repository at this point in the history
…or_each_display_sink
  • Loading branch information
mattkae committed Feb 11, 2025
1 parent 473cc62 commit efe1058
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/platforms/gbm-kms/server/kms/display_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ bool mgg::DisplaySink::overlay(std::vector<DisplayElement> const& renderable_lis

void mgg::DisplaySink::for_each_display_sink(std::function<void(graphics::DisplaySink&)> const& f)
{
// When an output is disconnected, its sink will have a size of 0x0.
// This may cause us to allocate a buffer of zero size, which leads
// to all sorts of problems (e.g. an error during eglSwapBuffers
// because the back buffer is empty). To avoid this, we don't iterate
// over display sinks that refer to disconnected outputs.
if (!outputs.front()->connected())
return;

f(*this);
}

Expand Down
3 changes: 3 additions & 0 deletions src/platforms/gbm-kms/server/kms/kms_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class KMSOutput
virtual void update_from_hardware_state(DisplayConfigurationOutput& to_update) const = 0;

virtual int drm_fd() const = 0;

/// Returns true if the connector is connected, otherwise false.
virtual bool connected() const = 0;
protected:
KMSOutput() = default;
KMSOutput(const KMSOutput&) = delete;
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/gbm-kms/server/kms/real_kms_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,9 @@ int mgg::RealKMSOutput::drm_fd() const
{
return drm_fd_;
}

bool mgg::RealKMSOutput::connected() const
{
return connector->connection == DRM_MODE_CONNECTED;
}

1 change: 1 addition & 0 deletions src/platforms/gbm-kms/server/kms/real_kms_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class RealKMSOutput : public KMSOutput
void update_from_hardware_state(DisplayConfigurationOutput& output) const override;

int drm_fd() const override;
bool connected() const override;

private:
bool ensure_crtc();
Expand Down
1 change: 1 addition & 0 deletions tests/unit-tests/platforms/gbm-kms/kms/mock_kms_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct MockKMSOutput : public graphics::gbm::KMSOutput
MOCK_CONST_METHOD1(fb_for, std::shared_ptr<graphics::FBHandle const>(graphics::DMABufBuffer const&));
MOCK_CONST_METHOD1(buffer_requires_migration, bool(gbm_bo*));
MOCK_CONST_METHOD0(drm_fd, int());
MOCK_CONST_METHOD0(connected, bool());
};

} // namespace test
Expand Down

0 comments on commit efe1058

Please sign in to comment.