File indexing completed on 2024-11-10 04:56:26

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2023 Xaver Hugl <xaver.hugl@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "drm_blob.h"
0010 #include "drm_gpu.h"
0011 
0012 namespace KWin
0013 {
0014 
0015 DrmBlob::DrmBlob(DrmGpu *gpu, uint32_t blobId)
0016     : m_gpu(gpu)
0017     , m_blobId(blobId)
0018 {
0019 }
0020 
0021 DrmBlob::~DrmBlob()
0022 {
0023     if (m_blobId) {
0024         drmModeDestroyPropertyBlob(m_gpu->fd(), m_blobId);
0025     }
0026 }
0027 
0028 uint32_t DrmBlob::blobId() const
0029 {
0030     return m_blobId;
0031 }
0032 
0033 std::shared_ptr<DrmBlob> DrmBlob::create(DrmGpu *gpu, const void *data, uint32_t dataSize)
0034 {
0035     uint32_t id = 0;
0036     if (drmModeCreatePropertyBlob(gpu->fd(), data, dataSize, &id) == 0) {
0037         return std::make_shared<DrmBlob>(gpu, id);
0038     } else {
0039         return nullptr;
0040     }
0041 }
0042 }