Skip to content

Commit

Permalink
Release gbm_bo used for bypass when framebuffer is released
Browse files Browse the repository at this point in the history
  • Loading branch information
tarek-y-ismail committed Oct 15, 2024
1 parent e91ec8c commit a423b51
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/platforms/atomic-kms/server/kms/display_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ auto import_gbm_bo(
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*
std::array<int, 4> offsets) -> std::shared_ptr<struct gbm_bo>
{
auto const plane_descriptors = buffer->planes();

Expand All @@ -383,15 +383,16 @@ auto import_gbm_bo(
.modifier = buffer->modifier().value_or(DRM_FORMAT_MOD_NONE),
};

return gbm_bo_import(gbm.get(), GBM_BO_IMPORT_FD_MODIFIER, (void*)&import_data, GBM_BO_USE_SCANOUT);
auto* gbm_bo = gbm_bo_import(gbm.get(), GBM_BO_IMPORT_FD_MODIFIER, (void*)&import_data, GBM_BO_USE_SCANOUT);
return std::shared_ptr<struct gbm_bo>(gbm_bo, &gbm_bo_destroy);
}

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(gbm, 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 All @@ -401,16 +402,16 @@ auto drm_fb_id_from_dma_buffer(
auto const plane_descriptors = buffer->planes();
uint32_t gem_handles[MAX_PLANES] = {0};
for (std::size_t i = 0; i < std::min(MAX_PLANES, plane_descriptors.size()); i++)
gem_handles[i] = gbm_bo_get_handle_for_plane(gbm_bo, i).u32;
gem_handles[i] = gbm_bo_get_handle_for_plane(gbm_bo.get(), i).u32;

// Note that we capture `gbm_bo` so that its lifetime matches that of the fb_id
auto fb_id = std::shared_ptr<uint32_t>{
new uint32_t{0},
[drm_fd](uint32_t* fb_id)
[drm_fd, gbm_bo](uint32_t* fb_id)
{
if (*fb_id)
{
drmModeRmFB(drm_fd, *fb_id);
}

delete fb_id;
}};

Expand Down

0 comments on commit a423b51

Please sign in to comment.