mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-04 11:23:12 +00:00
nvnflinger: use graphic buffer lifetime for map handle
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
GraphicBuffer::~GraphicBuffer() {
|
||||
if (m_nvmap != nullptr && this->BufferId() > 0) {
|
||||
m_nvmap->FreeHandle(this->BufferId(), true);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Service::android
|
||||
@@ -6,16 +6,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||
|
||||
namespace Service::Nvidia::NvCore {
|
||||
class NvMap;
|
||||
} // namespace Service::Nvidia::NvCore
|
||||
|
||||
namespace Service::android {
|
||||
|
||||
struct GraphicBuffer final {
|
||||
constexpr GraphicBuffer() = default;
|
||||
struct NvGraphicBuffer {
|
||||
constexpr NvGraphicBuffer() = default;
|
||||
|
||||
constexpr GraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_)
|
||||
constexpr NvGraphicBuffer(u32 width_, u32 height_, PixelFormat format_, u32 usage_)
|
||||
: width{static_cast<s32>(width_)}, height{static_cast<s32>(height_)}, format{format_},
|
||||
usage{static_cast<s32>(usage_)} {}
|
||||
|
||||
@@ -93,6 +99,17 @@ struct GraphicBuffer final {
|
||||
u32 offset{};
|
||||
INSERT_PADDING_WORDS(60);
|
||||
};
|
||||
static_assert(sizeof(GraphicBuffer) == 0x16C, "GraphicBuffer has wrong size");
|
||||
static_assert(sizeof(NvGraphicBuffer) == 0x16C, "NvGraphicBuffer has wrong size");
|
||||
|
||||
class GraphicBuffer final : public NvGraphicBuffer {
|
||||
public:
|
||||
explicit GraphicBuffer(u32 width, u32 height, PixelFormat format, u32 usage);
|
||||
explicit GraphicBuffer(Service::Nvidia::NvCore::NvMap& nvmap,
|
||||
std::shared_ptr<NvGraphicBuffer> buffer);
|
||||
~GraphicBuffer();
|
||||
|
||||
private:
|
||||
Service::Nvidia::NvCore::NvMap* m_nvmap{};
|
||||
};
|
||||
|
||||
} // namespace Service::android
|
||||
|
||||
Reference in New Issue
Block a user