mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-26 16:52:46 +01:00
service/nvflinger: Move display specifics over to vi_display
With the display and layer structures relocated to the vi service, we can begin giving these a proper interface before beginning to properly support the display types. This converts the display struct into a class and provides it with the necessary functions to preserve behavior within the NVFlinger class.
This commit is contained in:
parent
9539c4203b
commit
fa4dc2cf42
4 changed files with 141 additions and 35 deletions
|
@ -28,9 +28,13 @@ namespace Service::NVFlinger {
|
||||||
constexpr std::size_t SCREEN_REFRESH_RATE = 60;
|
constexpr std::size_t SCREEN_REFRESH_RATE = 60;
|
||||||
constexpr u64 frame_ticks = static_cast<u64>(Core::Timing::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE);
|
constexpr u64 frame_ticks = static_cast<u64>(Core::Timing::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE);
|
||||||
|
|
||||||
NVFlinger::NVFlinger(Core::Timing::CoreTiming& core_timing)
|
NVFlinger::NVFlinger(Core::Timing::CoreTiming& core_timing) : core_timing{core_timing} {
|
||||||
: displays{{0, "Default"}, {1, "External"}, {2, "Edid"}, {3, "Internal"}, {4, "Null"}},
|
displays.emplace_back(0, "Default");
|
||||||
core_timing{core_timing} {
|
displays.emplace_back(1, "External");
|
||||||
|
displays.emplace_back(2, "Edid");
|
||||||
|
displays.emplace_back(3, "Internal");
|
||||||
|
displays.emplace_back(4, "Null");
|
||||||
|
|
||||||
// Schedule the screen composition events
|
// Schedule the screen composition events
|
||||||
composition_event =
|
composition_event =
|
||||||
core_timing.RegisterEvent("ScreenComposition", [this](u64 userdata, int cycles_late) {
|
core_timing.RegisterEvent("ScreenComposition", [this](u64 userdata, int cycles_late) {
|
||||||
|
@ -55,13 +59,14 @@ std::optional<u64> NVFlinger::OpenDisplay(std::string_view name) {
|
||||||
// TODO(Subv): Currently we only support the Default display.
|
// TODO(Subv): Currently we only support the Default display.
|
||||||
ASSERT(name == "Default");
|
ASSERT(name == "Default");
|
||||||
|
|
||||||
const auto itr = std::find_if(displays.begin(), displays.end(),
|
const auto itr =
|
||||||
[&](const VI::Display& display) { return display.name == name; });
|
std::find_if(displays.begin(), displays.end(),
|
||||||
|
[&](const VI::Display& display) { return display.GetName() == name; });
|
||||||
if (itr == displays.end()) {
|
if (itr == displays.end()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return itr->id;
|
return itr->GetID();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
|
std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
|
||||||
|
@ -71,12 +76,10 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_MSG(display->layers.empty(), "Only one layer is supported per display at the moment");
|
|
||||||
|
|
||||||
const u64 layer_id = next_layer_id++;
|
const u64 layer_id = next_layer_id++;
|
||||||
const u32 buffer_queue_id = next_buffer_queue_id++;
|
const u32 buffer_queue_id = next_buffer_queue_id++;
|
||||||
auto buffer_queue = std::make_shared<BufferQueue>(buffer_queue_id, layer_id);
|
auto buffer_queue = std::make_shared<BufferQueue>(buffer_queue_id, layer_id);
|
||||||
display->layers.emplace_back(layer_id, buffer_queue);
|
display->CreateLayer(layer_id, buffer_queue);
|
||||||
buffer_queues.emplace_back(std::move(buffer_queue));
|
buffer_queues.emplace_back(std::move(buffer_queue));
|
||||||
return layer_id;
|
return layer_id;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +101,7 @@ Kernel::SharedPtr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_i
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return display->vsync_event.readable;
|
return display->GetVSyncEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const {
|
std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const {
|
||||||
|
@ -112,7 +115,7 @@ std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const {
|
||||||
VI::Display* NVFlinger::FindDisplay(u64 display_id) {
|
VI::Display* NVFlinger::FindDisplay(u64 display_id) {
|
||||||
const auto itr =
|
const auto itr =
|
||||||
std::find_if(displays.begin(), displays.end(),
|
std::find_if(displays.begin(), displays.end(),
|
||||||
[&](const VI::Display& display) { return display.id == display_id; });
|
[&](const VI::Display& display) { return display.GetID() == display_id; });
|
||||||
|
|
||||||
if (itr == displays.end()) {
|
if (itr == displays.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -124,7 +127,7 @@ VI::Display* NVFlinger::FindDisplay(u64 display_id) {
|
||||||
const VI::Display* NVFlinger::FindDisplay(u64 display_id) const {
|
const VI::Display* NVFlinger::FindDisplay(u64 display_id) const {
|
||||||
const auto itr =
|
const auto itr =
|
||||||
std::find_if(displays.begin(), displays.end(),
|
std::find_if(displays.begin(), displays.end(),
|
||||||
[&](const VI::Display& display) { return display.id == display_id; });
|
[&](const VI::Display& display) { return display.GetID() == display_id; });
|
||||||
|
|
||||||
if (itr == displays.end()) {
|
if (itr == displays.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -140,14 +143,7 @@ VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto itr = std::find_if(display->layers.begin(), display->layers.end(),
|
return display->FindLayer(layer_id);
|
||||||
[&](const VI::Layer& layer) { return layer.id == layer_id; });
|
|
||||||
|
|
||||||
if (itr == display->layers.end()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &*itr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const {
|
const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const {
|
||||||
|
@ -157,29 +153,20 @@ const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto itr = std::find_if(display->layers.begin(), display->layers.end(),
|
return display->FindLayer(layer_id);
|
||||||
[&](const VI::Layer& layer) { return layer.id == layer_id; });
|
|
||||||
|
|
||||||
if (itr == display->layers.end()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &*itr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NVFlinger::Compose() {
|
void NVFlinger::Compose() {
|
||||||
for (auto& display : displays) {
|
for (auto& display : displays) {
|
||||||
// Trigger vsync for this display at the end of drawing
|
// Trigger vsync for this display at the end of drawing
|
||||||
SCOPE_EXIT({ display.vsync_event.writable->Signal(); });
|
SCOPE_EXIT({ display.SignalVSyncEvent(); });
|
||||||
|
|
||||||
// Don't do anything for displays without layers.
|
// Don't do anything for displays without layers.
|
||||||
if (display.layers.empty())
|
if (!display.HasLayers())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO(Subv): Support more than 1 layer.
|
// TODO(Subv): Support more than 1 layer.
|
||||||
ASSERT_MSG(display.layers.size() == 1, "Max 1 layer per display is supported");
|
VI::Layer& layer = display.GetLayer(0);
|
||||||
|
|
||||||
VI::Layer& layer = display.layers[0];
|
|
||||||
auto& buffer_queue = layer.buffer_queue;
|
auto& buffer_queue = layer.buffer_queue;
|
||||||
|
|
||||||
// Search for a queued buffer and acquire it
|
// Search for a queued buffer and acquire it
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Module;
|
||||||
} // namespace Service::Nvidia
|
} // namespace Service::Nvidia
|
||||||
|
|
||||||
namespace Service::VI {
|
namespace Service::VI {
|
||||||
struct Display;
|
class Display;
|
||||||
struct Layer;
|
struct Layer;
|
||||||
} // namespace Service::VI
|
} // namespace Service::VI
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
#include "common/assert.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/kernel/readable_event.h"
|
#include "core/hle/kernel/readable_event.h"
|
||||||
#include "core/hle/service/vi/display/vi_display.h"
|
#include "core/hle/service/vi/display/vi_display.h"
|
||||||
|
@ -19,4 +23,49 @@ Display::Display(u64 id, std::string name) : id{id}, name{std::move(name)} {
|
||||||
|
|
||||||
Display::~Display() = default;
|
Display::~Display() = default;
|
||||||
|
|
||||||
|
Layer& Display::GetLayer(std::size_t index) {
|
||||||
|
return layers.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Layer& Display::GetLayer(std::size_t index) const {
|
||||||
|
return layers.at(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Kernel::SharedPtr<Kernel::ReadableEvent> Display::GetVSyncEvent() const {
|
||||||
|
return vsync_event.readable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::SignalVSyncEvent() {
|
||||||
|
vsync_event.writable->Signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Display::CreateLayer(u64 id, std::shared_ptr<NVFlinger::BufferQueue> buffer_queue) {
|
||||||
|
// TODO(Subv): Support more than 1 layer.
|
||||||
|
ASSERT_MSG(layers.empty(), "Only one layer is supported per display at the moment");
|
||||||
|
|
||||||
|
layers.emplace_back(id, std::move(buffer_queue));
|
||||||
|
}
|
||||||
|
|
||||||
|
Layer* Display::FindLayer(u64 id) {
|
||||||
|
const auto itr = std::find_if(layers.begin(), layers.end(),
|
||||||
|
[id](const VI::Layer& layer) { return layer.id == id; });
|
||||||
|
|
||||||
|
if (itr == layers.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &*itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Layer* Display::FindLayer(u64 id) const {
|
||||||
|
const auto itr = std::find_if(layers.begin(), layers.end(),
|
||||||
|
[id](const VI::Layer& layer) { return layer.id == id; });
|
||||||
|
|
||||||
|
if (itr == layers.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &*itr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Service::VI
|
} // namespace Service::VI
|
||||||
|
|
|
@ -10,14 +10,84 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/kernel/writable_event.h"
|
#include "core/hle/kernel/writable_event.h"
|
||||||
|
|
||||||
|
namespace Service::NVFlinger {
|
||||||
|
class BufferQueue;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service::VI {
|
namespace Service::VI {
|
||||||
|
|
||||||
struct Layer;
|
struct Layer;
|
||||||
|
|
||||||
struct Display {
|
/// Represents a single display type
|
||||||
|
class Display {
|
||||||
|
public:
|
||||||
|
/// Constructs a display with a given unique ID and name.
|
||||||
|
///
|
||||||
|
/// @param id The unique ID for this display.
|
||||||
|
/// @param name The name for this display.
|
||||||
|
///
|
||||||
Display(u64 id, std::string name);
|
Display(u64 id, std::string name);
|
||||||
~Display();
|
~Display();
|
||||||
|
|
||||||
|
Display(const Display&) = delete;
|
||||||
|
Display& operator=(const Display&) = delete;
|
||||||
|
|
||||||
|
Display(Display&&) = default;
|
||||||
|
Display& operator=(Display&&) = default;
|
||||||
|
|
||||||
|
/// Gets the unique ID assigned to this display.
|
||||||
|
u64 GetID() const {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets the name of this display
|
||||||
|
const std::string& GetName() const {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether or not this display has any layers added to it.
|
||||||
|
bool HasLayers() const {
|
||||||
|
return !layers.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets a layer for this display based off an index.
|
||||||
|
Layer& GetLayer(std::size_t index);
|
||||||
|
|
||||||
|
/// Gets a layer for this display based off an index.
|
||||||
|
const Layer& GetLayer(std::size_t index) const;
|
||||||
|
|
||||||
|
/// Gets the readable vsync event.
|
||||||
|
Kernel::SharedPtr<Kernel::ReadableEvent> GetVSyncEvent() const;
|
||||||
|
|
||||||
|
/// Signals the internal vsync event.
|
||||||
|
void SignalVSyncEvent();
|
||||||
|
|
||||||
|
/// Creates and adds a layer to this display with the given ID.
|
||||||
|
///
|
||||||
|
/// @param id The ID to assign to the created layer.
|
||||||
|
/// @param buffer_queue The buffer queue for the layer instance to use.
|
||||||
|
///
|
||||||
|
void CreateLayer(u64 id, std::shared_ptr<NVFlinger::BufferQueue> buffer_queue);
|
||||||
|
|
||||||
|
/// Attempts to find a layer with the given ID.
|
||||||
|
///
|
||||||
|
/// @param id The layer ID.
|
||||||
|
///
|
||||||
|
/// @returns If found, the Layer instance with the given ID.
|
||||||
|
/// If not found, then nullptr is returned.
|
||||||
|
///
|
||||||
|
Layer* FindLayer(u64 id);
|
||||||
|
|
||||||
|
/// Attempts to find a layer with the given ID.
|
||||||
|
///
|
||||||
|
/// @param id The layer ID.
|
||||||
|
///
|
||||||
|
/// @returns If found, the Layer instance with the given ID.
|
||||||
|
/// If not found, then nullptr is returned.
|
||||||
|
///
|
||||||
|
const Layer* FindLayer(u64 id) const;
|
||||||
|
|
||||||
|
private:
|
||||||
u64 id;
|
u64 id;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue