core: Allow mapping shared memory graphics buffer
Shared memory graphics buffers can be mapped, so implement GraphicsBuffer::map() and GraphicsBuffer::unmap().
This commit is contained in:
parent
d8029e461e
commit
80a3fea9f8
2 changed files with 32 additions and 1 deletions
|
@ -21,6 +21,33 @@ ShmGraphicsBuffer::ShmGraphicsBuffer(ShmAttributes &&attributes)
|
|||
{
|
||||
}
|
||||
|
||||
void *ShmGraphicsBuffer::map(MapFlags flags)
|
||||
{
|
||||
if (m_memoryMap.isValid()) {
|
||||
return m_memoryMap.data();
|
||||
}
|
||||
|
||||
int prot = 0;
|
||||
if (flags & MapFlag::Read) {
|
||||
prot |= PROT_READ;
|
||||
}
|
||||
if (flags & MapFlag::Write) {
|
||||
prot |= PROT_WRITE;
|
||||
}
|
||||
|
||||
m_memoryMap = MemoryMap(m_attributes.stride * m_attributes.size.height(), prot, MAP_SHARED, m_attributes.fd.get(), m_attributes.offset);
|
||||
if (m_memoryMap.isValid()) {
|
||||
return m_memoryMap.data();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ShmGraphicsBuffer::unmap()
|
||||
{
|
||||
m_memoryMap = MemoryMap{};
|
||||
}
|
||||
|
||||
QSize ShmGraphicsBuffer::size() const
|
||||
{
|
||||
return m_attributes.size;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "core/graphicsbuffer.h"
|
||||
#include "core/graphicsbufferallocator.h"
|
||||
#include "utils/filedescriptor.h"
|
||||
#include "utils/memorymap.h"
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
@ -20,12 +20,16 @@ class KWIN_EXPORT ShmGraphicsBuffer : public GraphicsBuffer
|
|||
public:
|
||||
explicit ShmGraphicsBuffer(ShmAttributes &&attributes);
|
||||
|
||||
void *map(MapFlags flags) override;
|
||||
void unmap() override;
|
||||
|
||||
QSize size() const override;
|
||||
bool hasAlphaChannel() const override;
|
||||
const ShmAttributes *shmAttributes() const override;
|
||||
|
||||
private:
|
||||
ShmAttributes m_attributes;
|
||||
MemoryMap m_memoryMap;
|
||||
bool m_hasAlphaChannel;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue