DRM: Use QSharedPointer
This commit is contained in:
parent
5c15cca190
commit
c737fde3da
16 changed files with 52 additions and 116 deletions
|
@ -23,9 +23,6 @@ public:
|
||||||
virtual ~DrmBuffer() = default;
|
virtual ~DrmBuffer() = default;
|
||||||
|
|
||||||
virtual bool needsModeChange(DrmBuffer *b) const {Q_UNUSED(b) return false;}
|
virtual bool needsModeChange(DrmBuffer *b) const {Q_UNUSED(b) return false;}
|
||||||
virtual bool shouldDeleteAfterPageflip() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 bufferId() const {
|
quint32 bufferId() const {
|
||||||
return m_bufferId;
|
return m_bufferId;
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
// DrmSurfaceBuffer
|
// DrmSurfaceBuffer
|
||||||
DrmSurfaceBuffer::DrmSurfaceBuffer(int fd, const std::shared_ptr<GbmSurface> &surface)
|
DrmSurfaceBuffer::DrmSurfaceBuffer(int fd, const QSharedPointer<GbmSurface> &surface)
|
||||||
: DrmBuffer(fd)
|
: DrmBuffer(fd)
|
||||||
, m_surface(surface)
|
, m_surface(surface)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "drm_buffer.h"
|
#include "drm_buffer.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
struct gbm_bo;
|
struct gbm_bo;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class GbmSurface;
|
||||||
class DrmSurfaceBuffer : public DrmBuffer
|
class DrmSurfaceBuffer : public DrmBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DrmSurfaceBuffer(int fd, const std::shared_ptr<GbmSurface> &surface);
|
DrmSurfaceBuffer(int fd, const QSharedPointer<GbmSurface> &surface);
|
||||||
DrmSurfaceBuffer(int fd, gbm_bo *buffer, KWaylandServer::BufferInterface *bufferInterface);
|
DrmSurfaceBuffer(int fd, gbm_bo *buffer, KWaylandServer::BufferInterface *bufferInterface);
|
||||||
~DrmSurfaceBuffer() override;
|
~DrmSurfaceBuffer() override;
|
||||||
|
|
||||||
|
@ -40,9 +40,6 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool shouldDeleteAfterPageflip() const override {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasBo() const {
|
bool hasBo() const {
|
||||||
return m_bo != nullptr;
|
return m_bo != nullptr;
|
||||||
|
@ -55,7 +52,7 @@ public:
|
||||||
void releaseGbm() override;
|
void releaseGbm() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<GbmSurface> m_surface;
|
QSharedPointer<GbmSurface> m_surface;
|
||||||
gbm_bo *m_bo = nullptr;
|
gbm_bo *m_bo = nullptr;
|
||||||
KWaylandServer::BufferInterface *m_bufferInterface = nullptr;
|
KWaylandServer::BufferInterface *m_bufferInterface = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -82,10 +82,6 @@ public:
|
||||||
m_eglDisplay = display;
|
m_eglDisplay = display;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmDumbBuffer *createBuffer(const QSize &size) const {
|
|
||||||
return new DrmDumbBuffer(m_fd, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setEglBackend(AbstractEglBackend *eglBackend) {
|
void setEglBackend(AbstractEglBackend *eglBackend) {
|
||||||
m_eglBackend = eglBackend;
|
m_eglBackend = eglBackend;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,6 @@ bool DrmCrtc::initProps()
|
||||||
|
|
||||||
void DrmCrtc::flipBuffer()
|
void DrmCrtc::flipBuffer()
|
||||||
{
|
{
|
||||||
if (m_currentBuffer && m_currentBuffer->shouldDeleteAfterPageflip() && m_currentBuffer != m_nextBuffer) {
|
|
||||||
delete m_currentBuffer;
|
|
||||||
}
|
|
||||||
m_currentBuffer = m_nextBuffer;
|
m_currentBuffer = m_nextBuffer;
|
||||||
m_nextBuffer = nullptr;
|
m_nextBuffer = nullptr;
|
||||||
|
|
||||||
|
@ -84,7 +81,7 @@ bool DrmCrtc::blank(DrmOutput *output)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_blackBuffer) {
|
if (!m_blackBuffer) {
|
||||||
DrmDumbBuffer *blackBuffer = m_gpu->createBuffer(output->pixelSize());
|
DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(m_gpu->fd(), output->pixelSize());
|
||||||
if (!blackBuffer->map()) {
|
if (!blackBuffer->map()) {
|
||||||
delete blackBuffer;
|
delete blackBuffer;
|
||||||
return false;
|
return false;
|
||||||
|
@ -94,10 +91,6 @@ bool DrmCrtc::blank(DrmOutput *output)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output->setModeLegacy(m_blackBuffer)) {
|
if (output->setModeLegacy(m_blackBuffer)) {
|
||||||
if (m_currentBuffer && m_currentBuffer->shouldDeleteAfterPageflip()) {
|
|
||||||
delete m_currentBuffer;
|
|
||||||
delete m_nextBuffer;
|
|
||||||
}
|
|
||||||
m_currentBuffer = nullptr;
|
m_currentBuffer = nullptr;
|
||||||
m_nextBuffer = nullptr;
|
m_nextBuffer = nullptr;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include "drm_object.h"
|
#include "drm_object.h"
|
||||||
|
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -41,13 +43,13 @@ public:
|
||||||
return m_resIndex;
|
return m_resIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmBuffer *current() {
|
QSharedPointer<DrmBuffer> current() {
|
||||||
return m_currentBuffer;
|
return m_currentBuffer;
|
||||||
}
|
}
|
||||||
DrmBuffer *next() {
|
QSharedPointer<DrmBuffer> next() {
|
||||||
return m_nextBuffer;
|
return m_nextBuffer;
|
||||||
}
|
}
|
||||||
void setNext(DrmBuffer *buffer) {
|
void setNext(const QSharedPointer<DrmBuffer> &buffer) {
|
||||||
m_nextBuffer = buffer;
|
m_nextBuffer = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +69,8 @@ private:
|
||||||
int m_resIndex;
|
int m_resIndex;
|
||||||
uint32_t m_gammaRampSize = 0;
|
uint32_t m_gammaRampSize = 0;
|
||||||
|
|
||||||
DrmBuffer *m_currentBuffer = nullptr;
|
QSharedPointer<DrmBuffer> m_currentBuffer;
|
||||||
DrmBuffer *m_nextBuffer = nullptr;
|
QSharedPointer<DrmBuffer> m_nextBuffer;
|
||||||
DrmDumbBuffer *m_blackBuffer = nullptr;
|
DrmDumbBuffer *m_blackBuffer = nullptr;
|
||||||
DrmBackend *m_backend;
|
DrmBackend *m_backend;
|
||||||
DrmGpu *m_gpu;
|
DrmGpu *m_gpu;
|
||||||
|
|
|
@ -19,12 +19,6 @@ DrmPlane::DrmPlane(uint32_t plane_id, int fd)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmPlane::~DrmPlane()
|
|
||||||
{
|
|
||||||
delete m_current;
|
|
||||||
delete m_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DrmPlane::init()
|
bool DrmPlane::init()
|
||||||
{
|
{
|
||||||
qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id;
|
qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id;
|
||||||
|
@ -137,7 +131,7 @@ DrmPlane::TypeIndex DrmPlane::type()
|
||||||
return TypeIndex::Overlay;
|
return TypeIndex::Overlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrmPlane::setNext(DrmBuffer *b)
|
void DrmPlane::setNext(const QSharedPointer<DrmBuffer> &b)
|
||||||
{
|
{
|
||||||
if (auto property = m_props.at(int(PropertyIndex::FbId))) {
|
if (auto property = m_props.at(int(PropertyIndex::FbId))) {
|
||||||
property->setValue(b ? b->bufferId() : 0);
|
property->setValue(b ? b->bufferId() : 0);
|
||||||
|
@ -164,9 +158,6 @@ DrmPlane::Transformations DrmPlane::transformation()
|
||||||
|
|
||||||
void DrmPlane::flipBuffer()
|
void DrmPlane::flipBuffer()
|
||||||
{
|
{
|
||||||
if (m_current != m_next && m_current && m_current->shouldDeleteAfterPageflip()) {
|
|
||||||
delete m_current;
|
|
||||||
}
|
|
||||||
m_current = m_next;
|
m_current = m_next;
|
||||||
m_next = nullptr;
|
m_next = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <qobjectdefs.h>
|
#include <qobjectdefs.h>
|
||||||
#include <xf86drmMode.h>
|
#include <xf86drmMode.h>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
@ -24,8 +25,6 @@ class DrmPlane : public DrmObject
|
||||||
public:
|
public:
|
||||||
DrmPlane(uint32_t plane_id, int fd);
|
DrmPlane(uint32_t plane_id, int fd);
|
||||||
|
|
||||||
~DrmPlane() override;
|
|
||||||
|
|
||||||
enum class PropertyIndex {
|
enum class PropertyIndex {
|
||||||
Type = 0,
|
Type = 0,
|
||||||
SrcX,
|
SrcX,
|
||||||
|
@ -73,16 +72,16 @@ public:
|
||||||
return m_formats;
|
return m_formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmBuffer *current() const {
|
QSharedPointer<DrmBuffer> current() const {
|
||||||
return m_current;
|
return m_current;
|
||||||
}
|
}
|
||||||
DrmBuffer *next() const {
|
QSharedPointer<DrmBuffer> next() const {
|
||||||
return m_next;
|
return m_next;
|
||||||
}
|
}
|
||||||
void setCurrent(DrmBuffer *b) {
|
void setCurrent(const QSharedPointer<DrmBuffer> &b) {
|
||||||
m_current = b;
|
m_current = b;
|
||||||
}
|
}
|
||||||
void setNext(DrmBuffer *b);
|
void setNext(const QSharedPointer<DrmBuffer> &b);
|
||||||
void setTransformation(Transformations t);
|
void setTransformation(Transformations t);
|
||||||
Transformations transformation();
|
Transformations transformation();
|
||||||
|
|
||||||
|
@ -95,8 +94,8 @@ public:
|
||||||
bool atomicPopulate(drmModeAtomicReq *req) const override;
|
bool atomicPopulate(drmModeAtomicReq *req) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DrmBuffer *m_current = nullptr;
|
QSharedPointer<DrmBuffer> m_current;
|
||||||
DrmBuffer *m_next = nullptr;
|
QSharedPointer<DrmBuffer> m_next;
|
||||||
|
|
||||||
// TODO: See weston drm_output_check_plane_format for future use of these member variables
|
// TODO: See weston drm_output_check_plane_format for future use of these member variables
|
||||||
QVector<uint32_t> m_formats; // Possible formats, which can be presented on this plane
|
QVector<uint32_t> m_formats; // Possible formats, which can be presented on this plane
|
||||||
|
|
|
@ -70,9 +70,6 @@ void DrmOutput::teardown()
|
||||||
|
|
||||||
if (m_primaryPlane) {
|
if (m_primaryPlane) {
|
||||||
// TODO: when having multiple planes, also clean up these
|
// TODO: when having multiple planes, also clean up these
|
||||||
if (m_primaryPlane->current() && m_primaryPlane->current()->shouldDeleteAfterPageflip()) {
|
|
||||||
delete m_primaryPlane->current();
|
|
||||||
}
|
|
||||||
m_primaryPlane->setCurrent(nullptr);
|
m_primaryPlane->setCurrent(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +83,7 @@ void DrmOutput::teardown()
|
||||||
|
|
||||||
void DrmOutput::releaseGbm()
|
void DrmOutput::releaseGbm()
|
||||||
{
|
{
|
||||||
if (DrmBuffer *b = m_crtc->current()) {
|
if (const auto &b = m_crtc->current()) {
|
||||||
b->releaseGbm();
|
b->releaseGbm();
|
||||||
}
|
}
|
||||||
if (m_primaryPlane && m_primaryPlane->current()) {
|
if (m_primaryPlane && m_primaryPlane->current()) {
|
||||||
|
@ -362,7 +359,7 @@ void DrmOutput::initEdid(drmModeConnector *connector)
|
||||||
bool DrmOutput::initCursor(const QSize &cursorSize)
|
bool DrmOutput::initCursor(const QSize &cursorSize)
|
||||||
{
|
{
|
||||||
auto createCursor = [this, cursorSize] (int index) {
|
auto createCursor = [this, cursorSize] (int index) {
|
||||||
m_cursor[index].reset(m_gpu->createBuffer(cursorSize));
|
m_cursor[index].reset(new DrmDumbBuffer(m_gpu->fd(), cursorSize));
|
||||||
if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) {
|
if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -684,7 +681,7 @@ void DrmOutput::pageFlipped()
|
||||||
} else {
|
} else {
|
||||||
if (!m_crtc->next()) {
|
if (!m_crtc->next()) {
|
||||||
// on manual vt switch
|
// on manual vt switch
|
||||||
if (DrmBuffer *b = m_crtc->current()) {
|
if (const auto &b = m_crtc->current()) {
|
||||||
b->releaseGbm();
|
b->releaseGbm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -696,27 +693,15 @@ void DrmOutput::pageFlipped()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrmOutput::present(DrmBuffer *buffer)
|
bool DrmOutput::present(const QSharedPointer<DrmBuffer> &buffer)
|
||||||
{
|
{
|
||||||
if (!buffer || buffer->bufferId() == 0) {
|
if (!buffer || buffer->bufferId() == 0) {
|
||||||
if (buffer && buffer->shouldDeleteAfterPageflip()) {
|
|
||||||
delete buffer;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (m_dpmsModePending != DpmsMode::On) {
|
if (m_dpmsModePending != DpmsMode::On) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool result;
|
return m_gpu->atomicModeSetting() ? presentAtomically(buffer) : presentLegacy(buffer);
|
||||||
if (m_gpu->atomicModeSetting()) {
|
|
||||||
result = presentAtomically(buffer);
|
|
||||||
} else {
|
|
||||||
result = presentLegacy(buffer);
|
|
||||||
}
|
|
||||||
if (!result && buffer->shouldDeleteAfterPageflip()) {
|
|
||||||
delete buffer;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrmOutput::dpmsAtomicOff()
|
bool DrmOutput::dpmsAtomicOff()
|
||||||
|
@ -724,7 +709,6 @@ bool DrmOutput::dpmsAtomicOff()
|
||||||
m_atomicOffPending = false;
|
m_atomicOffPending = false;
|
||||||
|
|
||||||
// TODO: With multiple planes: deactivate all of them here
|
// TODO: With multiple planes: deactivate all of them here
|
||||||
delete m_primaryPlane->next();
|
|
||||||
m_primaryPlane->setNext(nullptr);
|
m_primaryPlane->setNext(nullptr);
|
||||||
m_nextPlanesFlipList << m_primaryPlane;
|
m_nextPlanesFlipList << m_primaryPlane;
|
||||||
|
|
||||||
|
@ -742,7 +726,7 @@ bool DrmOutput::dpmsAtomicOff()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrmOutput::presentAtomically(DrmBuffer *buffer)
|
bool DrmOutput::presentAtomically(const QSharedPointer<DrmBuffer> &buffer)
|
||||||
{
|
{
|
||||||
if (!m_backend->session()->isActive()) {
|
if (!m_backend->session()->isActive()) {
|
||||||
qCWarning(KWIN_DRM) << "Refusing to present output because session is inactive";
|
qCWarning(KWIN_DRM) << "Refusing to present output because session is inactive";
|
||||||
|
@ -810,7 +794,7 @@ bool DrmOutput::presentAtomically(DrmBuffer *buffer)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrmOutput::presentLegacy(DrmBuffer *buffer)
|
bool DrmOutput::presentLegacy(const QSharedPointer<DrmBuffer> &buffer)
|
||||||
{
|
{
|
||||||
if (m_crtc->next()) {
|
if (m_crtc->next()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -821,8 +805,8 @@ bool DrmOutput::presentLegacy(DrmBuffer *buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we need to set a new mode first?
|
// Do we need to set a new mode first?
|
||||||
if (!m_crtc->current() || m_crtc->current()->needsModeChange(buffer)) {
|
if (!m_crtc->current() || m_crtc->current()->needsModeChange(buffer.get())) {
|
||||||
if (!setModeLegacy(buffer)) {
|
if (!setModeLegacy(buffer.get())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -969,12 +953,6 @@ bool DrmOutput::atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable)
|
||||||
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcH), targetRect.height());
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcH), targetRect.height());
|
||||||
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcId), m_crtc->id());
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcId), m_crtc->id());
|
||||||
} else {
|
} else {
|
||||||
if (m_primaryPlane->current() && m_primaryPlane->current()->shouldDeleteAfterPageflip()) {
|
|
||||||
delete m_primaryPlane->current();
|
|
||||||
}
|
|
||||||
if (m_primaryPlane->next() && m_primaryPlane->next()->shouldDeleteAfterPageflip()) {
|
|
||||||
delete m_primaryPlane->next();
|
|
||||||
}
|
|
||||||
m_primaryPlane->setCurrent(nullptr);
|
m_primaryPlane->setCurrent(nullptr);
|
||||||
m_primaryPlane->setNext(nullptr);
|
m_primaryPlane->setNext(nullptr);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QSharedPointer>
|
||||||
#include <xf86drmMode.h>
|
#include <xf86drmMode.h>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
|
@ -51,7 +52,7 @@ public:
|
||||||
bool updateCursor();
|
bool updateCursor();
|
||||||
void moveCursor();
|
void moveCursor();
|
||||||
bool init(drmModeConnector *connector);
|
bool init(drmModeConnector *connector);
|
||||||
bool present(DrmBuffer *buffer);
|
bool present(const QSharedPointer<DrmBuffer> &buffer);
|
||||||
void pageFlipped();
|
void pageFlipped();
|
||||||
|
|
||||||
// These values are defined by the kernel
|
// These values are defined by the kernel
|
||||||
|
@ -105,7 +106,7 @@ private:
|
||||||
// and save the connector ids in the DrmCrtc instance.
|
// and save the connector ids in the DrmCrtc instance.
|
||||||
DrmOutput(DrmBackend *backend, DrmGpu* gpu);
|
DrmOutput(DrmBackend *backend, DrmGpu* gpu);
|
||||||
|
|
||||||
bool presentAtomically(DrmBuffer *buffer);
|
bool presentAtomically(const QSharedPointer<DrmBuffer> &buffer);
|
||||||
|
|
||||||
enum class AtomicCommitMode {
|
enum class AtomicCommitMode {
|
||||||
Test,
|
Test,
|
||||||
|
@ -113,7 +114,7 @@ private:
|
||||||
};
|
};
|
||||||
bool doAtomicCommit(AtomicCommitMode mode);
|
bool doAtomicCommit(AtomicCommitMode mode);
|
||||||
|
|
||||||
bool presentLegacy(DrmBuffer *buffer);
|
bool presentLegacy(const QSharedPointer<DrmBuffer> &buffer);
|
||||||
bool setModeLegacy(DrmBuffer *buffer);
|
bool setModeLegacy(DrmBuffer *buffer);
|
||||||
void initEdid(drmModeConnector *connector);
|
void initEdid(drmModeConnector *connector);
|
||||||
void initDpms(drmModeConnector *connector);
|
void initDpms(drmModeConnector *connector);
|
||||||
|
|
|
@ -162,7 +162,7 @@ bool EglGbmBackend::initRenderingContext()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLSurface EglGbmBackend::createEglSurface(std::shared_ptr<GbmSurface> gbmSurface) const
|
EGLSurface EglGbmBackend::createEglSurface(QSharedPointer<GbmSurface> gbmSurface) const
|
||||||
{
|
{
|
||||||
auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(),
|
auto eglSurface = eglCreatePlatformWindowSurfaceEXT(eglDisplay(), config(),
|
||||||
(void *)(gbmSurface->surface()), nullptr);
|
(void *)(gbmSurface->surface()), nullptr);
|
||||||
|
@ -184,10 +184,10 @@ bool EglGbmBackend::resetOutput(Output &output, DrmOutput *drmOutput)
|
||||||
} else {
|
} else {
|
||||||
flags |= GBM_BO_USE_LINEAR;
|
flags |= GBM_BO_USE_LINEAR;
|
||||||
}
|
}
|
||||||
auto gbmSurface = std::make_shared<GbmSurface>(m_gpu->gbmDevice(),
|
auto gbmSurface = QSharedPointer<GbmSurface>::create(m_gpu->gbmDevice(),
|
||||||
size.width(), size.height(),
|
size.width(), size.height(),
|
||||||
GBM_FORMAT_XRGB8888,
|
GBM_FORMAT_XRGB8888,
|
||||||
flags);
|
flags);
|
||||||
if (!gbmSurface) {
|
if (!gbmSurface) {
|
||||||
qCCritical(KWIN_DRM) << "Creating GBM surface failed";
|
qCCritical(KWIN_DRM) << "Creating GBM surface failed";
|
||||||
return false;
|
return false;
|
||||||
|
@ -376,7 +376,7 @@ void EglGbmBackend::initRenderTarget(Output &output)
|
||||||
// Already initialized.
|
// Already initialized.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::shared_ptr<GLVertexBuffer> vbo(new GLVertexBuffer(KWin::GLVertexBuffer::Static));
|
QSharedPointer<GLVertexBuffer> vbo(new GLVertexBuffer(KWin::GLVertexBuffer::Static));
|
||||||
vbo->setData(6, 2, vertices, texCoords);
|
vbo->setData(6, 2, vertices, texCoords);
|
||||||
output.render.vbo = vbo;
|
output.render.vbo = vbo;
|
||||||
}
|
}
|
||||||
|
@ -580,7 +580,7 @@ void EglGbmBackend::aboutToStartPainting(int screenId, const QRegion &damagedReg
|
||||||
bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion)
|
bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion)
|
||||||
{
|
{
|
||||||
if (output.directScanoutBuffer) {
|
if (output.directScanoutBuffer) {
|
||||||
output.buffer = new DrmSurfaceBuffer(m_gpu->fd(), output.directScanoutBuffer, output.bufferInterface);
|
output.buffer = QSharedPointer<DrmSurfaceBuffer>::create(m_gpu->fd(), output.directScanoutBuffer, output.bufferInterface);
|
||||||
} else if (isPrimary()) {
|
} else if (isPrimary()) {
|
||||||
if (supportsSwapBuffersWithDamage()) {
|
if (supportsSwapBuffersWithDamage()) {
|
||||||
QVector<EGLint> rects = regionToRects(output.damageHistory.constFirst(), output.output);
|
QVector<EGLint> rects = regionToRects(output.damageHistory.constFirst(), output.output);
|
||||||
|
@ -595,7 +595,7 @@ bool EglGbmBackend::presentOnOutput(Output &output, const QRegion &damagedRegion
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output.buffer = new DrmSurfaceBuffer(m_gpu->fd(), output.gbmSurface);
|
output.buffer = QSharedPointer<DrmSurfaceBuffer>::create(m_gpu->fd(), output.gbmSurface);
|
||||||
} else {
|
} else {
|
||||||
qCDebug(KWIN_DRM) << "imported gbm_bo does not exist!";
|
qCDebug(KWIN_DRM) << "imported gbm_bo does not exist!";
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#define KWIN_EGL_GBM_BACKEND_H
|
#define KWIN_EGL_GBM_BACKEND_H
|
||||||
#include "abstract_egl_drm_backend.h"
|
#include "abstract_egl_drm_backend.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
struct gbm_surface;
|
struct gbm_surface;
|
||||||
struct gbm_bo;
|
struct gbm_bo;
|
||||||
|
@ -67,8 +67,8 @@ private:
|
||||||
|
|
||||||
struct Output {
|
struct Output {
|
||||||
DrmOutput *output = nullptr;
|
DrmOutput *output = nullptr;
|
||||||
DrmSurfaceBuffer *buffer = nullptr;
|
QSharedPointer<DrmSurfaceBuffer> buffer;
|
||||||
std::shared_ptr<GbmSurface> gbmSurface;
|
QSharedPointer<GbmSurface> gbmSurface;
|
||||||
EGLSurface eglSurface = EGL_NO_SURFACE;
|
EGLSurface eglSurface = EGL_NO_SURFACE;
|
||||||
int bufferAge = 0;
|
int bufferAge = 0;
|
||||||
/**
|
/**
|
||||||
|
@ -79,7 +79,7 @@ private:
|
||||||
struct {
|
struct {
|
||||||
GLuint framebuffer = 0;
|
GLuint framebuffer = 0;
|
||||||
GLuint texture = 0;
|
GLuint texture = 0;
|
||||||
std::shared_ptr<GLVertexBuffer> vbo;
|
QSharedPointer<GLVertexBuffer> vbo;
|
||||||
} render;
|
} render;
|
||||||
|
|
||||||
int dmabufFd = 0;
|
int dmabufFd = 0;
|
||||||
|
@ -90,7 +90,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
bool resetOutput(Output &output, DrmOutput *drmOutput);
|
bool resetOutput(Output &output, DrmOutput *drmOutput);
|
||||||
EGLSurface createEglSurface(std::shared_ptr<GbmSurface> gbmSurface) const;
|
EGLSurface createEglSurface(QSharedPointer<GbmSurface> gbmSurface) const;
|
||||||
|
|
||||||
bool makeContextCurrent(const Output &output) const;
|
bool makeContextCurrent(const Output &output) const;
|
||||||
void setViewport(const Output &output) const;
|
void setViewport(const Output &output) const;
|
||||||
|
|
|
@ -85,9 +85,6 @@ void EglStreamBackend::cleanupSurfaces()
|
||||||
|
|
||||||
void EglStreamBackend::cleanupOutput(const Output &o)
|
void EglStreamBackend::cleanupOutput(const Output &o)
|
||||||
{
|
{
|
||||||
if (o.buffer != nullptr) {
|
|
||||||
delete o.buffer;
|
|
||||||
}
|
|
||||||
if (o.eglSurface != EGL_NO_SURFACE) {
|
if (o.eglSurface != EGL_NO_SURFACE) {
|
||||||
eglDestroySurface(eglDisplay(), o.eglSurface);
|
eglDestroySurface(eglDisplay(), o.eglSurface);
|
||||||
}
|
}
|
||||||
|
@ -283,11 +280,8 @@ bool EglStreamBackend::initRenderingContext()
|
||||||
bool EglStreamBackend::resetOutput(Output &o, DrmOutput *drmOutput)
|
bool EglStreamBackend::resetOutput(Output &o, DrmOutput *drmOutput)
|
||||||
{
|
{
|
||||||
o.output = drmOutput;
|
o.output = drmOutput;
|
||||||
if (o.buffer != nullptr) {
|
|
||||||
delete o.buffer;
|
|
||||||
}
|
|
||||||
// dumb buffer used for modesetting
|
// dumb buffer used for modesetting
|
||||||
o.buffer = m_gpu->createBuffer(drmOutput->pixelSize());
|
o.buffer = QSharedPointer<DrmDumbBuffer>::create(m_gpu->fd(), drmOutput->pixelSize());
|
||||||
|
|
||||||
EGLAttrib streamAttribs[] = {
|
EGLAttrib streamAttribs[] = {
|
||||||
EGL_STREAM_FIFO_LENGTH_KHR, 0, // mailbox mode
|
EGL_STREAM_FIFO_LENGTH_KHR, 0, // mailbox mode
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
struct Output
|
struct Output
|
||||||
{
|
{
|
||||||
DrmOutput *output = nullptr;
|
DrmOutput *output = nullptr;
|
||||||
DrmBuffer *buffer = nullptr;
|
QSharedPointer<DrmBuffer> buffer;
|
||||||
EGLSurface eglSurface = EGL_NO_SURFACE;
|
EGLSurface eglSurface = EGL_NO_SURFACE;
|
||||||
EGLStreamKHR eglStream = EGL_NO_STREAM_KHR;
|
EGLStreamKHR eglStream = EGL_NO_STREAM_KHR;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,26 +36,16 @@ DrmQPainterBackend::DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu)
|
||||||
if (it == m_outputs.end()) {
|
if (it == m_outputs.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete (*it).buffer[0];
|
|
||||||
delete (*it).buffer[1];
|
|
||||||
m_outputs.erase(it);
|
m_outputs.erase(it);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrmQPainterBackend::~DrmQPainterBackend()
|
|
||||||
{
|
|
||||||
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
|
||||||
delete (*it).buffer[0];
|
|
||||||
delete (*it).buffer[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrmQPainterBackend::initOutput(DrmOutput *output)
|
void DrmQPainterBackend::initOutput(DrmOutput *output)
|
||||||
{
|
{
|
||||||
Output o;
|
Output o;
|
||||||
auto initBuffer = [&o, output, this] (int index) {
|
auto initBuffer = [&o, output, this] (int index) {
|
||||||
o.buffer[index] = m_gpu->createBuffer(output->pixelSize());
|
o.buffer[index] = QSharedPointer<DrmDumbBuffer>::create(m_gpu->fd(), output->pixelSize());
|
||||||
if (o.buffer[index]->map()) {
|
if (o.buffer[index]->map()) {
|
||||||
o.buffer[index]->image()->fill(Qt::black);
|
o.buffer[index]->image()->fill(Qt::black);
|
||||||
}
|
}
|
||||||
|
@ -70,10 +60,8 @@ void DrmQPainterBackend::initOutput(DrmOutput *output)
|
||||||
if (it == m_outputs.end()) {
|
if (it == m_outputs.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete (*it).buffer[0];
|
|
||||||
delete (*it).buffer[1];
|
|
||||||
auto initBuffer = [it, output, this] (int index) {
|
auto initBuffer = [it, output, this] (int index) {
|
||||||
it->buffer[index] = m_gpu->createBuffer(output->pixelSize());
|
it->buffer[index] = QSharedPointer<DrmDumbBuffer>::create(m_gpu->fd(), output->pixelSize());
|
||||||
if (it->buffer[index]->map()) {
|
if (it->buffer[index]->map()) {
|
||||||
it->buffer[index]->image()->fill(Qt::black);
|
it->buffer[index]->image()->fill(Qt::black);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
@ -26,7 +27,6 @@ class DrmQPainterBackend : public QObject, public QPainterBackend
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu);
|
DrmQPainterBackend(DrmBackend *backend, DrmGpu *gpu);
|
||||||
~DrmQPainterBackend() override;
|
|
||||||
|
|
||||||
QImage *bufferForScreen(int screenId) override;
|
QImage *bufferForScreen(int screenId) override;
|
||||||
bool needsFullRepaint(int screenId) const override;
|
bool needsFullRepaint(int screenId) const override;
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void initOutput(DrmOutput *output);
|
void initOutput(DrmOutput *output);
|
||||||
struct Output {
|
struct Output {
|
||||||
DrmDumbBuffer *buffer[2];
|
QSharedPointer<DrmDumbBuffer> buffer[2];
|
||||||
DrmOutput *output;
|
DrmOutput *output;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue