File indexing completed on 2024-05-12 05:31:21

0001 /*
0002     SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "core/graphicsbuffer.h"
0008 #include "utils/drm_format_helper.h"
0009 
0010 #include <drm_fourcc.h>
0011 
0012 namespace KWin
0013 {
0014 
0015 GraphicsBuffer::GraphicsBuffer(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 bool GraphicsBuffer::isReferenced() const
0021 {
0022     return m_refCount > 0;
0023 }
0024 
0025 bool GraphicsBuffer::isDropped() const
0026 {
0027     return m_dropped;
0028 }
0029 
0030 void GraphicsBuffer::ref()
0031 {
0032     ++m_refCount;
0033 }
0034 
0035 void GraphicsBuffer::unref()
0036 {
0037     Q_ASSERT(m_refCount > 0);
0038     --m_refCount;
0039     if (!m_refCount) {
0040         if (m_dropped) {
0041             delete this;
0042         } else {
0043             Q_EMIT released();
0044         }
0045     }
0046 }
0047 
0048 void GraphicsBuffer::drop()
0049 {
0050     m_dropped = true;
0051 
0052     if (!m_refCount) {
0053         delete this;
0054     }
0055 }
0056 
0057 GraphicsBuffer::Map GraphicsBuffer::map(MapFlags flags)
0058 {
0059     return {};
0060 }
0061 
0062 void GraphicsBuffer::unmap()
0063 {
0064 }
0065 
0066 const DmaBufAttributes *GraphicsBuffer::dmabufAttributes() const
0067 {
0068     return nullptr;
0069 }
0070 
0071 const ShmAttributes *GraphicsBuffer::shmAttributes() const
0072 {
0073     return nullptr;
0074 }
0075 
0076 bool GraphicsBuffer::alphaChannelFromDrmFormat(uint32_t format)
0077 {
0078     const auto info = FormatInfo::get(format);
0079     return info && info->alphaBits > 0;
0080 }
0081 
0082 } // namespace KWin
0083 
0084 #include "moc_graphicsbuffer.cpp"