From 20b4f260458968eff9d5b27d9d3b4d23ae075734 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 15 May 2023 18:27:45 +0200 Subject: [PATCH] libkwineffects: simplify gltexture Instead of using custom private classes for taking care of backend specific stuff, store that directly in the GLTexture subclasses --- .../standalone/x11_standalone_egl_backend.cpp | 39 ++++------- .../standalone/x11_standalone_egl_backend.h | 17 +---- .../standalone/x11_standalone_glx_backend.cpp | 68 ++++++++----------- .../standalone/x11_standalone_glx_backend.h | 19 +----- src/libkwineffects/kwineglimagetexture.cpp | 2 +- src/libkwineffects/kwingltexture.cpp | 55 +++------------ src/libkwineffects/kwingltexture.h | 6 +- src/libkwineffects/kwingltexture_p.h | 2 - 8 files changed, 58 insertions(+), 150 deletions(-) diff --git a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp index 0e25a8c596..fd68944127 100644 --- a/src/backends/x11/standalone/x11_standalone_egl_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_egl_backend.cpp @@ -418,41 +418,29 @@ void EglSurfaceTextureX11::update(const QRegion ®ion) } EglPixmapTexture::EglPixmapTexture(EglBackend *backend) - : GLTexture(std::make_unique(this, backend)) -{ -} - -bool EglPixmapTexture::create(SurfacePixmapX11 *texture) -{ - Q_D(EglPixmapTexture); - return d->create(texture); -} - -EglPixmapTexturePrivate::EglPixmapTexturePrivate(EglPixmapTexture *texture, EglBackend *backend) - : q(texture) + : GLTexture(GL_TEXTURE_2D) , m_backend(backend) { - m_target = GL_TEXTURE_2D; } -EglPixmapTexturePrivate::~EglPixmapTexturePrivate() +EglPixmapTexture::~EglPixmapTexture() { if (m_image != EGL_NO_IMAGE_KHR) { eglDestroyImageKHR(m_backend->eglDisplay(), m_image); } } -bool EglPixmapTexturePrivate::create(SurfacePixmapX11 *pixmap) +bool EglPixmapTexture::create(SurfacePixmapX11 *pixmap) { const xcb_pixmap_t nativePixmap = pixmap->pixmap(); if (nativePixmap == XCB_NONE) { return false; } - glGenTextures(1, &m_texture); - q->setWrapMode(GL_CLAMP_TO_EDGE); - q->setFilter(GL_LINEAR); - q->bind(); + glGenTextures(1, &d->m_texture); + setWrapMode(GL_CLAMP_TO_EDGE); + setFilter(GL_LINEAR); + bind(); const EGLint attribs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; @@ -464,18 +452,18 @@ bool EglPixmapTexturePrivate::create(SurfacePixmapX11 *pixmap) if (EGL_NO_IMAGE_KHR == m_image) { qCDebug(KWIN_X11STANDALONE) << "failed to create egl image"; - q->unbind(); + unbind(); return false; } glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast(m_image)); - q->unbind(); - q->setContentTransform(TextureTransform::MirrorY); - m_size = pixmap->size(); - updateMatrix(); + unbind(); + setContentTransform(TextureTransform::MirrorY); + d->m_size = pixmap->size(); + d->updateMatrix(); return true; } -void EglPixmapTexturePrivate::onDamage() +void EglPixmapTexture::onDamage() { if (options->isGlStrictBinding()) { // This is just implemented to be consistent with @@ -483,7 +471,6 @@ void EglPixmapTexturePrivate::onDamage() eglWaitNative(EGL_CORE_NATIVE_ENGINE); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, static_cast(m_image)); } - GLTexturePrivate::onDamage(); } } // namespace KWin diff --git a/src/backends/x11/standalone/x11_standalone_egl_backend.h b/src/backends/x11/standalone/x11_standalone_egl_backend.h index 09b65f1e2d..3b65848223 100644 --- a/src/backends/x11/standalone/x11_standalone_egl_backend.h +++ b/src/backends/x11/standalone/x11_standalone_egl_backend.h @@ -78,27 +78,14 @@ class EglPixmapTexture : public GLTexture { public: explicit EglPixmapTexture(EglBackend *backend); + ~EglPixmapTexture() override; bool create(SurfacePixmapX11 *texture); private: - Q_DECLARE_PRIVATE(EglPixmapTexture) -}; - -class EglPixmapTexturePrivate : public GLTexturePrivate -{ -public: - EglPixmapTexturePrivate(EglPixmapTexture *texture, EglBackend *backend); - ~EglPixmapTexturePrivate() override; - - bool create(SurfacePixmapX11 *texture); - -protected: void onDamage() override; -private: - EglPixmapTexture *q; - EglBackend *m_backend; + EglBackend *const m_backend; EGLImageKHR m_image = EGL_NO_IMAGE_KHR; }; diff --git a/src/backends/x11/standalone/x11_standalone_glx_backend.cpp b/src/backends/x11/standalone/x11_standalone_glx_backend.cpp index 7e03926049..cea481aa55 100644 --- a/src/backends/x11/standalone/x11_standalone_glx_backend.cpp +++ b/src/backends/x11/standalone/x11_standalone_glx_backend.cpp @@ -871,24 +871,13 @@ void GlxSurfaceTextureX11::update(const QRegion ®ion) } GlxPixmapTexture::GlxPixmapTexture(GlxBackend *backend) - : GLTexture(std::make_unique(this, backend)) -{ -} - -bool GlxPixmapTexture::create(SurfacePixmapX11 *texture) -{ - Q_D(GlxPixmapTexture); - return d->create(texture); -} - -GlxPixmapTexturePrivate::GlxPixmapTexturePrivate(GlxPixmapTexture *texture, GlxBackend *backend) - : m_backend(backend) - , q(texture) + : GLTexture(GL_TEXTURE_2D) + , m_backend(backend) , m_glxPixmap(None) { } -GlxPixmapTexturePrivate::~GlxPixmapTexturePrivate() +GlxPixmapTexture::~GlxPixmapTexture() { if (m_glxPixmap != None) { if (!options->isGlStrictBinding()) { @@ -899,16 +888,7 @@ GlxPixmapTexturePrivate::~GlxPixmapTexturePrivate() } } -void GlxPixmapTexturePrivate::onDamage() -{ - if (options->isGlStrictBinding() && m_glxPixmap) { - glXReleaseTexImageEXT(m_backend->display(), m_glxPixmap, GLX_FRONT_LEFT_EXT); - glXBindTexImageEXT(m_backend->display(), m_glxPixmap, GLX_FRONT_LEFT_EXT, nullptr); - } - GLTexturePrivate::onDamage(); -} - -bool GlxPixmapTexturePrivate::create(SurfacePixmapX11 *texture) +bool GlxPixmapTexture::create(SurfacePixmapX11 *texture) { if (texture->pixmap() == XCB_NONE || texture->size().isEmpty() || texture->visual() == XCB_NONE) { return false; @@ -920,39 +900,47 @@ bool GlxPixmapTexturePrivate::create(SurfacePixmapX11 *texture) } if (info.texture_targets & GLX_TEXTURE_2D_BIT_EXT) { - m_target = GL_TEXTURE_2D; - m_scale.setWidth(1.0f / m_size.width()); - m_scale.setHeight(1.0f / m_size.height()); + d->m_target = GL_TEXTURE_2D; + d->m_scale.setWidth(1.0f / d->m_size.width()); + d->m_scale.setHeight(1.0f / d->m_size.height()); } else { Q_ASSERT(info.texture_targets & GLX_TEXTURE_RECTANGLE_BIT_EXT); - m_target = GL_TEXTURE_RECTANGLE; - m_scale.setWidth(1.0f); - m_scale.setHeight(1.0f); + d->m_target = GL_TEXTURE_RECTANGLE; + d->m_scale.setWidth(1.0f); + d->m_scale.setHeight(1.0f); } const int attrs[] = { GLX_TEXTURE_FORMAT_EXT, info.bind_texture_format, GLX_MIPMAP_TEXTURE_EXT, false, - GLX_TEXTURE_TARGET_EXT, m_target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT : GLX_TEXTURE_RECTANGLE_EXT, + GLX_TEXTURE_TARGET_EXT, d->m_target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT : GLX_TEXTURE_RECTANGLE_EXT, 0}; m_glxPixmap = glXCreatePixmap(m_backend->display(), info.fbconfig, texture->pixmap(), attrs); - m_size = texture->size(); - q->setContentTransform(info.y_inverted ? TextureTransform::MirrorY : TextureTransforms()); - m_canUseMipmaps = false; + d->m_size = texture->size(); + setContentTransform(info.y_inverted ? TextureTransform::MirrorY : TextureTransforms()); + d->m_canUseMipmaps = false; - glGenTextures(1, &m_texture); + glGenTextures(1, &d->m_texture); - q->setDirty(); - q->setFilter(GL_LINEAR); - q->setWrapMode(GL_CLAMP_TO_EDGE); + setDirty(); + setFilter(GL_LINEAR); + setWrapMode(GL_CLAMP_TO_EDGE); - glBindTexture(m_target, m_texture); + glBindTexture(d->m_target, d->m_texture); glXBindTexImageEXT(m_backend->display(), m_glxPixmap, GLX_FRONT_LEFT_EXT, nullptr); - updateMatrix(); + d->updateMatrix(); return true; } +void GlxPixmapTexture::onDamage() +{ + if (options->isGlStrictBinding() && m_glxPixmap) { + glXReleaseTexImageEXT(m_backend->display(), m_glxPixmap, GLX_FRONT_LEFT_EXT); + glXBindTexImageEXT(m_backend->display(), m_glxPixmap, GLX_FRONT_LEFT_EXT, nullptr); + } +} + } // namespace diff --git a/src/backends/x11/standalone/x11_standalone_glx_backend.h b/src/backends/x11/standalone/x11_standalone_glx_backend.h index 5bbbc85c06..556314531f 100644 --- a/src/backends/x11/standalone/x11_standalone_glx_backend.h +++ b/src/backends/x11/standalone/x11_standalone_glx_backend.h @@ -134,34 +134,21 @@ private: X11StandaloneBackend *m_backend; std::unique_ptr m_vsyncMonitor; std::unique_ptr m_layer; - friend class GlxPixmapTexturePrivate; + friend class GlxPixmapTexture; }; class GlxPixmapTexture final : public GLTexture { public: explicit GlxPixmapTexture(GlxBackend *backend); + ~GlxPixmapTexture(); bool create(SurfacePixmapX11 *texture); private: - Q_DECLARE_PRIVATE(GlxPixmapTexture) -}; - -class GlxPixmapTexturePrivate final : public GLTexturePrivate -{ -public: - GlxPixmapTexturePrivate(GlxPixmapTexture *texture, GlxBackend *backend); - ~GlxPixmapTexturePrivate() override; - - bool create(SurfacePixmapX11 *texture); - -protected: void onDamage() override; -private: - GlxBackend *m_backend; - GlxPixmapTexture *q; + GlxBackend *const m_backend; GLXPixmap m_glxPixmap; }; diff --git a/src/libkwineffects/kwineglimagetexture.cpp b/src/libkwineffects/kwineglimagetexture.cpp index 86ec9097c3..97c0c8abd2 100644 --- a/src/libkwineffects/kwineglimagetexture.cpp +++ b/src/libkwineffects/kwineglimagetexture.cpp @@ -21,7 +21,7 @@ EGLImageTexture::EGLImageTexture(::EGLDisplay display, EGLImage image, uint text , m_image(image) , m_display(display) { - d_ptr->m_foreign = false; + d->m_foreign = false; setContentTransform(TextureTransform::MirrorY); } diff --git a/src/libkwineffects/kwingltexture.cpp b/src/libkwineffects/kwingltexture.cpp index 26e0cb1f97..321129fb5f 100644 --- a/src/libkwineffects/kwingltexture.cpp +++ b/src/libkwineffects/kwingltexture.cpp @@ -83,24 +83,16 @@ struct }; GLTexture::GLTexture(GLenum target) - : d_ptr(new GLTexturePrivate()) + : d(std::make_unique()) { - Q_D(GLTexture); d->m_target = target; } -GLTexture::GLTexture(std::unique_ptr &&dd) - : d_ptr(std::move(dd)) -{ -} - GLTexture::GLTexture(GLuint textureId, GLenum internalFormat, const QSize &size, int levels, bool isImmutable) - : d_ptr(new GLTexturePrivate()) + : GLTexture(GL_TEXTURE_2D) { - Q_D(GLTexture); d->m_foreign = true; d->m_texture = textureId; - d->m_target = GL_TEXTURE_2D; d->m_scale.setWidth(1.0 / size.width()); d->m_scale.setHeight(1.0 / size.height()); d->m_size = size; @@ -119,7 +111,6 @@ GLTexture::~GLTexture() bool GLTexture::create() { - Q_D(GLTexture); if (!isNull()) { return true; } @@ -191,19 +182,16 @@ void GLTexturePrivate::cleanup() bool GLTexture::isNull() const { - Q_D(const GLTexture); return GL_NONE == d->m_texture; } QSize GLTexture::size() const { - Q_D(const GLTexture); return d->m_size; } void GLTexture::setSize(const QSize &size) { - Q_D(GLTexture); if (!isNull()) { return; } @@ -217,7 +205,6 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s return; } - Q_D(GLTexture); Q_ASSERT(!d->m_foreign); GLenum glFormat; @@ -289,13 +276,12 @@ void GLTexture::update(const QImage &image, const QPoint &offset, const QRect &s void GLTexture::bind() { - Q_D(GLTexture); Q_ASSERT(d->m_texture); glBindTexture(d->m_target, d->m_texture); if (d->m_markedDirty) { - d->onDamage(); + onDamage(); } if (d->m_filterChanged) { GLenum minFilter = GL_NEAREST; @@ -337,8 +323,6 @@ void GLTexture::bind() void GLTexture::generateMipmaps() { - Q_D(GLTexture); - if (d->m_canUseMipmaps && d->s_supportsFramebufferObjects) { glGenerateMipmap(d->m_target); } @@ -346,7 +330,6 @@ void GLTexture::generateMipmaps() void GLTexture::unbind() { - Q_D(GLTexture); glBindTexture(d->m_target, 0); } @@ -357,14 +340,12 @@ void GLTexture::render(const QSizeF &size, qreal scale) void GLTexture::render(const QRegion ®ion, const QSizeF &targetSize, double scale, bool hardwareClipping) { - Q_D(GLTexture); const auto rotatedSize = d->m_textureToBufferMatrix.mapRect(QRect(QPoint(), size())).size(); render(QRectF(QPoint(), rotatedSize), region, targetSize, scale, hardwareClipping); } void GLTexture::render(const QRectF &source, const QRegion ®ion, const QSizeF &targetSize, double scale, bool hardwareClipping) { - Q_D(GLTexture); if (targetSize.isEmpty()) { return; // nothing to paint and m_vbo is likely nullptr and d->m_cachedSize empty as well, #337090 } @@ -416,31 +397,26 @@ void GLTexture::render(const QRectF &source, const QRegion ®ion, const QSizeF GLuint GLTexture::texture() const { - Q_D(const GLTexture); return d->m_texture; } GLenum GLTexture::target() const { - Q_D(const GLTexture); return d->m_target; } GLenum GLTexture::filter() const { - Q_D(const GLTexture); return d->m_filter; } GLenum GLTexture::internalFormat() const { - Q_D(const GLTexture); return d->m_internalFormat; } void GLTexture::clear() { - Q_D(GLTexture); Q_ASSERT(!d->m_foreign); if (!GLTexturePrivate::s_fbo && GLFramebuffer::supported() && GLPlatform::instance()->driver() != Driver_Catalyst) { // fail. -> bug #323065 glGenFramebuffers(1, &GLTexturePrivate::s_fbo); @@ -478,13 +454,11 @@ void GLTexture::clear() bool GLTexture::isDirty() const { - Q_D(const GLTexture); return d->m_markedDirty; } void GLTexture::setFilter(GLenum filter) { - Q_D(GLTexture); if (filter != d->m_filter) { d->m_filter = filter; d->m_filterChanged = true; @@ -493,24 +467,21 @@ void GLTexture::setFilter(GLenum filter) void GLTexture::setWrapMode(GLenum mode) { - Q_D(GLTexture); if (mode != d->m_wrapMode) { d->m_wrapMode = mode; d->m_wrapModeChanged = true; } } -void GLTexturePrivate::onDamage() -{ - // No-op -} - void GLTexture::setDirty() { - Q_D(GLTexture); d->m_markedDirty = true; } +void GLTexture::onDamage() +{ +} + void GLTexturePrivate::updateMatrix() { m_textureToBufferMatrix.setToIdentity(); @@ -551,7 +522,6 @@ void GLTexturePrivate::updateMatrix() void GLTexture::setContentTransform(TextureTransforms transform) { - Q_D(GLTexture); if (d->m_textureToBufferTransform != transform) { d->m_textureToBufferTransform = transform; d->updateMatrix(); @@ -560,20 +530,16 @@ void GLTexture::setContentTransform(TextureTransforms transform) TextureTransforms GLTexture::contentTransforms() const { - Q_D(const GLTexture); return d->m_textureToBufferTransform; } QMatrix4x4 GLTexture::contentTransformMatrix() const { - Q_D(const GLTexture); return d->m_textureToBufferMatrix; } void GLTexture::setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha) { - Q_D(GLTexture); - if (!GLPlatform::instance()->isGLES()) { const GLuint swizzle[] = {red, green, blue, alpha}; glTexParameteriv(d->m_target, GL_TEXTURE_SWIZZLE_RGBA, (const GLint *)swizzle); @@ -587,19 +553,16 @@ void GLTexture::setSwizzle(GLenum red, GLenum green, GLenum blue, GLenum alpha) int GLTexture::width() const { - Q_D(const GLTexture); return d->m_size.width(); } int GLTexture::height() const { - Q_D(const GLTexture); return d->m_size.height(); } QMatrix4x4 GLTexture::matrix(TextureCoordinateType type) const { - Q_D(const GLTexture); return d->m_matrix[type]; } @@ -672,7 +635,7 @@ std::unique_ptr GLTexture::allocate(GLenum internalFormat, const QSiz } glBindTexture(GL_TEXTURE_2D, 0); auto ret = std::make_unique(texture, internalFormat, size, levels, immutable); - ret->d_ptr->m_foreign = false; + ret->d->m_foreign = false; return ret; } @@ -737,7 +700,7 @@ std::unique_ptr GLTexture::upload(const QImage &image) glBindTexture(GL_TEXTURE_2D, 0); auto ret = std::make_unique(texture, internalFormat, image.size(), 1, immutable); ret->setContentTransform(TextureTransform::MirrorY); - ret->d_ptr->m_foreign = false; + ret->d->m_foreign = false; return ret; } diff --git a/src/libkwineffects/kwingltexture.h b/src/libkwineffects/kwingltexture.h index 6124f87787..4e4868b868 100644 --- a/src/libkwineffects/kwingltexture.h +++ b/src/libkwineffects/kwingltexture.h @@ -158,11 +158,9 @@ public: static std::unique_ptr upload(const QPixmap &pixmap); protected: - const std::unique_ptr d_ptr; - GLTexture(std::unique_ptr &&dd); + const std::unique_ptr d; -private: - Q_DECLARE_PRIVATE(GLTexture) + virtual void onDamage(); }; } // namespace diff --git a/src/libkwineffects/kwingltexture_p.h b/src/libkwineffects/kwingltexture_p.h index 5c907a33f2..e9834b0b6c 100644 --- a/src/libkwineffects/kwingltexture_p.h +++ b/src/libkwineffects/kwingltexture_p.h @@ -33,8 +33,6 @@ public: GLTexturePrivate(); virtual ~GLTexturePrivate(); - virtual void onDamage(); - void updateMatrix(); GLuint m_texture;