diff options
author | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-07-29 14:58:54 +0200 |
---|---|---|
committer | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-08-28 13:09:41 +0200 |
commit | a327ca8d8a1f6e0a44a3aa6bd4dac716911c434e (patch) | |
tree | ae4c432c495a7baee8f97737160836cbb2e38476 /src/compositor/compositor_api/qwaylandbufferref.cpp | |
parent | 6c9c54587c6cd1059d5de652d06e248456832ab6 (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/qwaylandbufferref.cpp')
-rw-r--r-- | src/compositor/compositor_api/qwaylandbufferref.cpp | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/src/compositor/compositor_api/qwaylandbufferref.cpp b/src/compositor/compositor_api/qwaylandbufferref.cpp index 8a0b9242c..7b5b3cd2b 100644 --- a/src/compositor/compositor_api/qwaylandbufferref.cpp +++ b/src/compositor/compositor_api/qwaylandbufferref.cpp @@ -46,6 +46,10 @@ class QWaylandBufferRefPrivate { public: QtWayland::SurfaceBuffer *buffer; + + bool nullOrDestroyed() { + return !buffer || buffer->isDestroyed(); + } }; QWaylandBufferRef::QWaylandBufferRef() @@ -65,8 +69,9 @@ QWaylandBufferRef::QWaylandBufferRef(QtWayland::SurfaceBuffer *buffer) QWaylandBufferRef::QWaylandBufferRef(const QWaylandBufferRef &ref) : d(new QWaylandBufferRefPrivate) { - d->buffer = 0; - *this = ref; + d->buffer = ref.d->buffer; + if (d->buffer) + d->buffer->ref(); } QWaylandBufferRef::~QWaylandBufferRef() @@ -88,44 +93,75 @@ QWaylandBufferRef &QWaylandBufferRef::operator=(const QWaylandBufferRef &ref) return *this; } -QWaylandBufferRef::operator bool() const +bool QWaylandBufferRef::operator==(const QWaylandBufferRef &ref) { - return d->buffer && d->buffer->waylandBufferHandle(); + return d->buffer == ref.d->buffer; } -bool QWaylandBufferRef::isShm() const +bool QWaylandBufferRef::operator!=(const QWaylandBufferRef &ref) { - return d->buffer->isShmBuffer(); + return d->buffer != ref.d->buffer; } -QImage QWaylandBufferRef::image() const +bool QWaylandBufferRef::isNull() const { - if (d->buffer->isShmBuffer()) - return d->buffer->image(); - return QImage(); + return !d->buffer; } -#ifdef QT_COMPOSITOR_WAYLAND_GL +bool QWaylandBufferRef::hasBuffer() const +{ + return d->buffer && !d->buffer->isDestroyed(); +} -GLuint QWaylandBufferRef::createTexture() +struct ::wl_resource *QWaylandBufferRef::wl_buffer() const { - if (!d->buffer->isShmBuffer() && !d->buffer->textureCreated()) { - d->buffer->createTexture(); - } - return d->buffer->texture(); + return d->buffer ? d->buffer->waylandBufferHandle() : Q_NULLPTR; } -void QWaylandBufferRef::destroyTexture() +QSize QWaylandBufferRef::size() const { - if (!d->buffer->isShmBuffer() && d->buffer->textureCreated()) { - d->buffer->destroyTexture(); - } + if (d->nullOrDestroyed()) + return QSize(); + + return d->buffer->size(); +} + +QWaylandSurface::Origin QWaylandBufferRef::origin() const +{ + if (d->nullOrDestroyed()) + return QWaylandSurface::OriginBottomLeft; + + return d->buffer->origin(); +} + +bool QWaylandBufferRef::isShm() const +{ + if (d->nullOrDestroyed()) + return false; + + return d->buffer->isShm(); +} + +QImage QWaylandBufferRef::image() const +{ + if (d->nullOrDestroyed()) + return QImage(); + + return d->buffer->image(); +} + +void QWaylandBufferRef::bindToTexture() const +{ + if (d->nullOrDestroyed()) + return; + + return d->buffer->bindToTexture(); + } void *QWaylandBufferRef::nativeBuffer() const { return d->buffer->handle(); } -#endif QT_END_NAMESPACE |