summaryrefslogtreecommitdiffstats
path: root/src/compositor/compositor_api/qwaylandquicksurface.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@theqtcompany.com>2015-07-29 14:58:54 +0200
committerJørgen Lind <jorgen.lind@theqtcompany.com>2015-08-28 13:09:41 +0200
commita327ca8d8a1f6e0a44a3aa6bd4dac716911c434e (patch)
treeae4c432c495a7baee8f97737160836cbb2e38476 /src/compositor/compositor_api/qwaylandquicksurface.cpp
parent6c9c54587c6cd1059d5de652d06e248456832ab6 (diff)
Move the texture ownership from the QWaylandSurface
to the respective QWaylandSurfaceView. For all GL applications this will have no significant impact, but will cause a memory regression for shm surfaces with multiple views. This is done to simplify the creation and destruction of textures, especially in multi-threaded environments. Also the same patch removes the y_inverted property and replaces it with a origin property. Its done in the same patch as a lot of the code was overlapping. Change-Id: I4bce50c614c9ac3ba0580e0560339476eac03433
Diffstat (limited to 'src/compositor/compositor_api/qwaylandquicksurface.cpp')
-rw-r--r--src/compositor/compositor_api/qwaylandquicksurface.cpp109
1 files changed, 5 insertions, 104 deletions
diff --git a/src/compositor/compositor_api/qwaylandquicksurface.cpp b/src/compositor/compositor_api/qwaylandquicksurface.cpp
index a55569da9..ebefb3bc3 100644
--- a/src/compositor/compositor_api/qwaylandquicksurface.cpp
+++ b/src/compositor/compositor_api/qwaylandquicksurface.cpp
@@ -49,96 +49,21 @@
QT_BEGIN_NAMESPACE
-class BufferAttacher : public QWaylandBufferAttacher
-{
-public:
- BufferAttacher()
- : surface(0)
- , texture(0)
- , update(false)
- {
-
- }
-
- ~BufferAttacher()
- {
- if (texture)
- texture->deleteLater();
- bufferRef = QWaylandBufferRef();
- nextBuffer = QWaylandBufferRef();
- }
-
- void attach(const QWaylandBufferRef &ref) Q_DECL_OVERRIDE
- {
- nextBuffer = ref;
- update = true;
- }
-
- void createTexture()
- {
- bufferRef = nextBuffer;
- delete texture;
- texture = 0;
-
- QQuickWindow *window = static_cast<QQuickWindow *>(surface->mainOutput()->window());
- if (nextBuffer) {
- if (bufferRef.isShm()) {
- texture = window->createTextureFromImage(bufferRef.image());
- } else {
- QQuickWindow::CreateTextureOptions opt = 0;
- if (surface->useTextureAlpha()) {
- opt |= QQuickWindow::TextureHasAlphaChannel;
- }
- texture = window->createTextureFromId(bufferRef.createTexture(), surface->size(), opt);
- }
- texture->bind();
- }
-
- update = false;
- }
-
- void unmap() Q_DECL_OVERRIDE
- {
- nextBuffer = QWaylandBufferRef();
- update = true;
- }
-
- void invalidateTexture()
- {
- if (bufferRef)
- bufferRef.destroyTexture();
- delete texture;
- texture = 0;
- update = true;
- bufferRef = QWaylandBufferRef();
- }
-
- QWaylandQuickSurface *surface;
- QWaylandBufferRef bufferRef;
- QWaylandBufferRef nextBuffer;
- QSGTexture *texture;
- bool update;
-};
-
-
class QWaylandQuickSurfacePrivate : public QWaylandSurfacePrivate
{
public:
QWaylandQuickSurfacePrivate(wl_client *client, quint32 id, int version, QWaylandQuickCompositor *c, QWaylandQuickSurface *surf)
: QWaylandSurfacePrivate(client, id, version, c, surf)
- , buffer(new BufferAttacher)
, compositor(c)
, useTextureAlpha(true)
, windowPropertyMap(new QQmlPropertyMap)
, clientRenderingEnabled(true)
{
-
}
~QWaylandQuickSurfacePrivate()
{
windowPropertyMap->deleteLater();
- // buffer is deleted automatically by ~Surface(), since it is the assigned attacher
}
void surface_commit(Resource *resource) Q_DECL_OVERRIDE
@@ -149,7 +74,6 @@ public:
output->waylandOutput()->update();
}
- BufferAttacher *buffer;
QWaylandQuickCompositor *compositor;
bool useTextureAlpha;
QQmlPropertyMap *windowPropertyMap;
@@ -160,8 +84,10 @@ QWaylandQuickSurface::QWaylandQuickSurface(wl_client *client, quint32 id, int ve
: QWaylandSurface(new QWaylandQuickSurfacePrivate(client, id, version, compositor, this))
{
Q_D(QWaylandQuickSurface);
- d->buffer->surface = this;
- setBufferAttacher(d->buffer);
+ connect(this, &QWaylandSurface::shellViewCreated, this, &QWaylandQuickSurface::shellViewCreated);
+ connect(this, &QWaylandSurface::outputChanged, this, &QWaylandQuickSurface::outputWindowChanged);
+ connect(this, &QWaylandSurface::windowPropertyChanged, d->windowPropertyMap, &QQmlPropertyMap::insert);
+ connect(d->windowPropertyMap, &QQmlPropertyMap::valueChanged, this, &QWaylandSurface::setWindowProperty);
connect(this, &QWaylandSurface::windowPropertyChanged, d->windowPropertyMap, &QQmlPropertyMap::insert);
connect(d->windowPropertyMap, &QQmlPropertyMap::valueChanged, this, &QWaylandSurface::setWindowProperty);
@@ -173,12 +99,6 @@ QWaylandQuickSurface::~QWaylandQuickSurface()
}
-QSGTexture *QWaylandQuickSurface::texture() const
-{
- Q_D(const QWaylandQuickSurface);
- return d->buffer->texture;
-}
-
bool QWaylandQuickSurface::useTextureAlpha() const
{
Q_D(const QWaylandQuickSurface);
@@ -191,7 +111,7 @@ void QWaylandQuickSurface::setUseTextureAlpha(bool useTextureAlpha)
if (d->useTextureAlpha != useTextureAlpha) {
d->useTextureAlpha = useTextureAlpha;
emit useTextureAlphaChanged();
- emit configure(d->buffer->bufferRef);
+ emit configure(handle()->currentBufferRef().hasBuffer());
}
}
@@ -251,25 +171,6 @@ bool QWaylandQuickSurface::event(QEvent *e)
return QObject::event(e);
}
-void QWaylandQuickSurface::updateTexture()
-{
- Q_D(QWaylandQuickSurface);
- const bool update = d->buffer->update;
- if (d->buffer->update)
- d->buffer->createTexture();
- foreach (QWaylandSurfaceView *view, views())
- static_cast<QWaylandSurfaceItem *>(view)->updateTexture(update);
-}
-
-void QWaylandQuickSurface::invalidateTexture()
-{
- Q_D(QWaylandQuickSurface);
- d->buffer->invalidateTexture();
- foreach (QWaylandSurfaceView *view, views())
- static_cast<QWaylandSurfaceItem *>(view)->updateTexture(true);
- emit redraw();
-}
-
bool QWaylandQuickSurface::clientRenderingEnabled() const
{
Q_D(const QWaylandQuickSurface);