diff options
Diffstat (limited to 'src/compositor/compositor_api/qwaylandbufferref.cpp')
-rw-r--r-- | src/compositor/compositor_api/qwaylandbufferref.cpp | 193 |
1 files changed, 151 insertions, 42 deletions
diff --git a/src/compositor/compositor_api/qwaylandbufferref.cpp b/src/compositor/compositor_api/qwaylandbufferref.cpp index 68e52317b..d0fe7ca40 100644 --- a/src/compositor/compositor_api/qwaylandbufferref.cpp +++ b/src/compositor/compositor_api/qwaylandbufferref.cpp @@ -3,9 +3,9 @@ ** Copyright (C) 2014 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> ** Contact: http://www.qt.io/licensing/ ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL3$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the @@ -16,16 +16,19 @@ ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. ** ** $QT_END_LICENSE$ ** @@ -43,14 +46,33 @@ class QWaylandBufferRefPrivate { public: QtWayland::SurfaceBuffer *buffer; + + bool nullOrDestroyed() { + return !buffer || buffer->isDestroyed(); + } }; +/*! + * \class QWaylandBufferRef + * \inmodule QtWaylandCompositor + * \brief A class which holds a reference to a surface buffer + * + * This class can be used to reference a surface buffer. As long as a reference + * to the buffer exists, it is owned by the compositor and the client cannot modify it. + */ + +/*! + * Constructs a null buffer ref. + */ QWaylandBufferRef::QWaylandBufferRef() : d(new QWaylandBufferRefPrivate) { d->buffer = 0; } +/*! + * Constructs a reference to \a buffer. + */ QWaylandBufferRef::QWaylandBufferRef(QtWayland::SurfaceBuffer *buffer) : d(new QWaylandBufferRefPrivate) { @@ -59,13 +81,20 @@ QWaylandBufferRef::QWaylandBufferRef(QtWayland::SurfaceBuffer *buffer) buffer->ref(); } +/*! + * Creates a new reference to the buffer referenced by \a ref. + */ QWaylandBufferRef::QWaylandBufferRef(const QWaylandBufferRef &ref) : d(new QWaylandBufferRefPrivate) { - d->buffer = 0; - *this = ref; + d->buffer = ref.d->buffer; + if (d->buffer) + d->buffer->ref(); } +/*! + * Dereferences the buffer. + */ QWaylandBufferRef::~QWaylandBufferRef() { if (d->buffer) @@ -73,6 +102,10 @@ QWaylandBufferRef::~QWaylandBufferRef() delete d; } +/*! + * Assigns \a ref to this buffer. The previously referenced buffer is + * dereferenced and the new one gets a new reference. + */ QWaylandBufferRef &QWaylandBufferRef::operator=(const QWaylandBufferRef &ref) { if (d->buffer) @@ -85,61 +118,137 @@ QWaylandBufferRef &QWaylandBufferRef::operator=(const QWaylandBufferRef &ref) return *this; } -QWaylandBufferRef::operator bool() const +/*! + * Returns true if this QWaylandBufferRef references the same buffer as \a ref. + * Otherwise returns false. + */ +bool QWaylandBufferRef::operator==(const QWaylandBufferRef &ref) { - return d->buffer && d->buffer->waylandBufferHandle(); + return d->buffer == ref.d->buffer; } -bool QWaylandBufferRef::isShm() const +/*! + * Returns false if this QWaylandBufferRef references the same buffer as \a ref. + * Otherwise returns true. + */ +bool QWaylandBufferRef::operator!=(const QWaylandBufferRef &ref) { - return d->buffer->isShmBuffer(); + return d->buffer != ref.d->buffer; } -QImage QWaylandBufferRef::image() const +/*! + * Returns true if this QWaylandBufferRef does not reference a buffer. + * Otherwise returns false. + * + * \sa hasBuffer() + */ +bool QWaylandBufferRef::isNull() const { - if (d->buffer->isShmBuffer()) - return d->buffer->image(); - return QImage(); + return !d->buffer; } -void *QWaylandBufferRef::waylandBuffer() const +/*! + * Returns true if this QWaylandBufferRef references a buffer. Otherwise returns false. + * + * \sa isNull() + */ +bool QWaylandBufferRef::hasBuffer() const { - return d->buffer->waylandBufferHandle(); + return d->buffer; } -#ifdef QT_COMPOSITOR_WAYLAND_GL +/*! + * Returns true if this QWaylandBufferRef references a buffer that + * has been destroyed. Otherwise returns false. + */ +bool QWaylandBufferRef::isDestroyed() const +{ + return d->buffer && d->buffer->isDestroyed(); +} -GLenum QWaylandBufferRef::textureTarget() const +/*! + * Returns the Wayland resource for the buffer. + */ +struct ::wl_resource *QWaylandBufferRef::wl_buffer() const { - Q_ASSERT(d->buffer->textureCreated()); - return d->buffer->textureTarget(); + return d->buffer ? d->buffer->waylandBufferHandle() : Q_NULLPTR; } -GLuint QWaylandBufferRef::createTexture() +/*! + * Returns the size of the buffer. + * If the buffer referenced is null, an invalid QSize() is returned. + */ +QSize QWaylandBufferRef::size() const { - if (!d->buffer->isShmBuffer() && !d->buffer->textureCreated()) { - d->buffer->createTexture(); - } - return d->buffer->texture(); + if (d->nullOrDestroyed()) + return QSize(); + + return d->buffer->size(); } -void QWaylandBufferRef::updateTexture() +/*! + * Returns the origin of the buffer. + * If the buffer referenced is null, QWaylandSurface::OriginBottomLeft + * is returned. + */ +QWaylandSurface::Origin QWaylandBufferRef::origin() const { - if (!d->buffer->isShmBuffer() && d->buffer->textureCreated()) - d->buffer->updateTexture(); + if (d->buffer) + return d->buffer->origin(); + + return QWaylandSurface::OriginBottomLeft; } -void QWaylandBufferRef::destroyTexture() +/*! + * Returns true if the buffer is a shared memory buffer. Otherwise returns false. + */ +bool QWaylandBufferRef::isShm() const { - if (!d->buffer->isShmBuffer() && d->buffer->textureCreated()) { - d->buffer->destroyTexture(); - } + if (d->nullOrDestroyed()) + return false; + + return d->buffer->isShm(); } -void *QWaylandBufferRef::nativeBuffer() const +/*! + * Returns an image with the contents of the buffer. + */ +QImage QWaylandBufferRef::image() const { - return d->buffer->handle(); + if (d->nullOrDestroyed()) + return QImage(); + + return d->buffer->image(); +} + +/*! + * Binds the buffer to the current OpenGL texture. This may + * perform a copy of the buffer data, depending on the platform + * and the type of the buffer. + */ +void QWaylandBufferRef::bindToTexture() const +{ + if (d->nullOrDestroyed()) + return; + + return d->buffer->bindToTexture(); + +} + +int QWaylandBufferRef::textureTarget() const +{ + if (d->nullOrDestroyed()) + return 0x0DE1; // GL_TEXTURE_2D + + return d->buffer->textureTarget(); +} + +void QWaylandBufferRef::updateTexture() const +{ + if (d->nullOrDestroyed() || d->buffer->isShm()) + return; + + d->buffer->updateTexture(); } -#endif QT_END_NAMESPACE |