aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/hle/service/nvnflinger
diff options
context:
space:
mode:
authorLiam <[email protected]>2024-02-19 09:47:19 -0500
committerLiam <[email protected]>2024-02-19 23:59:35 -0500
commit9f159dd62cbb1a4efe9c5cd724a94caf8c885793 (patch)
tree3b419db99ff18b0e7ea58789fd4767d888f3da58 /src/core/hle/service/nvnflinger
parentd1eaeeed8c2429547e584e1c8ef7abbdef1b7d36 (diff)
downloadyuzu-mainline-9f159dd62cbb1a4efe9c5cd724a94caf8c885793.tar.gz
yuzu-mainline-9f159dd62cbb1a4efe9c5cd724a94caf8c885793.zip
nvnflinger/vi: don't recreate buffer queue on open/close
Diffstat (limited to 'src/core/hle/service/nvnflinger')
-rw-r--r--src/core/hle/service/nvnflinger/display.h26
-rw-r--r--src/core/hle/service/nvnflinger/hardware_composer.cpp12
-rw-r--r--src/core/hle/service/nvnflinger/surface_flinger.cpp39
-rw-r--r--src/core/hle/service/nvnflinger/surface_flinger.h6
4 files changed, 50 insertions, 33 deletions
diff --git a/src/core/hle/service/nvnflinger/display.h b/src/core/hle/service/nvnflinger/display.h
index f27cbf144..40aa59787 100644
--- a/src/core/hle/service/nvnflinger/display.h
+++ b/src/core/hle/service/nvnflinger/display.h
@@ -3,8 +3,6 @@
#pragma once
-#include <list>
-
#include "core/hle/service/nvnflinger/buffer_item_consumer.h"
#include "core/hle/service/nvnflinger/hwc_layer.h"
@@ -26,18 +24,12 @@ struct Layer {
};
struct LayerStack {
- std::list<Layer> layers;
-};
-
-struct Display {
- explicit Display(u64 id_) {
- id = id_;
- }
+ std::vector<std::shared_ptr<Layer>> layers;
- Layer* FindLayer(s32 consumer_id) {
- for (auto& layer : stack.layers) {
- if (layer.consumer_id == consumer_id) {
- return &layer;
+ std::shared_ptr<Layer> FindLayer(s32 consumer_id) {
+ for (auto& layer : layers) {
+ if (layer->consumer_id == consumer_id) {
+ return layer;
}
}
@@ -45,7 +37,13 @@ struct Display {
}
bool HasLayers() {
- return !stack.layers.empty();
+ return !layers.empty();
+ }
+};
+
+struct Display {
+ explicit Display(u64 id_) {
+ id = id_;
}
u64 id;
diff --git a/src/core/hle/service/nvnflinger/hardware_composer.cpp b/src/core/hle/service/nvnflinger/hardware_composer.cpp
index 02215a786..f2dfe85a9 100644
--- a/src/core/hle/service/nvnflinger/hardware_composer.cpp
+++ b/src/core/hle/service/nvnflinger/hardware_composer.cpp
@@ -55,10 +55,10 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
// Acquire all necessary framebuffers.
for (auto& layer : display.stack.layers) {
- auto consumer_id = layer.consumer_id;
+ auto consumer_id = layer->consumer_id;
// Try to fetch the framebuffer (either new or stale).
- const auto result = this->CacheFramebufferLocked(layer, consumer_id);
+ const auto result = this->CacheFramebufferLocked(*layer, consumer_id);
// If we failed, skip this layer.
if (result == CacheStatus::NoBufferAvailable) {
@@ -75,7 +75,7 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
const auto& igbp_buffer = *item.graphic_buffer;
// TODO: get proper Z-index from layer
- if (layer.visible) {
+ if (layer->visible) {
composition_stack.emplace_back(HwcLayer{
.buffer_handle = igbp_buffer.BufferId(),
.offset = igbp_buffer.Offset(),
@@ -84,7 +84,7 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
.height = igbp_buffer.Height(),
.stride = igbp_buffer.Stride(),
.z_index = 0,
- .blending = layer.blending,
+ .blending = layer->blending,
.transform = static_cast<android::BufferTransformFlags>(item.transform),
.crop_rect = item.crop,
.acquire_fence = item.fence,
@@ -134,7 +134,7 @@ u32 HardwareComposer::ComposeLocked(f32* out_speed_scale, Display& display,
continue;
}
- if (auto* layer = display.FindLayer(layer_id); layer != nullptr) {
+ if (const auto layer = display.stack.FindLayer(layer_id); layer != nullptr) {
// TODO: support release fence
// This is needed to prevent screen tearing
layer->buffer_item_consumer->ReleaseBuffer(framebuffer.item, android::Fence::NoFence());
@@ -153,7 +153,7 @@ void HardwareComposer::RemoveLayerLocked(Display& display, ConsumerId consumer_i
}
// Try to release the buffer item.
- auto* const layer = display.FindLayer(consumer_id);
+ const auto layer = display.stack.FindLayer(consumer_id);
if (layer && it->second.is_acquired) {
layer->buffer_item_consumer->ReleaseBuffer(it->second.item, android::Fence::NoFence());
}
diff --git a/src/core/hle/service/nvnflinger/surface_flinger.cpp b/src/core/hle/service/nvnflinger/surface_flinger.cpp
index 41a705717..8362b65e5 100644
--- a/src/core/hle/service/nvnflinger/surface_flinger.cpp
+++ b/src/core/hle/service/nvnflinger/surface_flinger.cpp
@@ -36,7 +36,7 @@ void SurfaceFlinger::RemoveDisplay(u64 display_id) {
bool SurfaceFlinger::ComposeDisplay(s32* out_swap_interval, f32* out_compose_speed_scale,
u64 display_id) {
auto* const display = this->FindDisplay(display_id);
- if (!display || !display->HasLayers()) {
+ if (!display || !display->stack.HasLayers()) {
return false;
}
@@ -46,19 +46,34 @@ bool SurfaceFlinger::ComposeDisplay(s32* out_swap_interval, f32* out_compose_spe
return true;
}
-void SurfaceFlinger::AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id) {
- auto* const display = this->FindDisplay(display_id);
+void SurfaceFlinger::CreateLayer(s32 consumer_binder_id) {
auto binder = std::static_pointer_cast<android::BufferQueueConsumer>(
m_server.TryGetBinder(consumer_binder_id));
-
- if (!display || !binder) {
+ if (!binder) {
return;
}
auto buffer_item_consumer = std::make_shared<android::BufferItemConsumer>(std::move(binder));
buffer_item_consumer->Connect(false);
- display->stack.layers.emplace_back(std::move(buffer_item_consumer), consumer_binder_id);
+ m_layers.layers.emplace_back(
+ std::make_shared<Layer>(std::move(buffer_item_consumer), consumer_binder_id));
+}
+
+void SurfaceFlinger::DestroyLayer(s32 consumer_binder_id) {
+ std::erase_if(m_layers.layers,
+ [&](auto& layer) { return layer->consumer_id == consumer_binder_id; });
+}
+
+void SurfaceFlinger::AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id) {
+ auto* const display = this->FindDisplay(display_id);
+ auto layer = this->FindLayer(consumer_binder_id);
+
+ if (!display || !layer) {
+ return;
+ }
+
+ display->stack.layers.emplace_back(std::move(layer));
}
void SurfaceFlinger::RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_binder_id) {
@@ -69,18 +84,18 @@ void SurfaceFlinger::RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_bi
m_composer.RemoveLayerLocked(*display, consumer_binder_id);
std::erase_if(display->stack.layers,
- [&](auto& layer) { return layer.consumer_id == consumer_binder_id; });
+ [&](auto& layer) { return layer->consumer_id == consumer_binder_id; });
}
void SurfaceFlinger::SetLayerVisibility(s32 consumer_binder_id, bool visible) {
- if (auto* layer = this->FindLayer(consumer_binder_id); layer != nullptr) {
+ if (const auto layer = this->FindLayer(consumer_binder_id); layer != nullptr) {
layer->visible = visible;
return;
}
}
void SurfaceFlinger::SetLayerBlending(s32 consumer_binder_id, LayerBlending blending) {
- if (auto* layer = this->FindLayer(consumer_binder_id); layer != nullptr) {
+ if (const auto layer = this->FindLayer(consumer_binder_id); layer != nullptr) {
layer->blending = blending;
return;
}
@@ -96,9 +111,9 @@ Display* SurfaceFlinger::FindDisplay(u64 display_id) {
return nullptr;
}
-Layer* SurfaceFlinger::FindLayer(s32 consumer_binder_id) {
- for (auto& display : m_displays) {
- if (auto* layer = display.FindLayer(consumer_binder_id); layer != nullptr) {
+std::shared_ptr<Layer> SurfaceFlinger::FindLayer(s32 consumer_binder_id) {
+ for (auto& layer : m_layers.layers) {
+ if (layer->consumer_id == consumer_binder_id) {
return layer;
}
}
diff --git a/src/core/hle/service/nvnflinger/surface_flinger.h b/src/core/hle/service/nvnflinger/surface_flinger.h
index d8c53fbda..406281c83 100644
--- a/src/core/hle/service/nvnflinger/surface_flinger.h
+++ b/src/core/hle/service/nvnflinger/surface_flinger.h
@@ -36,6 +36,9 @@ public:
void RemoveDisplay(u64 display_id);
bool ComposeDisplay(s32* out_swap_interval, f32* out_compose_speed_scale, u64 display_id);
+ void CreateLayer(s32 consumer_binder_id);
+ void DestroyLayer(s32 consumer_binder_id);
+
void AddLayerToDisplayStack(u64 display_id, s32 consumer_binder_id);
void RemoveLayerFromDisplayStack(u64 display_id, s32 consumer_binder_id);
@@ -44,7 +47,7 @@ public:
private:
Display* FindDisplay(u64 display_id);
- Layer* FindLayer(s32 consumer_binder_id);
+ std::shared_ptr<Layer> FindLayer(s32 consumer_binder_id);
public:
// TODO: these don't belong here
@@ -57,6 +60,7 @@ private:
KernelHelpers::ServiceContext m_context;
std::vector<Display> m_displays;
+ LayerStack m_layers;
std::shared_ptr<Nvidia::Module> nvdrv;
s32 disp_fd;
HardwareComposer m_composer;