|
|
|
@ -28,9 +28,13 @@ namespace Service::NVFlinger { |
|
|
|
constexpr std::size_t SCREEN_REFRESH_RATE = 60; |
|
|
|
constexpr u64 frame_ticks = static_cast<u64>(Core::Timing::BASE_CLOCK_RATE / SCREEN_REFRESH_RATE); |
|
|
|
|
|
|
|
NVFlinger::NVFlinger(Core::Timing::CoreTiming& core_timing) |
|
|
|
: displays{{0, "Default"}, {1, "External"}, {2, "Edid"}, {3, "Internal"}, {4, "Null"}}, |
|
|
|
core_timing{core_timing} { |
|
|
|
NVFlinger::NVFlinger(Core::Timing::CoreTiming& core_timing) : core_timing{core_timing} { |
|
|
|
displays.emplace_back(0, "Default"); |
|
|
|
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
|
|
|
|
composition_event = |
|
|
|
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.
|
|
|
|
ASSERT(name == "Default"); |
|
|
|
|
|
|
|
const auto itr = std::find_if(displays.begin(), displays.end(), |
|
|
|
[&](const VI::Display& display) { return display.name == name; }); |
|
|
|
const auto itr = |
|
|
|
std::find_if(displays.begin(), displays.end(), |
|
|
|
[&](const VI::Display& display) { return display.GetName() == name; }); |
|
|
|
if (itr == displays.end()) { |
|
|
|
return {}; |
|
|
|
} |
|
|
|
|
|
|
|
return itr->id; |
|
|
|
return itr->GetID(); |
|
|
|
} |
|
|
|
|
|
|
|
std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { |
|
|
|
@ -71,13 +76,10 @@ std::optional<u64> NVFlinger::CreateLayer(u64 display_id) { |
|
|
|
return {}; |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
buffer_queues.emplace_back(std::move(buffer_queue)); |
|
|
|
buffer_queues.emplace_back(buffer_queue_id, layer_id); |
|
|
|
display->CreateLayer(layer_id, buffer_queues.back()); |
|
|
|
return layer_id; |
|
|
|
} |
|
|
|
|
|
|
|
@ -88,7 +90,7 @@ std::optional<u32> NVFlinger::FindBufferQueueId(u64 display_id, u64 layer_id) co |
|
|
|
return {}; |
|
|
|
} |
|
|
|
|
|
|
|
return layer->buffer_queue->GetId(); |
|
|
|
return layer->GetBufferQueue().GetId(); |
|
|
|
} |
|
|
|
|
|
|
|
Kernel::SharedPtr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_id) const { |
|
|
|
@ -98,12 +100,20 @@ Kernel::SharedPtr<Kernel::ReadableEvent> NVFlinger::FindVsyncEvent(u64 display_i |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
return display->vsync_event.readable; |
|
|
|
return display->GetVSyncEvent(); |
|
|
|
} |
|
|
|
|
|
|
|
std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const { |
|
|
|
BufferQueue& NVFlinger::FindBufferQueue(u32 id) { |
|
|
|
const auto itr = std::find_if(buffer_queues.begin(), buffer_queues.end(), |
|
|
|
[&](const auto& queue) { return queue->GetId() == id; }); |
|
|
|
[id](const auto& queue) { return queue.GetId() == id; }); |
|
|
|
|
|
|
|
ASSERT(itr != buffer_queues.end()); |
|
|
|
return *itr; |
|
|
|
} |
|
|
|
|
|
|
|
const BufferQueue& NVFlinger::FindBufferQueue(u32 id) const { |
|
|
|
const auto itr = std::find_if(buffer_queues.begin(), buffer_queues.end(), |
|
|
|
[id](const auto& queue) { return queue.GetId() == id; }); |
|
|
|
|
|
|
|
ASSERT(itr != buffer_queues.end()); |
|
|
|
return *itr; |
|
|
|
@ -112,7 +122,7 @@ std::shared_ptr<BufferQueue> NVFlinger::FindBufferQueue(u32 id) const { |
|
|
|
VI::Display* NVFlinger::FindDisplay(u64 display_id) { |
|
|
|
const auto itr = |
|
|
|
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()) { |
|
|
|
return nullptr; |
|
|
|
@ -124,7 +134,7 @@ VI::Display* NVFlinger::FindDisplay(u64 display_id) { |
|
|
|
const VI::Display* NVFlinger::FindDisplay(u64 display_id) const { |
|
|
|
const auto itr = |
|
|
|
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()) { |
|
|
|
return nullptr; |
|
|
|
@ -140,14 +150,7 @@ VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) { |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
const auto itr = std::find_if(display->layers.begin(), display->layers.end(), |
|
|
|
[&](const VI::Layer& layer) { return layer.id == layer_id; }); |
|
|
|
|
|
|
|
if (itr == display->layers.end()) { |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
return &*itr; |
|
|
|
return display->FindLayer(layer_id); |
|
|
|
} |
|
|
|
|
|
|
|
const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const { |
|
|
|
@ -157,33 +160,24 @@ const VI::Layer* NVFlinger::FindLayer(u64 display_id, u64 layer_id) const { |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
const auto itr = std::find_if(display->layers.begin(), display->layers.end(), |
|
|
|
[&](const VI::Layer& layer) { return layer.id == layer_id; }); |
|
|
|
|
|
|
|
if (itr == display->layers.end()) { |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
return &*itr; |
|
|
|
return display->FindLayer(layer_id); |
|
|
|
} |
|
|
|
|
|
|
|
void NVFlinger::Compose() { |
|
|
|
for (auto& display : displays) { |
|
|
|
// 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.
|
|
|
|
if (display.layers.empty()) |
|
|
|
if (!display.HasLayers()) |
|
|
|
continue; |
|
|
|
|
|
|
|
// TODO(Subv): Support more than 1 layer.
|
|
|
|
ASSERT_MSG(display.layers.size() == 1, "Max 1 layer per display is supported"); |
|
|
|
|
|
|
|
VI::Layer& layer = display.layers[0]; |
|
|
|
auto& buffer_queue = layer.buffer_queue; |
|
|
|
VI::Layer& layer = display.GetLayer(0); |
|
|
|
auto& buffer_queue = layer.GetBufferQueue(); |
|
|
|
|
|
|
|
// Search for a queued buffer and acquire it
|
|
|
|
auto buffer = buffer_queue->AcquireBuffer(); |
|
|
|
auto buffer = buffer_queue.AcquireBuffer(); |
|
|
|
|
|
|
|
MicroProfileFlip(); |
|
|
|
|
|
|
|
@ -208,7 +202,7 @@ void NVFlinger::Compose() { |
|
|
|
igbp_buffer.width, igbp_buffer.height, igbp_buffer.stride, |
|
|
|
buffer->get().transform, buffer->get().crop_rect); |
|
|
|
|
|
|
|
buffer_queue->ReleaseBuffer(buffer->get().slot); |
|
|
|
buffer_queue.ReleaseBuffer(buffer->get().slot); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|