summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/nvflinger
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2019-02-05 22:20:04 +0100
committerLioncash <mathew1800@gmail.com>2019-02-06 00:03:28 +0100
commitef073ff117752274f374443756652fdda9c44773 (patch)
tree3453e2c21a4aec602f5ee9a308cad23463d9dad3 /src/core/hle/service/nvflinger
parentservice/nvflinger: Mark FindVsyncEvent() as a const member function (diff)
downloadyuzu-ef073ff117752274f374443756652fdda9c44773.tar
yuzu-ef073ff117752274f374443756652fdda9c44773.tar.gz
yuzu-ef073ff117752274f374443756652fdda9c44773.tar.bz2
yuzu-ef073ff117752274f374443756652fdda9c44773.tar.lz
yuzu-ef073ff117752274f374443756652fdda9c44773.tar.xz
yuzu-ef073ff117752274f374443756652fdda9c44773.tar.zst
yuzu-ef073ff117752274f374443756652fdda9c44773.zip
Diffstat (limited to 'src/core/hle/service/nvflinger')
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp90
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.h23
2 files changed, 79 insertions, 34 deletions
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index ce3f2d8c1..cde06916d 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -46,7 +46,7 @@ void NVFlinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) {
nvdrv = std::move(instance);
}
-u64 NVFlinger::OpenDisplay(std::string_view name) {
+std::optional<u64> NVFlinger::OpenDisplay(std::string_view name) {
LOG_DEBUG(Service, "Opening \"{}\" display", name);
// TODO(Subv): Currently we only support the Default display.
@@ -54,32 +54,48 @@ u64 NVFlinger::OpenDisplay(std::string_view name) {
const auto itr = std::find_if(displays.begin(), displays.end(),
[&](const Display& display) { return display.name == name; });
-
- ASSERT(itr != displays.end());
+ if (itr == displays.end()) {
+ return {};
+ }
return itr->id;
}
-u64 NVFlinger::CreateLayer(u64 display_id) {
- auto& display = FindDisplay(display_id);
+std::optional<u64> NVFlinger::CreateLayer(u64 display_id) {
+ auto* const display = FindDisplay(display_id);
+
+ if (display == nullptr) {
+ return {};
+ }
- ASSERT_MSG(display.layers.empty(), "Only one layer is supported per display at the moment");
+ ASSERT_MSG(display->layers.empty(), "Only one layer is supported per display at the moment");
const u64 layer_id = next_layer_id++;
const u32 buffer_queue_id = next_buffer_queue_id++;
auto buffer_queue = std::make_shared<BufferQueue>(buffer_queue_id, layer_id);
- display.layers.emplace_back(layer_id, buffer_queue);
+ display->layers.emplace_back(layer_id, buffer_queue);
buffer_queues.emplace_back(std::move(buffer_queue));
return layer_id;
}
-u32 NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) const {
- const auto& layer = FindLayer(display_id, layer_id);
- return layer.buffer_queue->GetId();
+std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) const {
+ const auto* const layer = FindLayer(display_id, layer_id);
+
+ if (layer == nullptr) {
+ return {};
+ }
+
+ return layer->buffer_queue->GetId();
}
Kernel::SharedPtr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_id) const {
- return FindDisplay(display_id).vsync_event.readable;
+ auto* const display = FindDisplay(display_id);
+
+ if (display == nullptr) {
+ return nullptr;
+ }
+
+ return display->vsync_event.readable;
}
std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const {
@@ -90,40 +106,60 @@ std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const {
return *itr;
}
-Display& NVFlinger::FindDisplay(u64 display_id) {
+Display* NVFlinger::FindDisplay(u64 display_id) {
const auto itr = std::find_if(displays.begin(), displays.end(),
[&](const Display& display) { return display.id == display_id; });
- ASSERT(itr != displays.end());
- return *itr;
+ if (itr == displays.end()) {
+ return nullptr;
+ }
+
+ return &*itr;
}
-const Display& NVFlinger::FindDisplay(u64 display_id) const {
+const Display* NVFlinger::FindDisplay(u64 display_id) const {
const auto itr = std::find_if(displays.begin(), displays.end(),
[&](const Display& display) { return display.id == display_id; });
- ASSERT(itr != displays.end());
- return *itr;
+ if (itr == displays.end()) {
+ return nullptr;
+ }
+
+ return &*itr;
}
-Layer& NVFlinger::FindLayer(u64 display_id, u64 layer_id) {
- auto& display = FindDisplay(display_id);
+Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) {
+ auto* const display = FindDisplay(display_id);
- const auto itr = std::find_if(display.layers.begin(), display.layers.end(),
+ if (display == nullptr) {
+ return nullptr;
+ }
+
+ const auto itr = std::find_if(display->layers.begin(), display->layers.end(),
[&](const Layer& layer) { return layer.id == layer_id; });
- ASSERT(itr != display.layers.end());
- return *itr;
+ if (itr == display->layers.end()) {
+ return nullptr;
+ }
+
+ return &*itr;
}
-const Layer& NVFlinger::FindLayer(u64 display_id, u64 layer_id) const {
- const auto& display = FindDisplay(display_id);
+const Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const {
+ const auto* const display = FindDisplay(display_id);
+
+ if (display == nullptr) {
+ return nullptr;
+ }
- const auto itr = std::find_if(display.layers.begin(), display.layers.end(),
+ const auto itr = std::find_if(display->layers.begin(), display->layers.end(),
[&](const Layer& layer) { return layer.id == layer_id; });
- ASSERT(itr != display.layers.end());
- return *itr;
+ if (itr == display->layers.end()) {
+ return nullptr;
+ }
+
+ return &*itr;
}
void NVFlinger::Compose() {
diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h
index 61db2c23b..4c55e99f4 100644
--- a/src/core/hle/service/nvflinger/nvflinger.h
+++ b/src/core/hle/service/nvflinger/nvflinger.h
@@ -6,6 +6,7 @@
#include <array>
#include <memory>
+#include <optional>
#include <string>
#include <string_view>
#include <vector>
@@ -58,15 +59,23 @@ public:
void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance);
/// Opens the specified display and returns the ID.
- u64 OpenDisplay(std::string_view name);
+ ///
+ /// If an invalid display name is provided, then an empty optional is returned.
+ std::optional<u64> OpenDisplay(std::string_view name);
/// Creates a layer on the specified display and returns the layer ID.
- u64 CreateLayer(u64 display_id);
+ ///
+ /// If an invalid display ID is specified, then an empty optional is returned.
+ std::optional<u64> CreateLayer(u64 display_id);
/// Finds the buffer queue ID of the specified layer in the specified display.
- u32 FindBufferQueueId(u64 display_id, u64 layer_id) const;
+ ///
+ /// If an invalid display ID or layer ID is provided, then an empty optional is returned.
+ std::optional<u32> FindBufferQueueId(u64 display_id, u64 layer_id) const;
/// Gets the vsync event for the specified display.
+ ///
+ /// If an invalid display ID is provided, then nullptr is returned.
Kernel::SharedPtr<Kernel::ReadableEvent> FindVsyncEvent(u64 display_id) const;
/// Obtains a buffer queue identified by the ID.
@@ -78,16 +87,16 @@ public:
private:
/// Finds the display identified by the specified ID.
- Display& FindDisplay(u64 display_id);
+ Display* FindDisplay(u64 display_id);
/// Finds the display identified by the specified ID.
- const Display& FindDisplay(u64 display_id) const;
+ const Display* FindDisplay(u64 display_id) const;
/// Finds the layer identified by the specified ID in the desired display.
- Layer& FindLayer(u64 display_id, u64 layer_id);
+ Layer* FindLayer(u64 display_id, u64 layer_id);
/// Finds the layer identified by the specified ID in the desired display.
- const Layer& FindLayer(u64 display_id, u64 layer_id) const;
+ const Layer* FindLayer(u64 display_id, u64 layer_id) const;
std::shared_ptr<Nvidia::Module> nvdrv;