Commit da7dad15 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

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

parent 1ff623e9
Pipeline #197032 passed with stage
in 31 minutes and 8 seconds
......@@ -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)
......
......@@ -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)
......
......@@ -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
......@@ -30,7 +30,7 @@ public:
protected:
OpenGLBackend *m_backend;
QScopedPointer<GLTexture> m_texture;
std::unique_ptr<GLTexture> m_texture;
};
} // namespace KWin
......@@ -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 {
......
......@@ -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;
};
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment