plugins/screencast: Handle failing to import dmabuf

This commit is contained in:
Vlad Zahorodnii 2024-03-27 15:25:13 +02:00
parent 9e9da67fc0
commit 5c2314a6bd
3 changed files with 18 additions and 5 deletions

View file

@ -11,9 +11,9 @@
namespace KWin
{
ScreenCastDmaBufTexture::ScreenCastDmaBufTexture(std::shared_ptr<GLTexture> texture, GraphicsBuffer *buffer)
: m_texture(texture)
, m_framebuffer(std::make_unique<GLFramebuffer>(texture.get()))
ScreenCastDmaBufTexture::ScreenCastDmaBufTexture(std::shared_ptr<GLTexture> texture, std::unique_ptr<GLFramebuffer> &&framebuffer, GraphicsBuffer *buffer)
: m_texture(std::move(texture))
, m_framebuffer(std::move(framebuffer))
, m_buffer(buffer)
{
}

View file

@ -17,7 +17,7 @@ class GraphicsBuffer;
class ScreenCastDmaBufTexture
{
public:
explicit ScreenCastDmaBufTexture(std::shared_ptr<GLTexture> texture, GraphicsBuffer *buffer);
explicit ScreenCastDmaBufTexture(std::shared_ptr<GLTexture> texture, std::unique_ptr<GLFramebuffer> &&framebuffer, GraphicsBuffer *buffer);
virtual ~ScreenCastDmaBufTexture();
GraphicsBuffer *buffer() const;

View file

@ -929,7 +929,20 @@ std::shared_ptr<ScreenCastDmaBufTexture> ScreenCastStream::createDmaBufTexture(c
}
backend->makeCurrent();
return std::make_shared<ScreenCastDmaBufTexture>(backend->importDmaBufAsTexture(*attrs), buffer);
std::shared_ptr<GLTexture> texture = backend->importDmaBufAsTexture(*attrs);
if (!texture) {
buffer->drop();
return nullptr;
}
std::unique_ptr<GLFramebuffer> framebuffer = std::make_unique<GLFramebuffer>(texture.get());
if (!framebuffer->valid()) {
buffer->drop();
return nullptr;
}
return std::make_shared<ScreenCastDmaBufTexture>(std::move(texture), std::move(framebuffer), buffer);
}
} // namespace KWin