diff options
| author | 2019-02-21 10:43:26 -0500 | |
|---|---|---|
| committer | 2019-02-21 12:13:04 -0500 | |
| commit | fa4dc2cf427ddb464d73d532ba941513828b9b7a (patch) | |
| tree | de8750cdf516af224c1dae2283e7213e5e088d1d /src | |
| parent | Merge pull request #2125 from ReinUsesLisp/fixup-glstate (diff) | |
| download | yuzu-fa4dc2cf427ddb464d73d532ba941513828b9b7a.tar.gz yuzu-fa4dc2cf427ddb464d73d532ba941513828b9b7a.tar.xz yuzu-fa4dc2cf427ddb464d73d532ba941513828b9b7a.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nvflinger/nvflinger.cpp | 53 | ||||
| -rw-r--r-- | src/core/hle/service/nvflinger/nvflinger.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/vi/display/vi_display.cpp | 49 | ||||
| -rw-r--r-- | src/core/hle/service/vi/display/vi_display.h | 72 |
4 files changed, 141 insertions, 35 deletions
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index b5d452db1..6cc31050f 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp | |||
| @@ -28,9 +28,13 @@ namespace Service::NVFlinger { | |||
| 28 | constexpr std::size_t SCREEN_REFRESH_RATE = 60; | 28 | constexpr std::size_t SCREEN_REFRESH_RATE = 60; |
| 29 | constexpr u64 frame_ticks = static_cast<u64>(Core::Timing::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE); | 29 | constexpr u64 frame_ticks = static_cast<u64>(Core::Timing::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE); |
| 30 | 30 | ||
| 31 | NVFlinger::NVFlinger(Core::Timing::CoreTiming& core_timing) | 31 | NVFlinger::NVFlinger(Core::Timing::CoreTiming& core_timing) : core_timing{core_timing} { |
| 32 | : displays{{0, "Default"}, {1, "External"}, {2, "Edid"}, {3, "Internal"}, {4, "Null"}}, | 32 | displays.emplace_back(0, "Default"); |
| 33 | core_timing{core_timing} { | 33 | displays.emplace_back(1, "External"); |
| 34 | displays.emplace_back(2, "Edid"); | ||
| 35 | displays.emplace_back(3, "Internal"); | ||
| 36 | displays.emplace_back(4, "Null"); | ||
| 37 | |||
| 34 | // Schedule the screen composition events | 38 | // Schedule the screen composition events |
| 35 | composition_event = | 39 | composition_event = |
| 36 | core_timing.RegisterEvent("ScreenComposition", [this](u64 userdata, int cycles_late) { | 40 | core_timing.RegisterEvent("ScreenComposition", [this](u64 userdata, int cycles_late) { |
| @@ -55,13 +59,14 @@ std::optional<u64> NVFlinger::OpenDisplay(std::string_view name) { | |||
| 55 | // TODO(Subv): Currently we only support the Default display. | 59 | // TODO(Subv): Currently we only support the Default display. |
| 56 | ASSERT(name == "Default"); | 60 | ASSERT(name == "Default"); |
| 57 | 61 | ||
| 58 | const auto itr = std::find_if(displays.begin(), displays.end(), | 62 | const auto itr = |
| 59 | [&](const VI::Display& display) { return display.name == name; }); | 63 | std::find_if(displays.begin(), displays.end(), |
| 64 | [&](const VI::Display& display) { return display.GetName() == name; }); | ||
| 60 | if (itr == displays.end()) { | 65 | if (itr == displays.end()) { |
| 61 | return {}; | 66 | return {}; |
| 62 | } | 67 | } |
| 63 | 68 | ||
| 64 | return itr->id; | 69 | return itr->GetID(); |
| 65 | } | 70 | } |
| 66 | 71 | ||
| 67 | std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { | 72 | std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { |
| @@ -71,12 +76,10 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { | |||
| 71 | return {}; | 76 | return {}; |
| 72 | } | 77 | } |
| 73 | 78 | ||
| 74 | ASSERT_MSG(display->layers.empty(), "Only one layer is supported per display at the moment"); | ||
| 75 | |||
| 76 | const u64 layer_id = next_layer_id++; | 79 | const u64 layer_id = next_layer_id++; |
| 77 | const u32 buffer_queue_id = next_buffer_queue_id++; | 80 | const u32 buffer_queue_id = next_buffer_queue_id++; |
| 78 | auto buffer_queue = std::make_shared<BufferQueue>(buffer_queue_id, layer_id); | 81 | auto buffer_queue = std::make_shared<BufferQueue>(buffer_queue_id, layer_id); |
| 79 | display->layers.emplace_back(layer_id, buffer_queue); | 82 | display->CreateLayer(layer_id, buffer_queue); |
| 80 | buffer_queues.emplace_back(std::move(buffer_queue)); | 83 | buffer_queues.emplace_back(std::move(buffer_queue)); |
| 81 | return layer_id; | 84 | return layer_id; |
| 82 | } | 85 | } |
| @@ -98,7 +101,7 @@ Kernel::SharedPtr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_i | |||
| 98 | return nullptr; | 101 | return nullptr; |
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | return display->vsync_event.readable; | 104 | return display->GetVSyncEvent(); |
| 102 | } | 105 | } |
| 103 | 106 | ||
| 104 | std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const { | 107 | std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const { |
| @@ -112,7 +115,7 @@ std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const { | |||
| 112 | VI::Display* NVFlinger::FindDisplay(u64 display_id) { | 115 | VI::Display* NVFlinger::FindDisplay(u64 display_id) { |
| 113 | const auto itr = | 116 | const auto itr = |
| 114 | std::find_if(displays.begin(), displays.end(), | 117 | std::find_if(displays.begin(), displays.end(), |
| 115 | [&](const VI::Display& display) { return display.id == display_id; }); | 118 | [&](const VI::Display& display) { return display.GetID() == display_id; }); |
| 116 | 119 | ||
| 117 | if (itr == displays.end()) { | 120 | if (itr == displays.end()) { |
| 118 | return nullptr; | 121 | return nullptr; |
| @@ -124,7 +127,7 @@ VI::Display* NVFlinger::FindDisplay(u64 display_id) { | |||
| 124 | const VI::Display* NVFlinger::FindDisplay(u64 display_id) const { | 127 | const VI::Display* NVFlinger::FindDisplay(u64 display_id) const { |
| 125 | const auto itr = | 128 | const auto itr = |
| 126 | std::find_if(displays.begin(), displays.end(), | 129 | std::find_if(displays.begin(), displays.end(), |
| 127 | [&](const VI::Display& display) { return display.id == display_id; }); | 130 | [&](const VI::Display& display) { return display.GetID() == display_id; }); |
| 128 | 131 | ||
| 129 | if (itr == displays.end()) { | 132 | if (itr == displays.end()) { |
| 130 | return nullptr; | 133 | return nullptr; |
| @@ -140,14 +143,7 @@ VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) { | |||
| 140 | return nullptr; | 143 | return nullptr; |
| 141 | } | 144 | } |
| 142 | 145 | ||
| 143 | const auto itr = std::find_if(display->layers.begin(), display->layers.end(), | 146 | return display->FindLayer(layer_id); |
| 144 | [&](const VI::Layer& layer) { return layer.id == layer_id; }); | ||
| 145 | |||
| 146 | if (itr == display->layers.end()) { | ||
| 147 | return nullptr; | ||
| 148 | } | ||
| 149 | |||
| 150 | return &*itr; | ||
| 151 | } | 147 | } |
| 152 | 148 | ||
| 153 | const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const { | 149 | 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 { | |||
| 157 | return nullptr; | 153 | return nullptr; |
| 158 | } | 154 | } |
| 159 | 155 | ||
| 160 | const auto itr = std::find_if(display->layers.begin(), display->layers.end(), | 156 | return display->FindLayer(layer_id); |
| 161 | [&](const VI::Layer& layer) { return layer.id == layer_id; }); | ||
| 162 | |||
| 163 | if (itr == display->layers.end()) { | ||
| 164 | return nullptr; | ||
| 165 | } | ||
| 166 | |||
| 167 | return &*itr; | ||
| 168 | } | 157 | } |
| 169 | 158 | ||
| 170 | void NVFlinger::Compose() { | 159 | void NVFlinger::Compose() { |
| 171 | for (auto& display : displays) { | 160 | for (auto& display : displays) { |
| 172 | // Trigger vsync for this display at the end of drawing | 161 | // Trigger vsync for this display at the end of drawing |
| 173 | SCOPE_EXIT({ display.vsync_event.writable->Signal(); }); | 162 | SCOPE_EXIT({ display.SignalVSyncEvent(); }); |
| 174 | 163 | ||
| 175 | // Don't do anything for displays without layers. | 164 | // Don't do anything for displays without layers. |
| 176 | if (display.layers.empty()) | 165 | if (!display.HasLayers()) |
| 177 | continue; | 166 | continue; |
| 178 | 167 | ||
| 179 | // TODO(Subv): Support more than 1 layer. | 168 | // TODO(Subv): Support more than 1 layer. |
| 180 | ASSERT_MSG(display.layers.size() == 1, "Max 1 layer per display is supported"); | 169 | VI::Layer& layer = display.GetLayer(0); |
| 181 | |||
| 182 | VI::Layer& layer = display.layers[0]; | ||
| 183 | auto& buffer_queue = layer.buffer_queue; | 170 | auto& buffer_queue = layer.buffer_queue; |
| 184 | 171 | ||
| 185 | // Search for a queued buffer and acquire it | 172 | // Search for a queued buffer and acquire it |
diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h index 2e000af91..4741b1363 100644 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvflinger/nvflinger.h | |||
| @@ -28,7 +28,7 @@ class Module; | |||
| 28 | } // namespace Service::Nvidia | 28 | } // namespace Service::Nvidia |
| 29 | 29 | ||
| 30 | namespace Service::VI { | 30 | namespace Service::VI { |
| 31 | struct Display; | 31 | class Display; |
| 32 | struct Layer; | 32 | struct Layer; |
| 33 | } // namespace Service::VI | 33 | } // namespace Service::VI |
| 34 | 34 | ||
diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index a108e468f..4d77c3353 100644 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp | |||
| @@ -2,8 +2,12 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 5 | #include <fmt/format.h> | 8 | #include <fmt/format.h> |
| 6 | 9 | ||
| 10 | #include "common/assert.h" | ||
| 7 | #include "core/core.h" | 11 | #include "core/core.h" |
| 8 | #include "core/hle/kernel/readable_event.h" | 12 | #include "core/hle/kernel/readable_event.h" |
| 9 | #include "core/hle/service/vi/display/vi_display.h" | 13 | #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)} { | |||
| 19 | 23 | ||
| 20 | Display::~Display() = default; | 24 | Display::~Display() = default; |
| 21 | 25 | ||
| 26 | Layer& Display::GetLayer(std::size_t index) { | ||
| 27 | return layers.at(index); | ||
| 28 | } | ||
| 29 | |||
| 30 | const Layer& Display::GetLayer(std::size_t index) const { | ||
| 31 | return layers.at(index); | ||
| 32 | } | ||
| 33 | |||
| 34 | Kernel::SharedPtr<Kernel::ReadableEvent> Display::GetVSyncEvent() const { | ||
| 35 | return vsync_event.readable; | ||
| 36 | } | ||
| 37 | |||
| 38 | void Display::SignalVSyncEvent() { | ||
| 39 | vsync_event.writable->Signal(); | ||
| 40 | } | ||
| 41 | |||
| 42 | void Display::CreateLayer(u64 id, std::shared_ptr<NVFlinger::BufferQueue> buffer_queue) { | ||
| 43 | // TODO(Subv): Support more than 1 layer. | ||
| 44 | ASSERT_MSG(layers.empty(), "Only one layer is supported per display at the moment"); | ||
| 45 | |||
| 46 | layers.emplace_back(id, std::move(buffer_queue)); | ||
| 47 | } | ||
| 48 | |||
| 49 | Layer* Display::FindLayer(u64 id) { | ||
| 50 | const auto itr = std::find_if(layers.begin(), layers.end(), | ||
| 51 | [id](const VI::Layer& layer) { return layer.id == id; }); | ||
| 52 | |||
| 53 | if (itr == layers.end()) { | ||
| 54 | return nullptr; | ||
| 55 | } | ||
| 56 | |||
| 57 | return &*itr; | ||
| 58 | } | ||
| 59 | |||
| 60 | const Layer* Display::FindLayer(u64 id) const { | ||
| 61 | const auto itr = std::find_if(layers.begin(), layers.end(), | ||
| 62 | [id](const VI::Layer& layer) { return layer.id == id; }); | ||
| 63 | |||
| 64 | if (itr == layers.end()) { | ||
| 65 | return nullptr; | ||
| 66 | } | ||
| 67 | |||
| 68 | return &*itr; | ||
| 69 | } | ||
| 70 | |||
| 22 | } // namespace Service::VI | 71 | } // namespace Service::VI |
diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h index df44db306..22b831592 100644 --- a/src/core/hle/service/vi/display/vi_display.h +++ b/src/core/hle/service/vi/display/vi_display.h | |||
| @@ -10,14 +10,84 @@ | |||
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "core/hle/kernel/writable_event.h" | 11 | #include "core/hle/kernel/writable_event.h" |
| 12 | 12 | ||
| 13 | namespace Service::NVFlinger { | ||
| 14 | class BufferQueue; | ||
| 15 | } | ||
| 16 | |||
| 13 | namespace Service::VI { | 17 | namespace Service::VI { |
| 14 | 18 | ||
| 15 | struct Layer; | 19 | struct Layer; |
| 16 | 20 | ||
| 17 | struct Display { | 21 | /// Represents a single display type |
| 22 | class Display { | ||
| 23 | public: | ||
| 24 | /// Constructs a display with a given unique ID and name. | ||
| 25 | /// | ||
| 26 | /// @param id The unique ID for this display. | ||
| 27 | /// @param name The name for this display. | ||
| 28 | /// | ||
| 18 | Display(u64 id, std::string name); | 29 | Display(u64 id, std::string name); |
| 19 | ~Display(); | 30 | ~Display(); |
| 20 | 31 | ||
| 32 | Display(const Display&) = delete; | ||
| 33 | Display& operator=(const Display&) = delete; | ||
| 34 | |||
| 35 | Display(Display&&) = default; | ||
| 36 | Display& operator=(Display&&) = default; | ||
| 37 | |||
| 38 | /// Gets the unique ID assigned to this display. | ||
| 39 | u64 GetID() const { | ||
| 40 | return id; | ||
| 41 | } | ||
| 42 | |||
| 43 | /// Gets the name of this display | ||
| 44 | const std::string& GetName() const { | ||
| 45 | return name; | ||
| 46 | } | ||
| 47 | |||
| 48 | /// Whether or not this display has any layers added to it. | ||
| 49 | bool HasLayers() const { | ||
| 50 | return !layers.empty(); | ||
| 51 | } | ||
| 52 | |||
| 53 | /// Gets a layer for this display based off an index. | ||
| 54 | Layer& GetLayer(std::size_t index); | ||
| 55 | |||
| 56 | /// Gets a layer for this display based off an index. | ||
| 57 | const Layer& GetLayer(std::size_t index) const; | ||
| 58 | |||
| 59 | /// Gets the readable vsync event. | ||
| 60 | Kernel::SharedPtr<Kernel::ReadableEvent> GetVSyncEvent() const; | ||
| 61 | |||
| 62 | /// Signals the internal vsync event. | ||
| 63 | void SignalVSyncEvent(); | ||
| 64 | |||
| 65 | /// Creates and adds a layer to this display with the given ID. | ||
| 66 | /// | ||
| 67 | /// @param id The ID to assign to the created layer. | ||
| 68 | /// @param buffer_queue The buffer queue for the layer instance to use. | ||
| 69 | /// | ||
| 70 | void CreateLayer(u64 id, std::shared_ptr<NVFlinger::BufferQueue> buffer_queue); | ||
| 71 | |||
| 72 | /// Attempts to find a layer with the given ID. | ||
| 73 | /// | ||
| 74 | /// @param id The layer ID. | ||
| 75 | /// | ||
| 76 | /// @returns If found, the Layer instance with the given ID. | ||
| 77 | /// If not found, then nullptr is returned. | ||
| 78 | /// | ||
| 79 | Layer* FindLayer(u64 id); | ||
| 80 | |||
| 81 | /// Attempts to find a layer with the given ID. | ||
| 82 | /// | ||
| 83 | /// @param id The layer ID. | ||
| 84 | /// | ||
| 85 | /// @returns If found, the Layer instance with the given ID. | ||
| 86 | /// If not found, then nullptr is returned. | ||
| 87 | /// | ||
| 88 | const Layer* FindLayer(u64 id) const; | ||
| 89 | |||
| 90 | private: | ||
| 21 | u64 id; | 91 | u64 id; |
| 22 | std::string name; | 92 | std::string name; |
| 23 | 93 | ||