surfaceitem, surfacetexture: manage pixmaps and textures with std::unique_ptr

This commit is contained in:
Xaver Hugl 2022-06-29 13:24:56 +02:00
parent 1ff623e95e
commit da7dad1586
12 changed files with 32 additions and 28 deletions

View file

@ -215,11 +215,13 @@ EglSurfaceTextureX11::EglSurfaceTextureX11(EglBackend *backend, SurfacePixmapX11
bool EglSurfaceTextureX11::create()
{
auto texture = new EglPixmapTexture(static_cast<EglBackend *>(m_backend));
auto texture = std::make_unique<EglPixmapTexture>(static_cast<EglBackend *>(m_backend));
if (texture->create(m_pixmap)) {
m_texture.reset(texture);
m_texture = std::move(texture);
return true;
} else {
return false;
}
return !m_texture.isNull();
}
void EglSurfaceTextureX11::update(const QRegion &region)

View file

@ -872,11 +872,13 @@ GlxSurfaceTextureX11::GlxSurfaceTextureX11(GlxBackend *backend, SurfacePixmapX11
bool GlxSurfaceTextureX11::create()
{
auto texture = new GlxPixmapTexture(static_cast<GlxBackend *>(m_backend));
auto texture = std::make_unique<GlxPixmapTexture>(static_cast<GlxBackend *>(m_backend));
if (texture->create(m_pixmap)) {
m_texture.reset(texture);
m_texture = std::move(texture);
return true;
} else {
return false;
}
return !m_texture.isNull();
}
void GlxSurfaceTextureX11::update(const QRegion &region)

View file

@ -21,7 +21,7 @@ OpenGLSurfaceTexture::~OpenGLSurfaceTexture()
bool OpenGLSurfaceTexture::isValid() const
{
return !m_texture.isNull();
return m_texture != nullptr;
}
OpenGLBackend *OpenGLSurfaceTexture::backend() const
@ -31,7 +31,7 @@ OpenGLBackend *OpenGLSurfaceTexture::backend() const
GLTexture *OpenGLSurfaceTexture::texture() const
{
return m_texture.data();
return m_texture.get();
}
} // namespace KWin

View file

@ -30,7 +30,7 @@ public:
protected:
OpenGLBackend *m_backend;
QScopedPointer<GLTexture> m_texture;
std::unique_ptr<GLTexture> m_texture;
};
} // namespace KWin

View file

@ -59,17 +59,17 @@ QRegion SurfaceItem::damage() const
SurfacePixmap *SurfaceItem::pixmap() const
{
if (m_pixmap && m_pixmap->isValid()) {
return m_pixmap.data();
return m_pixmap.get();
}
if (m_previousPixmap && m_previousPixmap->isValid()) {
return m_previousPixmap.data();
return m_previousPixmap.get();
}
return nullptr;
}
SurfacePixmap *SurfaceItem::previousPixmap() const
{
return m_previousPixmap.data();
return m_previousPixmap.get();
}
void SurfaceItem::referencePreviousPixmap()
@ -92,8 +92,8 @@ void SurfaceItem::unreferencePreviousPixmap()
void SurfaceItem::updatePixmap()
{
if (m_pixmap.isNull()) {
m_pixmap.reset(createPixmap());
if (!m_pixmap) {
m_pixmap = createPixmap();
}
if (m_pixmap->isValid()) {
m_pixmap->update();
@ -108,9 +108,9 @@ void SurfaceItem::updatePixmap()
void SurfaceItem::discardPixmap()
{
if (!m_pixmap.isNull()) {
if (m_pixmap) {
if (m_pixmap->isValid()) {
m_previousPixmap.reset(m_pixmap.take());
m_previousPixmap = std::move(m_pixmap);
m_previousPixmap->markAsDiscarded();
referencePreviousPixmap();
} else {

View file

@ -44,7 +44,7 @@ public:
protected:
explicit SurfaceItem(Window *window, Item *parent = nullptr);
virtual SurfacePixmap *createPixmap() = 0;
virtual std::unique_ptr<SurfacePixmap> createPixmap() = 0;
void preprocess() override;
WindowQuadList buildQuads() const override;
@ -52,8 +52,8 @@ protected:
Window *m_window;
QRegion m_damage;
QScopedPointer<SurfacePixmap> m_pixmap;
QScopedPointer<SurfacePixmap> m_previousPixmap;
std::unique_ptr<SurfacePixmap> m_pixmap;
std::unique_ptr<SurfacePixmap> m_previousPixmap;
QMatrix4x4 m_surfaceToBufferMatrix;
int m_referencePixmapCounter = 0;
};

View file

@ -31,9 +31,9 @@ QRegion SurfaceItemInternal::shape() const
return QRegion(rect());
}
SurfacePixmap *SurfaceItemInternal::createPixmap()
std::unique_ptr<SurfacePixmap> SurfaceItemInternal::createPixmap()
{
return new SurfacePixmapInternal(this);
return std::make_unique<SurfacePixmapInternal>(this);
}
void SurfaceItemInternal::handleBufferGeometryChanged(Window *window, const QRect &old)

View file

@ -31,7 +31,7 @@ private Q_SLOTS:
void handleBufferGeometryChanged(Window *window, const QRect &old);
protected:
SurfacePixmap *createPixmap() override;
std::unique_ptr<SurfacePixmap> createPixmap() override;
};
class KWIN_EXPORT SurfacePixmapInternal final : public SurfacePixmap

View file

@ -132,9 +132,9 @@ void SurfaceItemWayland::handleSubSurfaceMappedChanged()
setVisible(m_surface->isMapped());
}
SurfacePixmap *SurfaceItemWayland::createPixmap()
std::unique_ptr<SurfacePixmap> SurfaceItemWayland::createPixmap()
{
return new SurfacePixmapWayland(this);
return std::make_unique<SurfacePixmapWayland>(this);
}
SurfacePixmapWayland::SurfacePixmapWayland(SurfaceItemWayland *item, QObject *parent)

View file

@ -45,7 +45,7 @@ private Q_SLOTS:
void handleSubSurfaceMappedChanged();
protected:
SurfacePixmap *createPixmap() override;
std::unique_ptr<SurfacePixmap> createPixmap() override;
private:
SurfaceItemWayland *getOrCreateSubSurfaceItem(KWaylandServer::SubSurfaceInterface *s);

View file

@ -146,9 +146,9 @@ QRegion SurfaceItemX11::opaque() const
}
}
SurfacePixmap *SurfaceItemX11::createPixmap()
std::unique_ptr<SurfacePixmap> SurfaceItemX11::createPixmap()
{
return new SurfacePixmapX11(this);
return std::make_unique<SurfacePixmapX11>(this);
}
SurfacePixmapX11::SurfacePixmapX11(SurfaceItemX11 *item, QObject *parent)

View file

@ -40,7 +40,7 @@ private Q_SLOTS:
void handleGeometryShapeChanged();
protected:
SurfacePixmap *createPixmap() override;
std::unique_ptr<SurfacePixmap> createPixmap() override;
private:
xcb_damage_damage_t m_damageHandle = XCB_NONE;