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

please-no-naked-new #3644

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
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
16 changes: 9 additions & 7 deletions src/platforms/gbm-kms/server/gbm_display_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class GBMBoFramebuffer : public mg::FBHandle
{
if (auto cached_fb = static_cast<std::shared_ptr<uint32_t const>*>(gbm_bo_get_user_data(bo.get())))
{
return std::unique_ptr<GBMBoFramebuffer>{new GBMBoFramebuffer{std::move(bo), *cached_fb}};
return std::make_unique<GBMBoFramebuffer>(std::move(bo), *cached_fb);
}

auto fb_id = new std::shared_ptr<uint32_t>{
auto fb_id = std::shared_ptr<uint32_t>{
new uint32_t{0},
[drm_fd](uint32_t* fb_id)
{
Expand All @@ -79,13 +79,15 @@ class GBMBoFramebuffer : public mg::FBHandle

/* Create a KMS FB object with the gbm_bo attached to it. */
auto ret = drmModeAddFB2(drm_fd, width, height, format,
handles, strides, offsets, fb_id->get(), 0);
handles, strides, offsets, fb_id.get(), 0);
if (ret)
return nullptr;

gbm_bo_set_user_data(bo.get(), fb_id, [](gbm_bo*, void* fb_ptr) { delete static_cast<std::shared_ptr<uint32_t const>*>(fb_ptr); });
// It is weird allocating a smart pointer on the heap, but we delete it
// via gbm_bo_set_user_data()'s destroy_user_data parameter.
gbm_bo_set_user_data(bo.get(), new std::shared_ptr<uint32_t>(fb_id), [](gbm_bo*, void* fb_ptr) { delete static_cast<std::shared_ptr<uint32_t const>*>(fb_ptr); });

return std::unique_ptr<GBMBoFramebuffer>{new GBMBoFramebuffer{std::move(bo), *fb_id}};
return std::make_unique<GBMBoFramebuffer>(std::move(bo), std::move(fb_id));
}

operator uint32_t() const override
Expand All @@ -100,13 +102,13 @@ class GBMBoFramebuffer : public mg::FBHandle
gbm_bo_get_width(bo.get()),
gbm_bo_get_height(bo.get())};
}
private:

GBMBoFramebuffer(LockedFrontBuffer bo, std::shared_ptr<uint32_t const> fb)
: bo{std::move(bo)},
fb_id{std::move(fb)}
{
}

private:
LockedFrontBuffer const bo;
std::shared_ptr<uint32_t const> const fb_id;
};
Expand Down
Loading