File indexing completed on 2024-05-19 16:35:16

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "clientbuffer.h"
0008 #include "clientbuffer_p.h"
0009 
0010 #include "qwayland-server-wayland.h"
0011 
0012 namespace KWaylandServer
0013 {
0014 ClientBuffer::ClientBuffer(ClientBufferPrivate &dd)
0015     : d_ptr(&dd)
0016 {
0017 }
0018 
0019 ClientBuffer::ClientBuffer(wl_resource *resource, ClientBufferPrivate &dd)
0020     : d_ptr(&dd)
0021 {
0022     initialize(resource);
0023 }
0024 
0025 ClientBuffer::~ClientBuffer()
0026 {
0027 }
0028 
0029 void ClientBuffer::initialize(wl_resource *resource)
0030 {
0031     Q_D(ClientBuffer);
0032     d->resource = resource;
0033 }
0034 
0035 wl_resource *ClientBuffer::resource() const
0036 {
0037     Q_D(const ClientBuffer);
0038     return d->resource;
0039 }
0040 
0041 bool ClientBuffer::isReferenced() const
0042 {
0043     Q_D(const ClientBuffer);
0044     return d->refCount > 0;
0045 }
0046 
0047 bool ClientBuffer::isDestroyed() const
0048 {
0049     Q_D(const ClientBuffer);
0050     return d->isDestroyed;
0051 }
0052 
0053 void ClientBuffer::ref()
0054 {
0055     Q_D(ClientBuffer);
0056     d->refCount++;
0057 }
0058 
0059 void ClientBuffer::unref()
0060 {
0061     Q_D(ClientBuffer);
0062     Q_ASSERT(d->refCount > 0);
0063     --d->refCount;
0064     if (!isReferenced()) {
0065         if (isDestroyed()) {
0066             delete this;
0067         } else {
0068             wl_buffer_send_release(d->resource);
0069         }
0070     }
0071 }
0072 
0073 void ClientBuffer::markAsDestroyed()
0074 {
0075     Q_D(ClientBuffer);
0076     if (!isReferenced()) {
0077         delete this;
0078     } else {
0079         d->resource = nullptr;
0080         d->isDestroyed = true;
0081     }
0082 }
0083 
0084 } // namespace KWaylandServer