From bfc8bcb24a7cbe77134d6d2900cd49a2aaa86851 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 15 May 2023 01:19:24 +0200 Subject: [PATCH] libkwineffects: use std::unique_ptr in GLTexture The implicit internal sharing stuff wasn't used in KWin, and the way the d pointer was initialized was horrible --- .../standalone/x11_standalone_egl_backend.cpp | 2 +- .../standalone/x11_standalone_glx_backend.cpp | 2 +- src/libkwineffects/kwingltexture.cpp | 20 ++----------------- src/libkwineffects/kwingltexture.h | 8 ++------ src/plugins/backgroundcontrast/contrast.cpp | 1 - 5 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp index 4ba253c926..0e25a8c596 100644 --- a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp @@ -418,7 +418,7 @@ void EglSurfaceTextureX11::update(const QRegion ®ion) } EglPixmapTexture::EglPixmapTexture(EglBackend *backend) - : GLTexture(*new EglPixmapTexturePrivate(this, backend)) + : GLTexture(std::make_unique(this, backend)) { } diff --git a/src/backends/x11/standalone/x11_standalone_glx_backend.cpp b/src/backends/x11/standalone/x11_standalone_glx_backend.cpp index ac75343da0..7e03926049 100644 --- a/src/backends/x11/standalone/x11_standalone_glx_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_glx_backend.cpp @@ -871,7 +871,7 @@ void GlxSurfaceTextureX11::update(const QRegion ®ion) } GlxPixmapTexture::GlxPixmapTexture(GlxBackend *backend) - : GLTexture(*new GlxPixmapTexturePrivate(this, backend)) + : GLTexture(std::make_unique(this, backend)) { } diff --git a/src/libkwineffects/kwingltexture.cpp b/src/libkwineffects/kwingltexture.cpp index 03b6e8f855..89ad1dcbaf 100644 --- a/src/libkwineffects/kwingltexture.cpp +++ b/src/libkwineffects/kwingltexture.cpp @@ -89,13 +89,8 @@ GLTexture::GLTexture(GLenum target) d->m_target = target; } -GLTexture::GLTexture(GLTexturePrivate &dd) - : d_ptr(&dd) -{ -} - -GLTexture::GLTexture(const GLTexture &tex) - : d_ptr(tex.d_ptr) +GLTexture::GLTexture(std::unique_ptr &&dd) + : d_ptr(std::move(dd)) { } @@ -271,12 +266,6 @@ bool GLTexture::create() return d->m_texture != GL_NONE; } -GLTexture &GLTexture::operator=(const GLTexture &tex) -{ - d_ptr = tex.d_ptr; - return *this; -} - GLTexturePrivate::GLTexturePrivate() : m_texture(0) , m_target(0) @@ -437,11 +426,6 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s } } -void GLTexture::discard() -{ - d_ptr = new GLTexturePrivate(); -} - void GLTexture::bind() { Q_D(GLTexture); diff --git a/src/libkwineffects/kwingltexture.h b/src/libkwineffects/kwingltexture.h index 559e4d2a26..d5dd339128 100644 --- a/src/libkwineffects/kwingltexture.h +++ b/src/libkwineffects/kwingltexture.h @@ -49,7 +49,6 @@ class KWINGLUTILS_EXPORT GLTexture { public: explicit GLTexture(GLenum target); - GLTexture(const GLTexture &tex); explicit GLTexture(const QImage &image, GLenum target = GL_TEXTURE_2D); explicit GLTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D); explicit GLTexture(const QString &fileName); @@ -71,8 +70,6 @@ public: explicit GLTexture(GLuint textureId, GLenum internalFormat, const QSize &size, int levels = 1); virtual ~GLTexture(); - GLTexture &operator=(const GLTexture &tex); - bool isNull() const; QSize size() const; void setSize(const QSize &size); @@ -114,7 +111,6 @@ public: QMatrix4x4 matrix(TextureCoordinateType type) const; void update(const QImage &image, const QPoint &offset = QPoint(0, 0), const QRect &src = QRect()); - virtual void discard(); void bind(); void unbind(); void render(const QSizeF &size, double scale); @@ -163,8 +159,8 @@ public: static bool supportsFormatRG(); protected: - QExplicitlySharedDataPointer d_ptr; - GLTexture(GLTexturePrivate &dd); + const std::unique_ptr d_ptr; + GLTexture(std::unique_ptr &&dd); private: Q_DECLARE_PRIVATE(GLTexture) diff --git a/src/plugins/backgroundcontrast/contrast.cpp b/src/plugins/backgroundcontrast/contrast.cpp index 306b9be5d3..8a9cd7434d 100644 --- a/src/plugins/backgroundcontrast/contrast.cpp +++ b/src/plugins/backgroundcontrast/contrast.cpp @@ -466,7 +466,6 @@ void ContrastEffect::doContrast(const RenderTarget &renderTarget, const RenderVi vbo->draw(GL_TRIANGLES, 0, actualShape.rectCount() * 6); scratch.unbind(); - scratch.discard(); vbo->unbindArrays();