diff options
-rw-r--r-- | examples/qwindow-compositor/qwindowcompositor.cpp | 35 | ||||
-rw-r--r-- | examples/qwindow-compositor/qwindowcompositor.h | 3 |
2 files changed, 28 insertions, 10 deletions
diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp index 8e71ef069..79d5b111b 100644 --- a/examples/qwindow-compositor/qwindowcompositor.cpp +++ b/examples/qwindow-compositor/qwindowcompositor.cpp @@ -56,6 +56,7 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window) : QWaylandCompositor(window, 0, DefaultExtensions | SubSurfaceExtension) , m_window(window) + , m_backgroundTexture(0) , m_textureBlitter(0) , m_renderScheduler(this) , m_draggingWindow(0) @@ -67,7 +68,6 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window) { m_window->makeCurrent(); - m_textureCache = new QOpenGLTextureCache(m_window->context()); m_textureBlitter = new TextureBlitter(); m_backgroundImage = makeBackgroundImage(QLatin1String(":/background.jpg")); m_renderScheduler.setSingleShot(true); @@ -86,8 +86,8 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window) QWindowCompositor::~QWindowCompositor() { + glDeleteTextures(1, &m_backgroundTexture); delete m_textureBlitter; - delete m_textureCache; } @@ -237,7 +237,18 @@ QWaylandSurface *QWindowCompositor::surfaceAt(const QPointF &point, QPointF *loc return 0; } -GLuint QWindowCompositor::composeSurface(QWaylandSurface *surface) +static GLuint textureFromImage(const QImage &image) +{ + GLuint texture = 0; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + QImage tx = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tx.width(), tx.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tx.constBits()); + glBindTexture(GL_TEXTURE_2D, 0); + return texture; +} + +GLuint QWindowCompositor::composeSurface(QWaylandSurface *surface, bool *textureOwned) { GLuint texture = 0; @@ -245,9 +256,11 @@ GLuint QWindowCompositor::composeSurface(QWaylandSurface *surface) functions->glBindFramebuffer(GL_FRAMEBUFFER, m_surface_fbo); if (surface->type() == QWaylandSurface::Shm) { - texture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image()); + texture = textureFromImage(surface->image()); + *textureOwned = true; } else if (surface->type() == QWaylandSurface::Texture) { texture = surface->texture(); + *textureOwned = false; } functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, @@ -273,11 +286,13 @@ void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface GLuint texture = 0; if (subSurface->type() == QWaylandSurface::Texture) { texture = subSurface->texture(); - } else if (surface->type() == QWaylandSurface::Shm ) { - texture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image()); + } else if (surface->type() == QWaylandSurface::Shm) { + texture = textureFromImage(subSurface->image()); } QRect geo(p.toPoint(),subSurface->size()); m_textureBlitter->drawTexture(texture,geo,window->size(),0,window->isYInverted(),subSurface->isYInverted()); + if (surface->type() == QWaylandSurface::Shm) + glDeleteTextures(1, &texture); } paintChildren(subSurface,window); } @@ -287,7 +302,8 @@ void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface void QWindowCompositor::render() { m_window->makeCurrent(); - m_backgroundTexture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),m_backgroundImage); + if (!m_backgroundTexture) + m_backgroundTexture = textureFromImage(m_backgroundImage); m_textureBlitter->bind(); // Draw the background image texture @@ -299,9 +315,12 @@ void QWindowCompositor::render() foreach (QWaylandSurface *surface, m_surfaces) { if (!surface->visible()) continue; - GLuint texture = composeSurface(surface); + bool ownsTexture; + GLuint texture = composeSurface(surface, &ownsTexture); QRect geo(surface->pos().toPoint(),surface->size()); m_textureBlitter->drawTexture(texture,geo,m_window->size(),0,false,surface->isYInverted()); + if (ownsTexture) + glDeleteTextures(1, &texture); } m_textureBlitter->release(); diff --git a/examples/qwindow-compositor/qwindowcompositor.h b/examples/qwindow-compositor/qwindowcompositor.h index 85da612a0..d09ffa893 100644 --- a/examples/qwindow-compositor/qwindowcompositor.h +++ b/examples/qwindow-compositor/qwindowcompositor.h @@ -71,7 +71,7 @@ protected: QWaylandSurface* surfaceAt(const QPointF &point, QPointF *local = 0); - GLuint composeSurface(QWaylandSurface *surface); + GLuint composeSurface(QWaylandSurface *surface, bool *textureOwned); void paintChildren(QWaylandSurface *surface, QWaylandSurface *window); @@ -93,7 +93,6 @@ private: GLuint m_backgroundTexture; QList<QWaylandSurface *> m_surfaces; TextureBlitter *m_textureBlitter; - QOpenGLTextureCache *m_textureCache; GLuint m_surface_fbo; QTimer m_renderScheduler; |