Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic KMS: enable bypass #3595

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass gbm_device directly instead of smuggling it through DisplaySink
  • Loading branch information
tarek-y-ismail committed Oct 17, 2024

Verified

This commit was signed with the committer’s verified signature.
m4tx Mateusz Maćkowski
commit ff8bf02eea9043f7da2ace77ba0b1e59b4d7e8f4
2 changes: 1 addition & 1 deletion include/platform/mir/graphics/platform.h
Original file line number Diff line number Diff line change
@@ -396,7 +396,7 @@ class DmaBufDisplayAllocator : public DisplayAllocator
{
};

virtual auto framebuffer_for(mir::graphics::DisplaySink& sink, std::shared_ptr<DMABufBuffer> buffer)
virtual auto framebuffer_for(std::shared_ptr<DMABufBuffer> buffer)
-> std::unique_ptr<Framebuffer> = 0;
};

21 changes: 8 additions & 13 deletions src/platforms/atomic-kms/server/kms/display_buffer.cpp
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ mga::DisplaySink::DisplaySink(
std::vector<std::shared_ptr<KMSOutput>> const& outputs,
geom::Rectangle const& area,
glm::mat2 const& transformation)
: DmaBufDisplayAllocator(drm_fd),
: DmaBufDisplayAllocator(gbm, drm_fd),
gbm{std::move(gbm)},
listener(listener),
outputs(outputs),
@@ -371,16 +371,12 @@ namespace {
}

auto import_gbm_bo(
mg::DisplaySink const& sink,
std::shared_ptr<struct gbm_device> gbm,
std::shared_ptr<mg::DMABufBuffer> buffer,
std::array<int, 4> dmabuf_fds,
std::array<int, 4> pitches,
std::array<int, 4> offsets) -> struct gbm_bo*
{
auto* ds = dynamic_cast<mga::DisplaySink const *>(&sink);
if (!ds)
return nullptr;

auto const plane_descriptors = buffer->planes();

gbm_import_fd_modifier_data import_data = {
@@ -394,16 +390,15 @@ namespace {
.modifier = buffer->modifier().value_or(DRM_FORMAT_MOD_NONE),
};

return gbm_bo_import(
ds->gbm_device().get(), GBM_BO_IMPORT_FD_MODIFIER, (void*)&import_data, GBM_BO_USE_SCANOUT);
return gbm_bo_import(gbm.get(), GBM_BO_IMPORT_FD_MODIFIER, (void*)&import_data, GBM_BO_USE_SCANOUT);
}

auto drm_fb_id_from_dma_buffer(mir::Fd drm_fd, mg::DisplaySink const& sink, std::shared_ptr<mg::DMABufBuffer> buffer)
auto drm_fb_id_from_dma_buffer(mir::Fd drm_fd, std::shared_ptr<struct gbm_device> const gbm, std::shared_ptr<mg::DMABufBuffer> buffer)
-> std::shared_ptr<uint32_t>
{

auto [dmabuf_fds, pitches, offsets, modifiers] = get_import_buffers(buffer);
auto* gbm_bo = import_gbm_bo(sink, buffer, dmabuf_fds, pitches, offsets);
auto* gbm_bo = import_gbm_bo(gbm, buffer, dmabuf_fds, pitches, offsets);
if (!gbm_bo)
{
mir::log_warning("Failed to import buffer");
@@ -449,9 +444,9 @@ namespace {
}
}

auto mga::DmaBufDisplayAllocator::framebuffer_for(mg::DisplaySink& sink, std::shared_ptr<DMABufBuffer> buffer) -> std::unique_ptr<Framebuffer>
auto mga::DmaBufDisplayAllocator::framebuffer_for(std::shared_ptr<DMABufBuffer> buffer) -> std::unique_ptr<Framebuffer>
{
auto fb_id = drm_fb_id_from_dma_buffer(drm_fd(), sink, buffer);
auto fb_id = drm_fb_id_from_dma_buffer(drm_fd(), gbm, buffer);

struct AtomicKmsFbHandle : public mg::FBHandle
{
@@ -502,7 +497,7 @@ auto mga::DisplaySink::maybe_create_allocator(DisplayAllocator::Tag const& type_
{
if (!bypass_allocator)
{
bypass_allocator = std::make_shared<DmaBufDisplayAllocator>(drm_fd());
bypass_allocator = std::make_shared<DmaBufDisplayAllocator>(gbm, drm_fd());
}
return bypass_allocator.get();
}
7 changes: 5 additions & 2 deletions src/platforms/atomic-kms/server/kms/display_sink.h
Original file line number Diff line number Diff line change
@@ -54,11 +54,13 @@ class KMSOutput;
class DmaBufDisplayAllocator : public graphics::DmaBufDisplayAllocator
{
public:
DmaBufDisplayAllocator(mir::Fd drm_fd) : drm_fd_{drm_fd}
DmaBufDisplayAllocator(std::shared_ptr<struct gbm_device> const gbm, mir::Fd drm_fd) :
drm_fd_{drm_fd},
gbm{gbm}
{
}

virtual auto framebuffer_for(mir::graphics::DisplaySink& sink, std::shared_ptr<DMABufBuffer> buffer) -> std::unique_ptr<Framebuffer> override;
virtual auto framebuffer_for(std::shared_ptr<DMABufBuffer> buffer) -> std::unique_ptr<Framebuffer> override;

auto drm_fd() -> mir::Fd const
{
@@ -67,6 +69,7 @@ class DmaBufDisplayAllocator : public graphics::DmaBufDisplayAllocator

private:
mir::Fd const drm_fd_;
std::shared_ptr<struct gbm_device> const gbm;
};

class DisplaySink :
7 changes: 3 additions & 4 deletions src/platforms/gbm-kms/server/buffer_allocator.cpp
Original file line number Diff line number Diff line change
@@ -561,26 +561,25 @@ auto mgg::GLRenderingProvider::make_framebuffer_provider(DisplaySink& sink)
struct FooFramebufferProvider: public FramebufferProvider
{
public:
FooFramebufferProvider(DmaBufDisplayAllocator* allocator, mg::DisplaySink& sink) : allocator{allocator}, sink{sink}
FooFramebufferProvider(DmaBufDisplayAllocator* allocator) : allocator{allocator}
{
}

auto buffer_to_framebuffer(std::shared_ptr<Buffer> buffer) -> std::unique_ptr<Framebuffer> override
{
if(auto dma_buf = std::dynamic_pointer_cast<mir::graphics::DMABufBuffer>(buffer))
{
return allocator->framebuffer_for(sink, dma_buf);
return allocator->framebuffer_for(dma_buf);
}

return {};
}

private:
DmaBufDisplayAllocator* allocator;
mg::DisplaySink& sink;
};

return std::make_unique<FooFramebufferProvider>(allocator, sink);
return std::make_unique<FooFramebufferProvider>(allocator);
}

// TODO: Make this not a null implementation, so bypass/overlays can work again