summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAndy Nichols <andy.nichols@digia.com>2014-02-04 15:04:56 +0100
committerAndy Nichols <andy.nichols@digia.com>2014-02-04 15:04:56 +0100
commite5d1d051e413160e37e7b61d8d7ad74298f98a76 (patch)
tree804f966db6780b539ec90206017a1a79c006450b /examples
parent05076e4e16615741becfc434979502901cbf396a (diff)
parent50f43a0c56e4329facbba6b7e4bbec0e87ff9d63 (diff)
Merge remote-tracking branch 'origin/stable' into dev
Conflicts: src/client/hardwareintegration/qwaylandclientbufferintegrationplugin_p.h src/client/hardwareintegration/qwaylandserverbufferintegrationplugin_p.h src/compositor/hardware_integration/qwaylandclientbufferintegrationplugin.h src/compositor/hardware_integration/qwaylandserverbufferintegrationplugin.h src/plugins/hardwareintegration/client/brcm-egl/main.cpp src/plugins/hardwareintegration/client/drm-egl-server/main.cpp src/plugins/hardwareintegration/client/wayland-egl/main.cpp src/plugins/hardwareintegration/client/xcomposite-egl/main.cpp src/plugins/hardwareintegration/client/xcomposite-glx/main.cpp src/plugins/hardwareintegration/compositor/brcm-egl/main.cpp src/plugins/hardwareintegration/compositor/drm-egl-server/main.cpp src/plugins/hardwareintegration/compositor/wayland-egl/main.cpp src/plugins/hardwareintegration/compositor/xcomposite-egl/main.cpp src/plugins/hardwareintegration/compositor/xcomposite-glx/main.cpp Change-Id: I9a9b418075970dd334babc3590b9b0315c2afb0d
Diffstat (limited to 'examples')
-rw-r--r--examples/qwidget-compositor/main.cpp13
-rw-r--r--examples/qwindow-compositor/qwindowcompositor.cpp58
-rw-r--r--examples/qwindow-compositor/qwindowcompositor.h5
-rw-r--r--examples/server-buffer/client/client.pro2
4 files changed, 57 insertions, 21 deletions
diff --git a/examples/qwidget-compositor/main.cpp b/examples/qwidget-compositor/main.cpp
index 2c58fe98d..1badb06ac 100644
--- a/examples/qwidget-compositor/main.cpp
+++ b/examples/qwidget-compositor/main.cpp
@@ -139,6 +139,9 @@ protected:
GLuint texture = 0;
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
+ QSize windowSize = surface->size();
+ surface->advanceBufferQueue();
+
if (!m_surfaceCompositorFbo)
functions->glGenFramebuffers(1,&m_surfaceCompositorFbo);
@@ -152,7 +155,7 @@ protected:
functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, texture, 0);
- paintChildren(surface,surface);
+ paintChildren(surface,surface,windowSize);
functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, 0, 0);
@@ -160,7 +163,7 @@ protected:
return texture;
}
- void paintChildren(QWaylandSurface *surface, QWaylandSurface *window) {
+ void paintChildren(QWaylandSurface *surface, QWaylandSurface *window, const QSize &windowSize) {
if (surface->subSurfaces().size() == 0)
return;
@@ -170,6 +173,7 @@ protected:
QWaylandSurface *subSurface = i.next();
QPointF p = subSurface->mapTo(window,QPoint(0,0));
QSize size = subSurface->size();
+ subSurface->advanceBufferQueue();
if (size.isValid()) {
GLuint texture = 0;
if (subSurface->type() == QWaylandSurface::Texture) {
@@ -177,9 +181,9 @@ protected:
} else if (surface->type() == QWaylandSurface::Shm ) {
texture = m_textureCache->bindTexture(context()->contextHandle(), surface->image());
}
- m_textureBlitter->drawTexture(texture,QRect(p.toPoint(),size),window->size(),0,window->isYInverted(),subSurface->isYInverted());
+ m_textureBlitter->drawTexture(texture,QRect(p.toPoint(),size),windowSize,0,window->isYInverted(),subSurface->isYInverted());
}
- paintChildren(subSurface,window);
+ paintChildren(subSurface,window,windowSize);
}
}
#else //hmmm, this is actually untested :(
@@ -220,6 +224,7 @@ protected:
p.drawPixmap(rect(), m_backgroundScaled);
#ifdef QT_COMPOSITOR_WAYLAND_GL
+ cleanupGraphicsResources();
if (!m_textureCache) {
m_textureCache = new QOpenGLTextureCache(context()->contextHandle());
}
diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp
index 8e71ef069..19f7ce5ec 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,30 +237,48 @@ 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;
+ QSize windowSize = surface->size();
+ surface->advanceBufferQueue();
+
QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
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,
GL_TEXTURE_2D, texture, 0);
- paintChildren(surface,surface);
+ paintChildren(surface, surface,windowSize);
functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,0, 0);
functions->glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+
return texture;
}
-void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface *window) {
+void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface *window, const QSize &windowSize) {
if (surface->subSurfaces().size() == 0)
return;
@@ -269,17 +287,22 @@ void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface
while (i.hasNext()) {
QWaylandSurface *subSurface = i.next();
QPointF p = subSurface->mapTo(window,QPointF(0,0));
- if (subSurface->size().isValid()) {
+ QSize subSize = subSurface->size();
+ subSurface->advanceBufferQueue();
+ if (subSize.isValid()) {
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());
+ QRect geo(p.toPoint(),subSize);
+ if (texture > 0)
+ m_textureBlitter->drawTexture(texture,geo,windowSize,0,window->isYInverted(),subSurface->isYInverted());
+ if (surface->type() == QWaylandSurface::Shm)
+ glDeleteTextures(1, &texture);
}
- paintChildren(subSurface,window);
+ paintChildren(subSurface,window,windowSize);
}
}
@@ -287,7 +310,11 @@ void QWindowCompositor::paintChildren(QWaylandSurface *surface, QWaylandSurface
void QWindowCompositor::render()
{
m_window->makeCurrent();
- m_backgroundTexture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),m_backgroundImage);
+
+ cleanupGraphicsResources();
+
+ if (!m_backgroundTexture)
+ m_backgroundTexture = textureFromImage(m_backgroundImage);
m_textureBlitter->bind();
// Draw the background image texture
@@ -299,9 +326,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..c58c0d571 100644
--- a/examples/qwindow-compositor/qwindowcompositor.h
+++ b/examples/qwindow-compositor/qwindowcompositor.h
@@ -71,8 +71,8 @@ protected:
QWaylandSurface* surfaceAt(const QPointF &point, QPointF *local = 0);
- GLuint composeSurface(QWaylandSurface *surface);
- void paintChildren(QWaylandSurface *surface, QWaylandSurface *window);
+ GLuint composeSurface(QWaylandSurface *surface, bool *textureOwned);
+ void paintChildren(QWaylandSurface *surface, QWaylandSurface *window, const QSize &windowSize);
bool eventFilter(QObject *obj, QEvent *event);
@@ -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;
diff --git a/examples/server-buffer/client/client.pro b/examples/server-buffer/client/client.pro
index 1296ed186..ce4a04f91 100644
--- a/examples/server-buffer/client/client.pro
+++ b/examples/server-buffer/client/client.pro
@@ -3,6 +3,8 @@ TARGET = client
INCLUDEPATH += .
QT += waylandclient-private
+CONFIG += link_pkgconfig
+PKGCONFIG += wayland-client
CONFIG += wayland-scanner
WAYLANDCLIENTSOURCES += ../share-buffer.xml