From f45c25aabacc70861723a7ca1096a677bd987487 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Jan 2019 14:48:31 -0500 Subject: [PATCH 1/5] nvflinger: Use a std::array for the available displays instead of std::vector The built-in set of displays is fixed, so we can utilize an array instead of a vector here. --- src/core/hle/service/nvflinger/nvflinger.cpp | 6 ------ src/core/hle/service/nvflinger/nvflinger.h | 8 +++++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 6a613aeabf..5bc0d74e81 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -30,12 +30,6 @@ constexpr std::size_t SCREEN_REFRESH_RATE = 60; constexpr u64 frame_ticks = static_cast(CoreTiming::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE); NVFlinger::NVFlinger() { - // Add the different displays to the list of displays. - displays.emplace_back(0, "Default"); - displays.emplace_back(1, "External"); - displays.emplace_back(2, "Edid"); - displays.emplace_back(3, "Internal"); - // Schedule the screen composition events composition_event = CoreTiming::RegisterEvent("ScreenComposition", [this](u64 userdata, int cycles_late) { diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h index 9abba555bd..5ba64a4ce2 100644 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvflinger/nvflinger.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -84,7 +85,12 @@ private: std::shared_ptr nvdrv; - std::vector displays; + std::array displays{{ + {0, "Default"}, + {1, "External"}, + {2, "Edid"}, + {3, "Internal"}, + }}; std::vector> buffer_queues; /// Id to use for the next layer that is created, this counter is shared among all displays. From d9f9bb7552986dff33b5c1906f9743ebdc9b58d1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Jan 2019 14:52:14 -0500 Subject: [PATCH 2/5] nvflinger: Mark locals const where applicable Makes non-mutable state more explicit. --- src/core/hle/service/nvflinger/nvflinger.cpp | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 5bc0d74e81..b774ce3a51 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -54,8 +54,8 @@ u64 NVFlinger::OpenDisplay(std::string_view name) { // TODO(Subv): Currently we only support the Default display. ASSERT(name == "Default"); - auto itr = std::find_if(displays.begin(), displays.end(), - [&](const Display& display) { return display.name == name; }); + const auto itr = std::find_if(displays.begin(), displays.end(), + [&](const Display& display) { return display.name == name; }); ASSERT(itr != displays.end()); @@ -67,8 +67,8 @@ u64 NVFlinger::CreateLayer(u64 display_id) { ASSERT_MSG(display.layers.empty(), "Only one layer is supported per display at the moment"); - u64 layer_id = next_layer_id++; - u32 buffer_queue_id = next_buffer_queue_id++; + const u64 layer_id = next_layer_id++; + const u32 buffer_queue_id = next_buffer_queue_id++; auto buffer_queue = std::make_shared(buffer_queue_id, layer_id); display.layers.emplace_back(layer_id, buffer_queue); buffer_queues.emplace_back(std::move(buffer_queue)); @@ -85,16 +85,16 @@ Kernel::SharedPtr NVFlinger::GetVsyncEvent(u64 display_id } std::shared_ptr NVFlinger::GetBufferQueue(u32 id) const { - auto itr = std::find_if(buffer_queues.begin(), buffer_queues.end(), - [&](const auto& queue) { return queue->GetId() == id; }); + const auto itr = std::find_if(buffer_queues.begin(), buffer_queues.end(), + [&](const auto& queue) { return queue->GetId() == id; }); ASSERT(itr != buffer_queues.end()); return *itr; } Display& NVFlinger::GetDisplay(u64 display_id) { - auto itr = std::find_if(displays.begin(), displays.end(), - [&](const Display& display) { return display.id == 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; @@ -103,8 +103,8 @@ Display& NVFlinger::GetDisplay(u64 display_id) { Layer& NVFlinger::GetLayer(u64 display_id, u64 layer_id) { auto& display = GetDisplay(display_id); - auto itr = std::find_if(display.layers.begin(), display.layers.end(), - [&](const Layer& layer) { return layer.id == layer_id; }); + 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; @@ -139,7 +139,7 @@ void NVFlinger::Compose() { continue; } - auto& igbp_buffer = buffer->get().igbp_buffer; + const auto& igbp_buffer = buffer->get().igbp_buffer; // Now send the buffer to the GPU for drawing. // TODO(Subv): Support more than just disp0. The display device selection is probably based From 3d81a8efd5ebbeeba1e482cd2c246079dc2ecbbb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Jan 2019 14:53:01 -0500 Subject: [PATCH 3/5] nvflinger: Remove unnecessary header inclusions --- src/core/hle/service/nvflinger/nvflinger.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index b774ce3a51..7dbfc590b6 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -5,7 +5,6 @@ #include #include -#include "common/alignment.h" #include "common/assert.h" #include "common/logging/log.h" #include "common/microprofile.h" @@ -22,7 +21,6 @@ #include "core/hle/service/nvflinger/nvflinger.h" #include "core/perf_stats.h" #include "video_core/renderer_base.h" -#include "video_core/video_core.h" namespace Service::NVFlinger { From 679e63550a23e33b5801174783c869a0c44b9f65 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Jan 2019 14:53:50 -0500 Subject: [PATCH 4/5] nvflinger: Change log message in OpenDisplay to be a debug log instead of a warning Opening a display isn't really a thing to warn about. It's an expected thing, so this can be a debug log. This also alters the string to indicate the display name better. Opening "Default" display reads a little nicer compared to Opening display Default. --- src/core/hle/service/nvflinger/nvflinger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 7dbfc590b6..6db2cce417 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -47,7 +47,7 @@ void NVFlinger::SetNVDrvInstance(std::shared_ptr instance) { } u64 NVFlinger::OpenDisplay(std::string_view name) { - LOG_WARNING(Service, "Opening display {}", name); + LOG_DEBUG(Service, "Opening \"{}\" display", name); // TODO(Subv): Currently we only support the Default display. ASSERT(name == "Default"); From 7e9249740205b43ff42005ef4b710d0af3be2899 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 29 Jan 2019 14:59:19 -0500 Subject: [PATCH 5/5] nvflinger: Add the Null display In addition to the default, external, EDID, and internal displays, there's also a null display provided as well, which as the name suggests, does nothing but discard all commands given to it. This is provided for completeness. --- src/core/hle/service/nvflinger/nvflinger.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/nvflinger/nvflinger.h b/src/core/hle/service/nvflinger/nvflinger.h index 5ba64a4ce2..8f9a0a7f85 100644 --- a/src/core/hle/service/nvflinger/nvflinger.h +++ b/src/core/hle/service/nvflinger/nvflinger.h @@ -85,11 +85,12 @@ private: std::shared_ptr nvdrv; - std::array displays{{ + std::array displays{{ {0, "Default"}, {1, "External"}, {2, "Edid"}, {3, "Internal"}, + {4, "Null"}, }}; std::vector> buffer_queues;