Skip to content

Commit

Permalink
Setting the CRTC when there is a resolution mismatch on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Sep 7, 2023
1 parent d926d21 commit 44d563b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/platforms/gbm-kms/server/kms/display_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,29 @@ mgg::DisplayBuffer::DisplayBuffer(
{
listener->report_successful_setup_of_native_resources();

if (!smooth_transition)
bool needs_crtc_set = false;
for (auto& output : outputs)
{
try
{
geometry::Rectangle rectangle = output->get_rectangle();
if (rectangle != area)
{
needs_crtc_set = true;
break;
}
}
catch (std::invalid_argument&)
{
needs_crtc_set = true;
break;
}
}

if (smooth_transition && needs_crtc_set)
mir::log_warning("smooth_transition was requested but the CRTC requires setting");

if (needs_crtc_set)
{
// TODO: Pull a supported format out of KMS rather than assuming XRGB8888
auto initial_fb = std::make_shared<mgg::CPUAddressableFB>(
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/gbm-kms/server/kms/kms_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "mir/graphics/frame.h"
#include "mir/graphics/dmabuf_buffer.h"
#include "mir_toolkit/common.h"

#include "kms-utils/drm_mode_resources.h"

#include <gbm.h>
Expand Down Expand Up @@ -64,6 +63,7 @@ class KMSOutput
virtual int max_refresh_rate() const = 0;

virtual bool set_crtc(FBHandle const& fb) = 0;
virtual auto get_rectangle() -> mir::geometry::Rectangle = 0;
virtual void clear_crtc() = 0;
virtual bool schedule_page_flip(FBHandle const& fb) = 0;
virtual void wait_for_page_flip() = 0;
Expand Down
13 changes: 13 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 @@ -155,6 +155,19 @@ bool mgg::RealKMSOutput::set_crtc(FBHandle const& fb)
return true;
}

auto mgg::RealKMSOutput::get_rectangle() -> mir::geometry::Rectangle
{
if (!ensure_crtc())
{
mir::log_error("Output %s has no associated CRTC to get ", mgk::connector_name(connector).c_str());
BOOST_THROW_EXCEPTION(std::invalid_argument("get_crtc: Output has no associated CRTC to get"));
}

return mir::geometry::Rectangle(
mir::geometry::Point(current_crtc->x, current_crtc->y),
mir::geometry::Size(current_crtc->width, current_crtc->height));
}

void mgg::RealKMSOutput::clear_crtc()
{
try
Expand Down
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 @@ -49,6 +49,7 @@ class RealKMSOutput : public KMSOutput
int max_refresh_rate() const override;

bool set_crtc(FBHandle const& fb) override;
auto get_rectangle() -> mir::geometry::Rectangle override;
void clear_crtc() override;
bool schedule_page_flip(FBHandle const& fb) override;
void wait_for_page_flip() override;
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 @@ -39,6 +39,7 @@ struct MockKMSOutput : public graphics::gbm::KMSOutput
return set_crtc_thunk(&fb);
}

MOCK_METHOD0(get_rectangle, mir::geometry::Rectangle());
MOCK_METHOD1(set_crtc_thunk, bool(graphics::gbm::FBHandle const*));
MOCK_METHOD0(clear_crtc, void());

Expand Down

0 comments on commit 44d563b

Please sign in to comment.