core: Add GraphicsBuffer map flags

This allows to specify whether the graphics buffer will be read or
written. It's mainly needed to map our APIs to gbm APIs.
remotes/origin/work/zamundaaa/fix-nvidia-primary-gpu
Vlad Zahorodnii 3 years ago
parent 9bbe0cc4ac
commit ea639ad170
  1. 12
      src/core/gbmgraphicsbufferallocator.cpp
  2. 6
      src/core/gbmgraphicsbufferallocator.h
  3. 2
      src/core/graphicsbuffer.cpp
  4. 10
      src/core/graphicsbuffer.h
  5. 4
      src/core/graphicsbufferview.cpp
  6. 6
      src/core/graphicsbufferview.h
  7. 2
      src/wayland/shmclientbuffer.cpp
  8. 2
      src/wayland/shmclientbuffer_p.h

@ -117,14 +117,22 @@ const DmaBufAttributes *GbmGraphicsBuffer::dmabufAttributes() const
return &m_dmabufAttributes;
}
void *GbmGraphicsBuffer::map()
void *GbmGraphicsBuffer::map(MapFlags flags)
{
if (m_mapPtr) {
return m_mapPtr;
}
uint32_t access = 0;
if (flags & MapFlag::Read) {
access |= GBM_BO_TRANSFER_READ;
}
if (flags & MapFlag::Write) {
access |= GBM_BO_TRANSFER_WRITE;
}
uint32_t stride = 0;
m_mapPtr = gbm_bo_map(m_bo, 0, 0, m_dmabufAttributes.width, m_dmabufAttributes.height, GBM_BO_TRANSFER_READ_WRITE, &stride, &m_mapData);
m_mapPtr = gbm_bo_map(m_bo, 0, 0, m_dmabufAttributes.width, m_dmabufAttributes.height, access, &stride, &m_mapData);
return m_mapPtr;
}

@ -23,13 +23,13 @@ public:
GbmGraphicsBuffer(DmaBufAttributes attributes, gbm_bo *handle);
~GbmGraphicsBuffer() override;
void *map(MapFlags flags) override;
void unmap() override;
QSize size() const override;
bool hasAlphaChannel() const override;
const DmaBufAttributes *dmabufAttributes() const override;
void *map() override;
void unmap() override;
private:
gbm_bo *m_bo;
void *m_mapPtr = nullptr;

@ -53,7 +53,7 @@ void GraphicsBuffer::drop()
}
}
void *GraphicsBuffer::map()
void *GraphicsBuffer::map(MapFlags flags)
{
return nullptr;
}

@ -58,7 +58,13 @@ public:
void unref();
void drop();
virtual void *map();
enum MapFlag {
Read = 0x1,
Write = 0x2,
};
Q_DECLARE_FLAGS(MapFlags, MapFlag)
virtual void *map(MapFlags flags);
virtual void unmap();
virtual QSize size() const = 0;
@ -78,3 +84,5 @@ protected:
};
} // namespace KWin
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::GraphicsBuffer::MapFlags)

@ -39,7 +39,7 @@ static QImage::Format drmFormatToQImageFormat(uint32_t drmFormat)
}
}
GraphicsBufferView::GraphicsBufferView(GraphicsBuffer *buffer)
GraphicsBufferView::GraphicsBufferView(GraphicsBuffer *buffer, GraphicsBuffer::MapFlags accessFlags)
: m_buffer(buffer)
{
int width;
@ -65,7 +65,7 @@ GraphicsBufferView::GraphicsBufferView(GraphicsBuffer *buffer)
return;
}
void *data = buffer->map();
void *data = buffer->map(accessFlags);
if (data) {
m_image = QImage(static_cast<uchar *>(data), width, height, stride, drmFormatToQImageFormat(format));
}

@ -6,19 +6,17 @@
#pragma once
#include "kwin_export.h"
#include "core/graphicsbuffer.h"
#include <QImage>
namespace KWin
{
class GraphicsBuffer;
class KWIN_EXPORT GraphicsBufferView
{
public:
explicit GraphicsBufferView(GraphicsBuffer *buffer);
explicit GraphicsBufferView(GraphicsBuffer *buffer, GraphicsBuffer::MapFlags accessFlags = GraphicsBuffer::Read);
~GraphicsBufferView();
QImage *image();

@ -233,7 +233,7 @@ static void sigbusHandler(int signum, siginfo_t *info, void *context)
}
}
void *ShmClientBuffer::map()
void *ShmClientBuffer::map(MapFlags flags)
{
if (!m_shmPool->sigbusImpossible) {
// A SIGBUS signal may be emitted if the backing file is shrinked and we access now

@ -57,7 +57,7 @@ public:
ShmClientBuffer(ShmPool *pool, KWin::ShmAttributes attributes, wl_client *client, uint32_t id);
~ShmClientBuffer() override;
void *map() override;
void *map(MapFlags flags) override;
void unmap() override;
QSize size() const override;

Loading…
Cancel
Save