core: Introduce GraphicsBufferOptions
GraphicsBufferOptions describes the properties of the allocated graphics buffer.
This commit is contained in:
parent
bdc14f247e
commit
1833d790f5
11 changed files with 62 additions and 27 deletions
|
@ -71,7 +71,10 @@ std::shared_ptr<VirtualEglLayerBuffer> VirtualEglSwapchain::acquire()
|
|||
}
|
||||
}
|
||||
|
||||
GbmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(m_size, m_format);
|
||||
GbmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(GraphicsBufferOptions{
|
||||
.size = m_size,
|
||||
.format = m_format,
|
||||
});
|
||||
if (!graphicsBuffer) {
|
||||
qCWarning(KWIN_VIRTUAL) << "Failed to allocate layer swapchain buffer";
|
||||
return nullptr;
|
||||
|
|
|
@ -77,7 +77,10 @@ std::shared_ptr<VirtualQPainterBufferSlot> VirtualQPainterSwapchain::acquire()
|
|||
}
|
||||
}
|
||||
|
||||
ShmGraphicsBuffer *buffer = m_allocator->allocate(m_size, m_format);
|
||||
ShmGraphicsBuffer *buffer = m_allocator->allocate(GraphicsBufferOptions{
|
||||
.size = m_size,
|
||||
.format = m_format,
|
||||
});
|
||||
if (!buffer) {
|
||||
qCDebug(KWIN_VIRTUAL) << "Did not get a new Buffer from Shm Pool";
|
||||
return nullptr;
|
||||
|
|
|
@ -90,7 +90,11 @@ std::shared_ptr<WaylandEglLayerBuffer> WaylandEglLayerSwapchain::acquire()
|
|||
}
|
||||
}
|
||||
|
||||
GbmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(m_size, m_format, m_modifiers);
|
||||
GbmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(GraphicsBufferOptions{
|
||||
.size = m_size,
|
||||
.format = m_format,
|
||||
.modifiers = m_modifiers,
|
||||
});
|
||||
if (!graphicsBuffer) {
|
||||
qCWarning(KWIN_WAYLAND_BACKEND) << "Failed to allocate layer swapchain buffer";
|
||||
return nullptr;
|
||||
|
|
|
@ -81,7 +81,10 @@ std::shared_ptr<WaylandQPainterBufferSlot> WaylandQPainterSwapchain::acquire()
|
|||
}
|
||||
}
|
||||
|
||||
ShmGraphicsBuffer *buffer = m_allocator->allocate(m_size, m_format);
|
||||
ShmGraphicsBuffer *buffer = m_allocator->allocate(GraphicsBufferOptions{
|
||||
.size = m_size,
|
||||
.format = m_format,
|
||||
});
|
||||
if (!buffer) {
|
||||
qCDebug(KWIN_WAYLAND_BACKEND) << "Did not get a new Buffer from Shm Pool";
|
||||
return nullptr;
|
||||
|
|
|
@ -79,7 +79,11 @@ std::shared_ptr<X11WindowedEglLayerBuffer> X11WindowedEglLayerSwapchain::acquire
|
|||
}
|
||||
}
|
||||
|
||||
GbmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(m_size, m_format, m_modifiers);
|
||||
GbmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(GraphicsBufferOptions{
|
||||
.size = m_size,
|
||||
.format = m_format,
|
||||
.modifiers = m_modifiers,
|
||||
});
|
||||
if (!graphicsBuffer) {
|
||||
qCWarning(KWIN_X11WINDOWED) << "Failed to allocate layer swapchain buffer";
|
||||
return nullptr;
|
||||
|
|
|
@ -88,7 +88,10 @@ std::shared_ptr<X11WindowedQPainterLayerBuffer> X11WindowedQPainterLayerSwapchai
|
|||
}
|
||||
}
|
||||
|
||||
ShmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(m_size, m_format);
|
||||
ShmGraphicsBuffer *graphicsBuffer = m_allocator->allocate(GraphicsBufferOptions{
|
||||
.size = m_size,
|
||||
.format = m_format,
|
||||
});
|
||||
if (!graphicsBuffer) {
|
||||
qCWarning(KWIN_X11WINDOWED) << "Failed to allocate a shared memory graphics buffer";
|
||||
return nullptr;
|
||||
|
|
|
@ -22,15 +22,15 @@ GbmGraphicsBufferAllocator::~GbmGraphicsBufferAllocator()
|
|||
{
|
||||
}
|
||||
|
||||
GbmGraphicsBuffer *GbmGraphicsBufferAllocator::allocate(const QSize &size, uint32_t format, const QVector<uint64_t> &modifiers)
|
||||
GbmGraphicsBuffer *GbmGraphicsBufferAllocator::allocate(const GraphicsBufferOptions &options)
|
||||
{
|
||||
if (!modifiers.isEmpty() && !(modifiers.size() == 1 && modifiers.first() == DRM_FORMAT_MOD_INVALID)) {
|
||||
if (!options.modifiers.isEmpty() && !(options.modifiers.size() == 1 && options.modifiers.first() == DRM_FORMAT_MOD_INVALID)) {
|
||||
gbm_bo *bo = gbm_bo_create_with_modifiers(m_gbmDevice,
|
||||
size.width(),
|
||||
size.height(),
|
||||
format,
|
||||
modifiers.constData(),
|
||||
modifiers.size());
|
||||
options.size.width(),
|
||||
options.size.height(),
|
||||
options.format,
|
||||
options.modifiers.constData(),
|
||||
options.modifiers.size());
|
||||
if (bo) {
|
||||
std::optional<DmaBufAttributes> attributes = dmaBufAttributesForBo(bo);
|
||||
if (!attributes.has_value()) {
|
||||
|
@ -42,16 +42,16 @@ GbmGraphicsBuffer *GbmGraphicsBufferAllocator::allocate(const QSize &size, uint3
|
|||
}
|
||||
|
||||
uint32_t flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
|
||||
if (modifiers.size() == 1 && modifiers.first() == DRM_FORMAT_MOD_LINEAR) {
|
||||
if (options.modifiers.size() == 1 && options.modifiers.first() == DRM_FORMAT_MOD_LINEAR) {
|
||||
flags |= GBM_BO_USE_LINEAR;
|
||||
} else if (!modifiers.contains(DRM_FORMAT_MOD_INVALID)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
gbm_bo *bo = gbm_bo_create(m_gbmDevice,
|
||||
size.width(),
|
||||
size.height(),
|
||||
format,
|
||||
options.size.width(),
|
||||
options.size.height(),
|
||||
options.format,
|
||||
flags);
|
||||
if (bo) {
|
||||
std::optional<DmaBufAttributes> attributes = dmaBufAttributesForBo(bo);
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
explicit GbmGraphicsBufferAllocator(gbm_device *device);
|
||||
~GbmGraphicsBufferAllocator() override;
|
||||
|
||||
GbmGraphicsBuffer *allocate(const QSize &size, uint32_t format, const QVector<uint64_t> &modifiers = {}) override;
|
||||
GbmGraphicsBuffer *allocate(const GraphicsBufferOptions &options) override;
|
||||
|
||||
private:
|
||||
gbm_device *m_gbmDevice;
|
||||
|
|
|
@ -16,13 +16,28 @@ namespace KWin
|
|||
|
||||
class GraphicsBuffer;
|
||||
|
||||
/**
|
||||
* The GraphicsBufferOptions describes the properties of an allocated graphics buffer.
|
||||
*/
|
||||
struct GraphicsBufferOptions
|
||||
{
|
||||
/// The size of the buffer, in device pixels.
|
||||
QSize size;
|
||||
|
||||
/// The pixel format of the buffer, see DRM_FORMAT_*.
|
||||
uint32_t format;
|
||||
|
||||
/// An optional list of modifiers, see DRM_FORMAT_MOD_*.
|
||||
QVector<uint64_t> modifiers;
|
||||
};
|
||||
|
||||
class KWIN_EXPORT GraphicsBufferAllocator
|
||||
{
|
||||
public:
|
||||
GraphicsBufferAllocator();
|
||||
virtual ~GraphicsBufferAllocator();
|
||||
|
||||
virtual GraphicsBuffer *allocate(const QSize &size, uint32_t format, const QVector<uint64_t> &modifiers = {}) = 0;
|
||||
virtual GraphicsBuffer *allocate(const GraphicsBufferOptions &options) = 0;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -36,13 +36,13 @@ const ShmAttributes *ShmGraphicsBuffer::shmAttributes() const
|
|||
return &m_attributes;
|
||||
}
|
||||
|
||||
ShmGraphicsBuffer *ShmGraphicsBufferAllocator::allocate(const QSize &size, uint32_t format, const QVector<uint64_t> &modifiers)
|
||||
ShmGraphicsBuffer *ShmGraphicsBufferAllocator::allocate(const GraphicsBufferOptions &options)
|
||||
{
|
||||
if (!modifiers.isEmpty()) {
|
||||
if (!options.modifiers.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
switch (options.format) {
|
||||
case DRM_FORMAT_ARGB8888:
|
||||
case DRM_FORMAT_XRGB8888:
|
||||
break;
|
||||
|
@ -50,8 +50,8 @@ ShmGraphicsBuffer *ShmGraphicsBufferAllocator::allocate(const QSize &size, uint3
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const int stride = size.width() * 4;
|
||||
const int bufferSize = size.height() * stride;
|
||||
const int stride = options.size.width() * 4;
|
||||
const int bufferSize = options.size.height() * stride;
|
||||
|
||||
#if HAVE_MEMFD
|
||||
FileDescriptor fd = FileDescriptor(memfd_create("shm", MFD_CLOEXEC | MFD_ALLOW_SEALING));
|
||||
|
@ -86,8 +86,8 @@ ShmGraphicsBuffer *ShmGraphicsBufferAllocator::allocate(const QSize &size, uint3
|
|||
.fd = std::move(fd),
|
||||
.stride = stride,
|
||||
.offset = 0,
|
||||
.size = size,
|
||||
.format = format,
|
||||
.size = options.size,
|
||||
.format = options.format,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ private:
|
|||
class KWIN_EXPORT ShmGraphicsBufferAllocator : public GraphicsBufferAllocator
|
||||
{
|
||||
public:
|
||||
ShmGraphicsBuffer *allocate(const QSize &size, uint32_t format, const QVector<uint64_t> &modifiers = {}) override;
|
||||
ShmGraphicsBuffer *allocate(const GraphicsBufferOptions &options) override;
|
||||
};
|
||||
|
||||
} // namespace KWin
|
||||
|
|
Loading…
Reference in a new issue