2018-01-13 22:22:39 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2018-01-08 03:27:58 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
#include <memory>
|
2018-01-09 02:28:06 +01:00
|
|
|
#include <boost/optional.hpp>
|
2018-01-08 03:27:58 +01:00
|
|
|
#include "core/hle/kernel/event.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
2018-01-09 03:58:59 +01:00
|
|
|
namespace CoreTiming {
|
|
|
|
struct EventType;
|
|
|
|
}
|
|
|
|
|
2018-01-08 03:27:58 +01:00
|
|
|
namespace Service {
|
|
|
|
namespace VI {
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
struct IGBPBuffer {
|
|
|
|
u32_le magic;
|
|
|
|
u32_le width;
|
|
|
|
u32_le height;
|
|
|
|
u32_le stride;
|
|
|
|
u32_le format;
|
|
|
|
u32_le usage;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
|
|
|
u32_le index;
|
|
|
|
INSERT_PADDING_WORDS(3);
|
|
|
|
u32_le gpu_buffer_id;
|
|
|
|
INSERT_PADDING_WORDS(17);
|
|
|
|
u32_le nvmap_handle;
|
2018-01-09 03:30:22 +01:00
|
|
|
u32_le offset;
|
|
|
|
INSERT_PADDING_WORDS(60);
|
2018-01-09 00:18:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(IGBPBuffer) == 0x16C, "IGBPBuffer has wrong size");
|
|
|
|
|
|
|
|
class BufferQueue {
|
|
|
|
public:
|
2018-01-21 17:13:47 +01:00
|
|
|
enum class QueryType {
|
|
|
|
NativeWindowWidth = 0,
|
|
|
|
NativeWindowHeight = 1,
|
|
|
|
NativeWindowFormat = 2,
|
|
|
|
};
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
BufferQueue(u32 id, u64 layer_id);
|
|
|
|
~BufferQueue() = default;
|
|
|
|
|
2018-01-09 02:28:06 +01:00
|
|
|
struct Buffer {
|
|
|
|
enum class Status { Free = 0, Queued = 1, Dequeued = 2, Acquired = 3 };
|
|
|
|
|
|
|
|
u32 slot;
|
|
|
|
Status status = Status::Free;
|
|
|
|
IGBPBuffer igbp_buffer;
|
|
|
|
};
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
void SetPreallocatedBuffer(u32 slot, IGBPBuffer& buffer);
|
|
|
|
u32 DequeueBuffer(u32 pixel_format, u32 width, u32 height);
|
|
|
|
const IGBPBuffer& RequestBuffer(u32 slot) const;
|
|
|
|
void QueueBuffer(u32 slot);
|
2018-01-09 02:28:06 +01:00
|
|
|
boost::optional<const Buffer&> AcquireBuffer();
|
|
|
|
void ReleaseBuffer(u32 slot);
|
2018-01-21 17:13:47 +01:00
|
|
|
u32 Query(QueryType type);
|
2018-01-09 00:18:50 +01:00
|
|
|
|
2018-01-09 00:29:43 +01:00
|
|
|
u32 GetId() const {
|
|
|
|
return id;
|
|
|
|
}
|
2018-01-09 00:18:50 +01:00
|
|
|
|
2018-01-15 23:20:08 +01:00
|
|
|
Kernel::SharedPtr<Kernel::Event> GetNativeHandle() const {
|
|
|
|
return native_handle;
|
|
|
|
}
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
private:
|
|
|
|
u32 id;
|
|
|
|
u64 layer_id;
|
|
|
|
|
|
|
|
std::vector<Buffer> queue;
|
2018-01-15 23:20:08 +01:00
|
|
|
Kernel::SharedPtr<Kernel::Event> native_handle;
|
2018-01-09 00:18:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Layer {
|
|
|
|
Layer(u64 id, std::shared_ptr<BufferQueue> queue);
|
|
|
|
~Layer() = default;
|
|
|
|
|
|
|
|
u64 id;
|
|
|
|
std::shared_ptr<BufferQueue> buffer_queue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Display {
|
2018-01-09 00:29:43 +01:00
|
|
|
Display(u64 id, std::string name);
|
|
|
|
~Display() = default;
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
u64 id;
|
2018-01-09 00:29:43 +01:00
|
|
|
std::string name;
|
2018-01-09 00:18:50 +01:00
|
|
|
|
|
|
|
std::vector<Layer> layers;
|
2018-01-09 00:29:43 +01:00
|
|
|
Kernel::SharedPtr<Kernel::Event> vsync_event;
|
2018-01-09 00:18:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class NVFlinger {
|
|
|
|
public:
|
|
|
|
NVFlinger();
|
2018-01-09 01:12:28 +01:00
|
|
|
~NVFlinger();
|
2018-01-09 00:18:50 +01:00
|
|
|
|
|
|
|
/// Opens the specified display and returns the id.
|
|
|
|
u64 OpenDisplay(const std::string& name);
|
|
|
|
|
|
|
|
/// Creates a layer on the specified display and returns the layer id.
|
|
|
|
u64 CreateLayer(u64 display_id);
|
|
|
|
|
|
|
|
/// Gets the buffer queue id of the specified layer in the specified display.
|
|
|
|
u32 GetBufferQueueId(u64 display_id, u64 layer_id);
|
|
|
|
|
2018-01-09 00:29:43 +01:00
|
|
|
/// Gets the vsync event for the specified display.
|
|
|
|
Kernel::SharedPtr<Kernel::Event> GetVsyncEvent(u64 display_id);
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
/// Obtains a buffer queue identified by the id.
|
2018-01-09 00:29:43 +01:00
|
|
|
std::shared_ptr<BufferQueue> GetBufferQueue(u32 id) const;
|
2018-01-09 00:18:50 +01:00
|
|
|
|
2018-01-09 01:12:28 +01:00
|
|
|
/// Performs a composition request to the emulated nvidia GPU and triggers the vsync events when
|
|
|
|
/// finished.
|
|
|
|
void Compose();
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
private:
|
|
|
|
/// Returns the display identified by the specified id.
|
|
|
|
Display& GetDisplay(u64 display_id);
|
|
|
|
|
|
|
|
/// Returns the layer identified by the specified id in the desired display.
|
|
|
|
Layer& GetLayer(u64 display_id, u64 layer_id);
|
|
|
|
|
|
|
|
std::vector<Display> displays;
|
|
|
|
std::vector<std::shared_ptr<BufferQueue>> buffer_queues;
|
|
|
|
|
|
|
|
/// Id to use for the next layer that is created, this counter is shared among all displays.
|
|
|
|
u64 next_layer_id = 1;
|
|
|
|
/// Id to use for the next buffer queue that is created, this counter is shared among all
|
|
|
|
/// layers.
|
|
|
|
u32 next_buffer_queue_id = 1;
|
2018-01-09 01:12:28 +01:00
|
|
|
|
|
|
|
/// CoreTiming event that handles screen composition.
|
2018-01-09 03:58:59 +01:00
|
|
|
CoreTiming::EventType* composition_event;
|
2018-01-09 00:18:50 +01:00
|
|
|
};
|
|
|
|
|
2018-01-08 03:27:58 +01:00
|
|
|
class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> {
|
|
|
|
public:
|
2018-01-09 00:18:50 +01:00
|
|
|
IApplicationDisplayService(std::shared_ptr<NVFlinger> nv_flinger);
|
2018-01-08 03:27:58 +01:00
|
|
|
~IApplicationDisplayService() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GetRelayService(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetSystemDisplayService(Kernel::HLERequestContext& ctx);
|
|
|
|
void GetManagerDisplayService(Kernel::HLERequestContext& ctx);
|
2018-01-15 23:20:08 +01:00
|
|
|
void GetIndirectDisplayTransactionService(Kernel::HLERequestContext& ctx);
|
2018-01-08 03:27:58 +01:00
|
|
|
void OpenDisplay(Kernel::HLERequestContext& ctx);
|
2018-01-15 23:20:08 +01:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx);
|
2018-01-08 03:27:58 +01:00
|
|
|
void SetLayerScalingMode(Kernel::HLERequestContext& ctx);
|
|
|
|
void OpenLayer(Kernel::HLERequestContext& ctx);
|
2018-01-15 23:20:08 +01:00
|
|
|
void CreateStrayLayer(Kernel::HLERequestContext& ctx);
|
|
|
|
void DestroyStrayLayer(Kernel::HLERequestContext& ctx);
|
2018-01-08 03:27:58 +01:00
|
|
|
void GetDisplayVsyncEvent(Kernel::HLERequestContext& ctx);
|
|
|
|
|
2018-01-09 00:18:50 +01:00
|
|
|
std::shared_ptr<NVFlinger> nv_flinger;
|
2018-01-08 03:27:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Registers all VI services with the specified service manager.
|
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager);
|
|
|
|
|
|
|
|
} // namespace VI
|
|
|
|
} // namespace Service
|