Skip to content

Commit

Permalink
Pass gbm_device directly instead of smuggling it through DisplaySink
Browse files Browse the repository at this point in the history
  • Loading branch information
tarek-y-ismail committed Sep 24, 2024
1 parent 5eb3558 commit 8031474
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion include/platform/mir/graphics/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
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
Expand Up @@ -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),
Expand Down Expand Up @@ -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 = {
Expand All @@ -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");
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}
Expand Down
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
Expand Up @@ -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
{
Expand All @@ -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 :
Expand Down
7 changes: 3 additions & 4 deletions src/platforms/gbm-kms/server/buffer_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8031474

Please sign in to comment.