File indexing completed on 2024-11-10 04:57:06
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 "plugins/qpa/swapchain.h" 0008 0009 namespace KWin 0010 { 0011 namespace QPA 0012 { 0013 0014 Swapchain::Swapchain(GraphicsBufferAllocator *allocator, const GraphicsBufferOptions &options, GraphicsBuffer *initialBuffer) 0015 : m_allocator(allocator) 0016 , m_allocationOptions(options) 0017 { 0018 m_buffers.push_back(initialBuffer); 0019 } 0020 0021 Swapchain::~Swapchain() 0022 { 0023 for (GraphicsBuffer *buffer : std::as_const(m_buffers)) { 0024 buffer->drop(); 0025 } 0026 } 0027 0028 QSize Swapchain::size() const 0029 { 0030 return m_allocationOptions.size; 0031 } 0032 0033 GraphicsBuffer *Swapchain::acquire() 0034 { 0035 for (GraphicsBuffer *buffer : std::as_const(m_buffers)) { 0036 if (!buffer->isReferenced()) { 0037 return buffer; 0038 } 0039 } 0040 0041 GraphicsBuffer *buffer = m_allocator->allocate(m_allocationOptions); 0042 if (!buffer) { 0043 return nullptr; 0044 } 0045 0046 m_buffers.append(buffer); 0047 return buffer; 0048 } 0049 0050 uint32_t Swapchain::format() const 0051 { 0052 return m_allocationOptions.format; 0053 } 0054 0055 QList<uint64_t> Swapchain::modifiers() const 0056 { 0057 return m_allocationOptions.modifiers; 0058 } 0059 } 0060 }