summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/nvnflinger/ui/graphic_buffer.cpp
blob: ede2a11933fd7754f8569f3a05c47dee48af20b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

#include "core/hle/service/nvdrv/core/nvmap.h"
#include "core/hle/service/nvnflinger/ui/graphic_buffer.h"

namespace Service::android {

static NvGraphicBuffer GetBuffer(std::shared_ptr<NvGraphicBuffer>& buffer) {
    if (buffer) {
        return *buffer;
    } else {
        return {};
    }
}

GraphicBuffer::GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_)
    : NvGraphicBuffer(width_, height_, format_, usage_), m_nvmap(nullptr) {}

GraphicBuffer::GraphicBuffer(Service::Nvidia::NvCore::NvMap& nvmap,
                             std::shared_ptr<NvGraphicBuffer> buffer)
    : NvGraphicBuffer(GetBuffer(buffer)), m_nvmap(std::addressof(nvmap)) {
    if (this->BufferId() > 0) {
        m_nvmap->DuplicateHandle(this->BufferId(), true);
        m_nvmap->PinHandle(this->BufferId(), false);
    }
}

GraphicBuffer::~GraphicBuffer() {
    if (m_nvmap != nullptr && this->BufferId() > 0) {
        m_nvmap->UnpinHandle(this->BufferId());
        m_nvmap->FreeHandle(this->BufferId(), true);
    }
}

} // namespace Service::android