mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-07-20 12:55:45 +00:00
fix weird implementation
This commit is contained in:
parent
885ce4c58c
commit
603176b6e7
3 changed files with 36 additions and 22 deletions
|
@ -1,27 +1,37 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <common/assert.h>
|
#include <common/assert.h>
|
||||||
|
|
||||||
struct BufferHistoryEntry { s32 slot; s64 timestamp; s64 frame_number; };
|
struct BufferHistoryEntry {
|
||||||
|
s32 slot;
|
||||||
class BufferHistoryManager { public: void PushEntry(s32 slot, s64 timestamp, s64 frame_number) { std::lock_guardstd::mutex lock(mutex_); if (entries_.size() >= kMaxHistorySize) entries_.pop_front();
|
s64 timestamp;
|
||||||
|
s64 frame_number;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BufferHistoryManager {
|
||||||
|
public:
|
||||||
|
void PushEntry(s32 slot, s64 timestamp, s64 frame_number) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
if (entries_.size() >= kMaxHistorySize) {
|
||||||
|
entries_.pop_front();
|
||||||
|
}
|
||||||
entries_.emplace_back(BufferHistoryEntry{slot, timestamp, frame_number});
|
entries_.emplace_back(BufferHistoryEntry{slot, timestamp, frame_number});
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 GetHistory(std::span<BufferHistoryEntry> out_entries) {
|
s32 GetHistory(std::span<BufferHistoryEntry> out_entries) {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
s32 count =
|
||||||
s32 count = std::min(static_cast<s32>(entries_.size()), static_cast<s32>(out_entries.size()));
|
std::min<s32>(static_cast<s32>(entries_.size()), static_cast<s32>(out_entries.size()));
|
||||||
|
for (s32 i = 0; i < count; ++i) {
|
||||||
for (s32 i = 0; i < count; ++i)
|
|
||||||
out_entries[i] = entries_[entries_.size() - count + i];
|
out_entries[i] = entries_[entries_.size() - count + i];
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private: static constexpr size_t kMaxHistorySize = 16; std::deque<BufferHistoryEntry> entries_; std::mutex mutex_; };
|
private:
|
||||||
|
static constexpr size_t kMaxHistorySize = 16;
|
||||||
|
std::deque<BufferHistoryEntry> entries_;
|
||||||
|
std::mutex mutex_;
|
||||||
|
};
|
|
@ -928,9 +928,13 @@ void BufferQueueProducer::Transact(u32 code, std::span<const u8> parcel_data,
|
||||||
}
|
}
|
||||||
case TransactionId::GetBufferHistory: {
|
case TransactionId::GetBufferHistory: {
|
||||||
LOG_DEBUG(Service_Nvnflinger, "GetBufferHistory");
|
LOG_DEBUG(Service_Nvnflinger, "GetBufferHistory");
|
||||||
auto out_span = request.PopRaw<std::span<BufferHistoryEntry>>();
|
auto out_span = parcel_in.Read<std::span<BufferHistoryEntry>>();
|
||||||
s32 count = buffer_history_.GetHistory(out_span);
|
s32 count = buffer_history_.GetHistory(out_span);
|
||||||
response.Push(s32(count));
|
parcel_out.Write(s32(count));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ASSERT_MSG(false, "Unimplemented TransactionId {}", code);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "core/hle/service/nvnflinger/buffer_slot.h"
|
#include "core/hle/service/nvnflinger/buffer_slot.h"
|
||||||
#include "core/hle/service/nvnflinger/graphic_buffer_producer.h"
|
#include "core/hle/service/nvnflinger/graphic_buffer_producer.h"
|
||||||
#include "core/hle/service/nvnflinger/pixel_format.h"
|
#include "core/hle/service/nvnflinger/pixel_format.h"
|
||||||
|
#include "core/hle/service/nvnflinger/buffer_history.h"
|
||||||
#include "core/hle/service/nvnflinger/status.h"
|
#include "core/hle/service/nvnflinger/status.h"
|
||||||
#include "core/hle/service/nvnflinger/window.h"
|
#include "core/hle/service/nvnflinger/window.h"
|
||||||
|
|
||||||
|
@ -84,7 +85,6 @@ private:
|
||||||
std::shared_ptr<BufferQueueCore> core;
|
std::shared_ptr<BufferQueueCore> core;
|
||||||
BufferQueueDefs::SlotsType& slots;
|
BufferQueueDefs::SlotsType& slots;
|
||||||
BufferHistoryManager buffer_history_;
|
BufferHistoryManager buffer_history_;
|
||||||
buffer_history_.PushEntry(slot, timestamp, frame_number);
|
|
||||||
u32 sticky_transform{};
|
u32 sticky_transform{};
|
||||||
std::mutex callback_mutex;
|
std::mutex callback_mutex;
|
||||||
s32 next_callback_ticket{};
|
s32 next_callback_ticket{};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue