2018-01-13 16:22:39 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2018-01-07 21:27:58 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-01-11 22:36:56 -05:00
|
|
|
#include <algorithm>
|
2018-02-11 19:03:31 -05:00
|
|
|
#include <array>
|
2018-03-21 06:09:40 -04:00
|
|
|
#include <memory>
|
|
|
|
#include <boost/optional.hpp>
|
2018-01-07 21:27:58 -05:00
|
|
|
#include "common/alignment.h"
|
2018-01-08 20:28:06 -05:00
|
|
|
#include "common/scope_exit.h"
|
2018-01-08 19:12:28 -05:00
|
|
|
#include "core/core_timing.h"
|
2018-01-07 21:27:58 -05:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2018-03-21 06:09:40 -04:00
|
|
|
#include "core/hle/kernel/event.h"
|
2018-02-13 22:12:46 -05:00
|
|
|
#include "core/hle/service/nvdrv/nvdrv.h"
|
2018-01-22 11:54:58 -05:00
|
|
|
#include "core/hle/service/nvflinger/buffer_queue.h"
|
2018-01-07 21:27:58 -05:00
|
|
|
#include "core/hle/service/vi/vi.h"
|
|
|
|
#include "core/hle/service/vi/vi_m.h"
|
2018-02-02 04:59:50 -05:00
|
|
|
#include "core/hle/service/vi/vi_s.h"
|
|
|
|
#include "core/hle/service/vi/vi_u.h"
|
2018-04-02 23:28:45 -04:00
|
|
|
#include "core/settings.h"
|
2018-01-14 23:51:54 -05:00
|
|
|
#include "video_core/renderer_base.h"
|
|
|
|
#include "video_core/video_core.h"
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::VI {
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-02-07 07:11:17 -05:00
|
|
|
struct DisplayInfo {
|
|
|
|
char display_name[0x40]{"Default"};
|
|
|
|
u64 unknown_1{1};
|
|
|
|
u64 unknown_2{1};
|
|
|
|
u64 width{1920};
|
|
|
|
u64 height{1080};
|
|
|
|
};
|
|
|
|
static_assert(sizeof(DisplayInfo) == 0x60, "DisplayInfo has wrong size");
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
class Parcel {
|
|
|
|
public:
|
|
|
|
// This default size was chosen arbitrarily.
|
|
|
|
static constexpr size_t DefaultBufferSize = 0x40;
|
|
|
|
Parcel() : buffer(DefaultBufferSize) {}
|
2018-01-17 20:21:14 -05:00
|
|
|
explicit Parcel(std::vector<u8> data) : buffer(std::move(data)) {}
|
2018-01-07 21:27:58 -05:00
|
|
|
virtual ~Parcel() = default;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T Read() {
|
2018-02-17 13:54:59 -05:00
|
|
|
ASSERT(read_index + sizeof(T) <= buffer.size());
|
2018-01-07 21:27:58 -05:00
|
|
|
T val;
|
|
|
|
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
|
|
|
|
read_index += sizeof(T);
|
|
|
|
read_index = Common::AlignUp(read_index, 4);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T ReadUnaligned() {
|
2018-02-17 13:54:59 -05:00
|
|
|
ASSERT(read_index + sizeof(T) <= buffer.size());
|
2018-01-07 21:27:58 -05:00
|
|
|
T val;
|
|
|
|
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
|
|
|
|
read_index += sizeof(T);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u8> ReadBlock(size_t length) {
|
2018-02-17 13:54:59 -05:00
|
|
|
ASSERT(read_index + length <= buffer.size());
|
2018-01-17 20:08:02 -05:00
|
|
|
const u8* const begin = buffer.data() + read_index;
|
|
|
|
const u8* const end = begin + length;
|
|
|
|
std::vector<u8> data(begin, end);
|
2018-01-07 21:27:58 -05:00
|
|
|
read_index += length;
|
|
|
|
read_index = Common::AlignUp(read_index, 4);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::u16string ReadInterfaceToken() {
|
|
|
|
u32 unknown = Read<u32_le>();
|
|
|
|
u32 length = Read<u32_le>();
|
|
|
|
|
|
|
|
std::u16string token{};
|
|
|
|
|
|
|
|
for (u32 ch = 0; ch < length + 1; ++ch) {
|
|
|
|
token.push_back(ReadUnaligned<u16_le>());
|
|
|
|
}
|
|
|
|
|
|
|
|
read_index = Common::AlignUp(read_index, 4);
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void Write(const T& val) {
|
|
|
|
if (buffer.size() < write_index + sizeof(T))
|
|
|
|
buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize);
|
|
|
|
std::memcpy(buffer.data() + write_index, &val, sizeof(T));
|
|
|
|
write_index += sizeof(T);
|
|
|
|
write_index = Common::AlignUp(write_index, 4);
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:12:46 -05:00
|
|
|
template <typename T>
|
|
|
|
void WriteObject(const T& val) {
|
|
|
|
u32_le size = static_cast<u32>(sizeof(val));
|
|
|
|
Write(size);
|
|
|
|
// TODO(Subv): Support file descriptors.
|
|
|
|
Write<u32_le>(0); // Fd count.
|
|
|
|
Write(val);
|
|
|
|
}
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
void Deserialize() {
|
2018-02-17 13:54:59 -05:00
|
|
|
ASSERT(buffer.size() > sizeof(Header));
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
Header header{};
|
|
|
|
std::memcpy(&header, buffer.data(), sizeof(Header));
|
|
|
|
|
|
|
|
read_index = header.data_offset;
|
|
|
|
DeserializeData();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u8> Serialize() {
|
|
|
|
ASSERT(read_index == 0);
|
|
|
|
write_index = sizeof(Header);
|
|
|
|
|
|
|
|
SerializeData();
|
|
|
|
|
|
|
|
Header header{};
|
2018-01-19 18:01:41 -05:00
|
|
|
header.data_size = static_cast<u32_le>(write_index - sizeof(Header));
|
2018-02-11 17:28:07 -05:00
|
|
|
header.data_offset = sizeof(Header);
|
|
|
|
header.objects_size = 4;
|
|
|
|
header.objects_offset = sizeof(Header) + header.data_size;
|
2018-01-07 21:27:58 -05:00
|
|
|
std::memcpy(buffer.data(), &header, sizeof(Header));
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-01-17 20:16:48 -05:00
|
|
|
virtual void SerializeData() {}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-01-17 20:16:48 -05:00
|
|
|
virtual void DeserializeData() {}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct Header {
|
|
|
|
u32_le data_size;
|
|
|
|
u32_le data_offset;
|
|
|
|
u32_le objects_size;
|
|
|
|
u32_le objects_offset;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(Header) == 16, "ParcelHeader has wrong size");
|
|
|
|
|
|
|
|
std::vector<u8> buffer;
|
|
|
|
size_t read_index = 0;
|
|
|
|
size_t write_index = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NativeWindow : public Parcel {
|
|
|
|
public:
|
2018-04-19 21:34:36 -04:00
|
|
|
explicit NativeWindow(u32 id) {
|
2018-01-07 21:27:58 -05:00
|
|
|
data.id = id;
|
|
|
|
}
|
|
|
|
~NativeWindow() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
|
|
|
Write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Data {
|
|
|
|
u32_le magic = 2;
|
2018-02-11 17:28:07 -05:00
|
|
|
u32_le process_id = 1;
|
2018-01-07 21:27:58 -05:00
|
|
|
u32_le id;
|
2018-02-11 17:28:07 -05:00
|
|
|
INSERT_PADDING_WORDS(3);
|
2018-01-18 21:21:26 -05:00
|
|
|
std::array<u8, 8> dispdrv = {'d', 'i', 's', 'p', 'd', 'r', 'v', '\0'};
|
2018-02-11 17:28:07 -05:00
|
|
|
INSERT_PADDING_WORDS(2);
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
static_assert(sizeof(Data) == 0x28, "ParcelData has wrong size");
|
|
|
|
|
|
|
|
Data data{};
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPConnectRequestParcel : public Parcel {
|
|
|
|
public:
|
2018-01-17 20:21:14 -05:00
|
|
|
explicit IGBPConnectRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
2018-01-07 21:27:58 -05:00
|
|
|
Deserialize();
|
|
|
|
}
|
|
|
|
~IGBPConnectRequestParcel() override = default;
|
|
|
|
|
2018-01-17 20:16:48 -05:00
|
|
|
void DeserializeData() override {
|
2018-01-07 21:27:58 -05:00
|
|
|
std::u16string token = ReadInterfaceToken();
|
|
|
|
data = Read<Data>();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
u32_le unk;
|
|
|
|
u32_le api;
|
|
|
|
u32_le producer_controlled_by_app;
|
|
|
|
};
|
|
|
|
|
|
|
|
Data data;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPConnectResponseParcel : public Parcel {
|
|
|
|
public:
|
2018-04-19 21:34:36 -04:00
|
|
|
explicit IGBPConnectResponseParcel(u32 width, u32 height) {
|
2018-01-07 21:27:58 -05:00
|
|
|
data.width = width;
|
|
|
|
data.height = height;
|
|
|
|
}
|
|
|
|
~IGBPConnectResponseParcel() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
|
|
|
Write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Data {
|
|
|
|
u32_le width;
|
|
|
|
u32_le height;
|
|
|
|
u32_le transform_hint;
|
|
|
|
u32_le num_pending_buffers;
|
|
|
|
u32_le status;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(Data) == 20, "ParcelData has wrong size");
|
|
|
|
|
|
|
|
Data data{};
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPSetPreallocatedBufferRequestParcel : public Parcel {
|
|
|
|
public:
|
2018-01-17 20:21:14 -05:00
|
|
|
explicit IGBPSetPreallocatedBufferRequestParcel(const std::vector<u8>& buffer)
|
|
|
|
: Parcel(buffer) {
|
2018-01-07 21:27:58 -05:00
|
|
|
Deserialize();
|
|
|
|
}
|
|
|
|
~IGBPSetPreallocatedBufferRequestParcel() override = default;
|
|
|
|
|
2018-01-17 20:16:48 -05:00
|
|
|
void DeserializeData() override {
|
2018-01-07 21:27:58 -05:00
|
|
|
std::u16string token = ReadInterfaceToken();
|
|
|
|
data = Read<Data>();
|
2018-01-22 11:54:58 -05:00
|
|
|
buffer = Read<NVFlinger::IGBPBuffer>();
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
u32_le slot;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
|
|
|
u32_le graphic_buffer_length;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
Data data;
|
2018-01-22 11:54:58 -05:00
|
|
|
NVFlinger::IGBPBuffer buffer;
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPSetPreallocatedBufferResponseParcel : public Parcel {
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
|
|
|
// TODO(Subv): Find out what this means
|
|
|
|
Write<u32>(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPDequeueBufferRequestParcel : public Parcel {
|
|
|
|
public:
|
2018-01-17 20:21:14 -05:00
|
|
|
explicit IGBPDequeueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
2018-01-07 21:27:58 -05:00
|
|
|
Deserialize();
|
|
|
|
}
|
|
|
|
~IGBPDequeueBufferRequestParcel() override = default;
|
|
|
|
|
2018-01-17 20:16:48 -05:00
|
|
|
void DeserializeData() override {
|
2018-01-07 21:27:58 -05:00
|
|
|
std::u16string token = ReadInterfaceToken();
|
|
|
|
data = Read<Data>();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
u32_le pixel_format;
|
|
|
|
u32_le width;
|
|
|
|
u32_le height;
|
|
|
|
u32_le get_frame_timestamps;
|
|
|
|
u32_le usage;
|
|
|
|
};
|
|
|
|
|
|
|
|
Data data;
|
|
|
|
};
|
|
|
|
|
2018-02-13 22:12:46 -05:00
|
|
|
struct BufferProducerFence {
|
|
|
|
u32 is_valid;
|
|
|
|
std::array<Nvidia::IoctlFence, 4> fences;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(BufferProducerFence) == 36, "BufferProducerFence has wrong size");
|
2018-02-12 21:17:04 -05:00
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
class IGBPDequeueBufferResponseParcel : public Parcel {
|
|
|
|
public:
|
2018-04-19 21:34:36 -04:00
|
|
|
explicit IGBPDequeueBufferResponseParcel(u32 slot) : slot(slot) {}
|
2018-01-07 21:27:58 -05:00
|
|
|
~IGBPDequeueBufferResponseParcel() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
2018-02-13 22:12:46 -05:00
|
|
|
// TODO(Subv): Find out how this Fence is used.
|
|
|
|
BufferProducerFence fence = {};
|
2018-02-13 23:03:02 -05:00
|
|
|
fence.is_valid = 1;
|
2018-02-17 14:00:30 -05:00
|
|
|
for (auto& fence_ : fence.fences)
|
|
|
|
fence_.id = -1;
|
2018-02-13 22:12:46 -05:00
|
|
|
|
|
|
|
Write(slot);
|
2018-02-13 22:51:24 -05:00
|
|
|
Write<u32_le>(1);
|
2018-02-13 22:12:46 -05:00
|
|
|
WriteObject(fence);
|
|
|
|
Write<u32_le>(0);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
u32_le slot;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPRequestBufferRequestParcel : public Parcel {
|
|
|
|
public:
|
2018-01-17 20:21:14 -05:00
|
|
|
explicit IGBPRequestBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
2018-01-07 21:27:58 -05:00
|
|
|
Deserialize();
|
|
|
|
}
|
|
|
|
~IGBPRequestBufferRequestParcel() override = default;
|
|
|
|
|
2018-01-17 20:16:48 -05:00
|
|
|
void DeserializeData() override {
|
2018-01-07 21:27:58 -05:00
|
|
|
std::u16string token = ReadInterfaceToken();
|
|
|
|
slot = Read<u32_le>();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32_le slot;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPRequestBufferResponseParcel : public Parcel {
|
|
|
|
public:
|
2018-01-22 11:54:58 -05:00
|
|
|
explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer)
|
|
|
|
: Parcel(), buffer(buffer) {}
|
2018-01-07 21:27:58 -05:00
|
|
|
~IGBPRequestBufferResponseParcel() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
2018-02-13 22:23:53 -05:00
|
|
|
// TODO(Subv): Figure out what this value means, writing non-zero here will make libnx try
|
|
|
|
// to read an IGBPBuffer object from the parcel.
|
2018-02-17 13:59:45 -05:00
|
|
|
Write<u32_le>(1);
|
|
|
|
WriteObject(buffer);
|
2018-01-07 21:27:58 -05:00
|
|
|
Write<u32_le>(0);
|
|
|
|
}
|
|
|
|
|
2018-01-22 11:54:58 -05:00
|
|
|
NVFlinger::IGBPBuffer buffer;
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPQueueBufferRequestParcel : public Parcel {
|
|
|
|
public:
|
2018-01-17 20:21:14 -05:00
|
|
|
explicit IGBPQueueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
2018-01-07 21:27:58 -05:00
|
|
|
Deserialize();
|
|
|
|
}
|
|
|
|
~IGBPQueueBufferRequestParcel() override = default;
|
|
|
|
|
2018-01-17 20:16:48 -05:00
|
|
|
void DeserializeData() override {
|
2018-01-07 21:27:58 -05:00
|
|
|
std::u16string token = ReadInterfaceToken();
|
|
|
|
data = Read<Data>();
|
|
|
|
}
|
|
|
|
|
2018-02-11 19:03:31 -05:00
|
|
|
struct Fence {
|
|
|
|
u32_le id;
|
|
|
|
u32_le value;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(Fence) == 8, "Fence has wrong size");
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
struct Data {
|
|
|
|
u32_le slot;
|
2018-02-11 19:03:31 -05:00
|
|
|
INSERT_PADDING_WORDS(3);
|
2018-01-07 21:27:58 -05:00
|
|
|
u32_le timestamp;
|
2018-02-11 19:03:31 -05:00
|
|
|
s32_le is_auto_timestamp;
|
|
|
|
s32_le crop_left;
|
|
|
|
s32_le crop_top;
|
|
|
|
s32_le crop_right;
|
|
|
|
s32_le crop_bottom;
|
|
|
|
s32_le scaling_mode;
|
|
|
|
NVFlinger::BufferQueue::BufferTransformFlags transform;
|
|
|
|
u32_le sticky_transform;
|
|
|
|
INSERT_PADDING_WORDS(2);
|
|
|
|
u32_le fence_is_valid;
|
|
|
|
std::array<Fence, 2> fences;
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
2018-02-11 19:03:31 -05:00
|
|
|
static_assert(sizeof(Data) == 80, "ParcelData has wrong size");
|
2018-01-07 21:27:58 -05:00
|
|
|
|
|
|
|
Data data;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPQueueBufferResponseParcel : public Parcel {
|
|
|
|
public:
|
2018-04-19 21:34:36 -04:00
|
|
|
explicit IGBPQueueBufferResponseParcel(u32 width, u32 height) {
|
2018-01-07 21:27:58 -05:00
|
|
|
data.width = width;
|
|
|
|
data.height = height;
|
|
|
|
}
|
|
|
|
~IGBPQueueBufferResponseParcel() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
|
|
|
Write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Data {
|
|
|
|
u32_le width;
|
|
|
|
u32_le height;
|
|
|
|
u32_le transform_hint;
|
|
|
|
u32_le num_pending_buffers;
|
|
|
|
u32_le status;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(Data) == 20, "ParcelData has wrong size");
|
|
|
|
|
|
|
|
Data data{};
|
|
|
|
};
|
|
|
|
|
2018-01-21 11:13:47 -05:00
|
|
|
class IGBPQueryRequestParcel : public Parcel {
|
|
|
|
public:
|
|
|
|
explicit IGBPQueryRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
|
|
|
Deserialize();
|
|
|
|
}
|
|
|
|
~IGBPQueryRequestParcel() override = default;
|
|
|
|
|
|
|
|
void DeserializeData() override {
|
|
|
|
std::u16string token = ReadInterfaceToken();
|
|
|
|
type = Read<u32_le>();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IGBPQueryResponseParcel : public Parcel {
|
|
|
|
public:
|
2018-04-19 21:34:36 -04:00
|
|
|
explicit IGBPQueryResponseParcel(u32 value) : value(value) {}
|
2018-01-21 11:13:47 -05:00
|
|
|
~IGBPQueryResponseParcel() override = default;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void SerializeData() override {
|
|
|
|
Write(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u32_le value;
|
|
|
|
};
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> {
|
|
|
|
public:
|
2018-01-22 11:54:58 -05:00
|
|
|
explicit IHOSBinderDriver(std::shared_ptr<NVFlinger::NVFlinger> nv_flinger)
|
2018-01-08 18:18:50 -05:00
|
|
|
: ServiceFramework("IHOSBinderDriver"), nv_flinger(std::move(nv_flinger)) {
|
2018-01-07 21:27:58 -05:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &IHOSBinderDriver::TransactParcel, "TransactParcel"},
|
|
|
|
{1, &IHOSBinderDriver::AdjustRefcount, "AdjustRefcount"},
|
2018-01-15 17:20:08 -05:00
|
|
|
{2, &IHOSBinderDriver::GetNativeHandle, "GetNativeHandle"},
|
2018-02-13 21:39:58 -05:00
|
|
|
{3, &IHOSBinderDriver::TransactParcel, "TransactParcelAuto"},
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
~IHOSBinderDriver() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class TransactionId {
|
|
|
|
RequestBuffer = 1,
|
|
|
|
SetBufferCount = 2,
|
|
|
|
DequeueBuffer = 3,
|
|
|
|
DetachBuffer = 4,
|
|
|
|
DetachNextBuffer = 5,
|
|
|
|
AttachBuffer = 6,
|
|
|
|
QueueBuffer = 7,
|
|
|
|
CancelBuffer = 8,
|
|
|
|
Query = 9,
|
|
|
|
Connect = 10,
|
|
|
|
Disconnect = 11,
|
|
|
|
|
|
|
|
AllocateBuffers = 13,
|
|
|
|
SetPreallocatedBuffer = 14
|
|
|
|
};
|
|
|
|
|
2018-02-13 21:54:12 -05:00
|
|
|
void TransactParcel(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 id = rp.Pop<u32>();
|
|
|
|
auto transaction = static_cast<TransactionId>(rp.Pop<u32>());
|
|
|
|
u32 flags = rp.Pop<u32>();
|
2018-01-08 18:18:50 -05:00
|
|
|
auto buffer_queue = nv_flinger->GetBufferQueue(id);
|
2018-02-12 19:40:19 -05:00
|
|
|
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_DEBUG(Service_VI, "called, transaction={:X}", static_cast<u32>(transaction));
|
2018-02-13 21:54:12 -05:00
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
if (transaction == TransactionId::Connect) {
|
2018-02-13 21:54:12 -05:00
|
|
|
IGBPConnectRequestParcel request{ctx.ReadBuffer()};
|
2018-01-07 21:27:58 -05:00
|
|
|
IGBPConnectResponseParcel response{1280, 720};
|
2018-02-13 21:54:12 -05:00
|
|
|
ctx.WriteBuffer(response.Serialize());
|
2018-01-07 21:27:58 -05:00
|
|
|
} else if (transaction == TransactionId::SetPreallocatedBuffer) {
|
2018-02-13 21:54:12 -05:00
|
|
|
IGBPSetPreallocatedBufferRequestParcel request{ctx.ReadBuffer()};
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-01-08 18:18:50 -05:00
|
|
|
buffer_queue->SetPreallocatedBuffer(request.data.slot, request.buffer);
|
2018-01-07 21:27:58 -05:00
|
|
|
|
|
|
|
IGBPSetPreallocatedBufferResponseParcel response{};
|
2018-02-13 21:54:12 -05:00
|
|
|
ctx.WriteBuffer(response.Serialize());
|
2018-01-07 21:27:58 -05:00
|
|
|
} else if (transaction == TransactionId::DequeueBuffer) {
|
2018-02-13 21:54:12 -05:00
|
|
|
IGBPDequeueBufferRequestParcel request{ctx.ReadBuffer()};
|
2018-03-18 20:27:15 -04:00
|
|
|
const u32 width{request.data.width};
|
|
|
|
const u32 height{request.data.height};
|
|
|
|
boost::optional<u32> slot = buffer_queue->DequeueBuffer(width, height);
|
|
|
|
|
|
|
|
if (slot != boost::none) {
|
|
|
|
// Buffer is available
|
|
|
|
IGBPDequeueBufferResponseParcel response{*slot};
|
|
|
|
ctx.WriteBuffer(response.Serialize());
|
|
|
|
} else {
|
|
|
|
// Wait the current thread until a buffer becomes available
|
|
|
|
auto wait_event = ctx.SleepClientThread(
|
|
|
|
Kernel::GetCurrentThread(), "IHOSBinderDriver::DequeueBuffer", -1,
|
|
|
|
[=](Kernel::SharedPtr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
|
|
|
|
ThreadWakeupReason reason) {
|
|
|
|
// Repeat TransactParcel DequeueBuffer when a buffer is available
|
|
|
|
auto buffer_queue = nv_flinger->GetBufferQueue(id);
|
|
|
|
boost::optional<u32> slot = buffer_queue->DequeueBuffer(width, height);
|
|
|
|
IGBPDequeueBufferResponseParcel response{*slot};
|
|
|
|
ctx.WriteBuffer(response.Serialize());
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
});
|
|
|
|
buffer_queue->SetBufferWaitEvent(std::move(wait_event));
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
} else if (transaction == TransactionId::RequestBuffer) {
|
2018-02-13 21:54:12 -05:00
|
|
|
IGBPRequestBufferRequestParcel request{ctx.ReadBuffer()};
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-01-08 18:18:50 -05:00
|
|
|
auto& buffer = buffer_queue->RequestBuffer(request.slot);
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
IGBPRequestBufferResponseParcel response{buffer};
|
2018-02-13 21:54:12 -05:00
|
|
|
ctx.WriteBuffer(response.Serialize());
|
2018-01-07 21:27:58 -05:00
|
|
|
} else if (transaction == TransactionId::QueueBuffer) {
|
2018-02-13 21:54:12 -05:00
|
|
|
IGBPQueueBufferRequestParcel request{ctx.ReadBuffer()};
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-02-11 19:03:31 -05:00
|
|
|
buffer_queue->QueueBuffer(request.data.slot, request.data.transform);
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
IGBPQueueBufferResponseParcel response{1280, 720};
|
2018-02-13 21:54:12 -05:00
|
|
|
ctx.WriteBuffer(response.Serialize());
|
2018-01-21 11:13:47 -05:00
|
|
|
} else if (transaction == TransactionId::Query) {
|
2018-02-13 21:54:12 -05:00
|
|
|
IGBPQueryRequestParcel request{ctx.ReadBuffer()};
|
2018-01-21 11:13:47 -05:00
|
|
|
|
2018-01-22 11:54:58 -05:00
|
|
|
u32 value =
|
|
|
|
buffer_queue->Query(static_cast<NVFlinger::BufferQueue::QueryType>(request.type));
|
2018-01-21 11:13:47 -05:00
|
|
|
|
|
|
|
IGBPQueryResponseParcel response{value};
|
2018-02-13 21:54:12 -05:00
|
|
|
ctx.WriteBuffer(response.Serialize());
|
2018-02-12 21:15:53 -05:00
|
|
|
} else if (transaction == TransactionId::CancelBuffer) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called, transaction=CancelBuffer");
|
2018-01-07 21:27:58 -05:00
|
|
|
} else {
|
|
|
|
ASSERT_MSG(false, "Unimplemented");
|
|
|
|
}
|
2018-02-09 22:50:29 -05:00
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2018-01-07 21:27:58 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdjustRefcount(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 id = rp.Pop<u32>();
|
|
|
|
s32 addval = rp.PopRaw<s32>();
|
|
|
|
u32 type = rp.Pop<u32>();
|
|
|
|
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={:08X}, type={:08X}", id, addval,
|
2018-07-02 12:20:50 -04:00
|
|
|
type);
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2018-01-07 21:27:58 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-01-15 17:20:08 -05:00
|
|
|
void GetNativeHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 id = rp.Pop<u32>();
|
|
|
|
u32 unknown = rp.Pop<u32>();
|
|
|
|
|
|
|
|
auto buffer_queue = nv_flinger->GetBufferQueue(id);
|
|
|
|
|
|
|
|
// TODO(Subv): Find out what this actually is.
|
|
|
|
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called id={}, unknown={:08X}", id, unknown);
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2018-01-15 17:20:08 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(buffer_queue->GetNativeHandle());
|
|
|
|
}
|
|
|
|
|
2018-01-22 11:54:58 -05:00
|
|
|
std::shared_ptr<NVFlinger::NVFlinger> nv_flinger;
|
2018-02-12 21:17:04 -05:00
|
|
|
}; // namespace VI
|
2018-01-07 21:27:58 -05:00
|
|
|
|
|
|
|
class ISystemDisplayService final : public ServiceFramework<ISystemDisplayService> {
|
|
|
|
public:
|
|
|
|
ISystemDisplayService() : ServiceFramework("ISystemDisplayService") {
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{1200, nullptr, "GetZOrderCountMin"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{1202, nullptr, "GetZOrderCountMax"},
|
|
|
|
{1203, nullptr, "GetDisplayLogicalResolution"},
|
|
|
|
{1204, nullptr, "SetDisplayMagnification"},
|
|
|
|
{2201, nullptr, "SetLayerPosition"},
|
|
|
|
{2203, nullptr, "SetLayerSize"},
|
|
|
|
{2204, nullptr, "GetLayerZ"},
|
2018-01-07 21:27:58 -05:00
|
|
|
{2205, &ISystemDisplayService::SetLayerZ, "SetLayerZ"},
|
2018-04-16 05:04:34 -04:00
|
|
|
{2207, &ISystemDisplayService::SetLayerVisibility, "SetLayerVisibility"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{2209, nullptr, "SetLayerAlpha"},
|
|
|
|
{2312, nullptr, "CreateStrayLayer"},
|
|
|
|
{2400, nullptr, "OpenIndirectLayer"},
|
|
|
|
{2401, nullptr, "CloseIndirectLayer"},
|
|
|
|
{2402, nullptr, "FlipIndirectLayer"},
|
|
|
|
{3000, nullptr, "ListDisplayModes"},
|
|
|
|
{3001, nullptr, "ListDisplayRgbRanges"},
|
|
|
|
{3002, nullptr, "ListDisplayContentTypes"},
|
|
|
|
{3200, nullptr, "GetDisplayMode"},
|
|
|
|
{3201, nullptr, "SetDisplayMode"},
|
|
|
|
{3202, nullptr, "GetDisplayUnderscan"},
|
|
|
|
{3203, nullptr, "SetDisplayUnderscan"},
|
|
|
|
{3204, nullptr, "GetDisplayContentType"},
|
|
|
|
{3205, nullptr, "SetDisplayContentType"},
|
|
|
|
{3206, nullptr, "GetDisplayRgbRange"},
|
|
|
|
{3207, nullptr, "SetDisplayRgbRange"},
|
|
|
|
{3208, nullptr, "GetDisplayCmuMode"},
|
|
|
|
{3209, nullptr, "SetDisplayCmuMode"},
|
|
|
|
{3210, nullptr, "GetDisplayContrastRatio"},
|
|
|
|
{3211, nullptr, "SetDisplayContrastRatio"},
|
|
|
|
{3214, nullptr, "GetDisplayGamma"},
|
|
|
|
{3215, nullptr, "SetDisplayGamma"},
|
|
|
|
{3216, nullptr, "GetDisplayCmuLuma"},
|
|
|
|
{3217, nullptr, "SetDisplayCmuLuma"},
|
|
|
|
{8225, nullptr, "GetSharedBufferMemoryHandleId"},
|
|
|
|
{8250, nullptr, "OpenSharedLayer"},
|
|
|
|
{8251, nullptr, "CloseSharedLayer"},
|
|
|
|
{8252, nullptr, "ConnectSharedLayer"},
|
|
|
|
{8253, nullptr, "DisconnectSharedLayer"},
|
|
|
|
{8254, nullptr, "AcquireSharedFrameBuffer"},
|
|
|
|
{8255, nullptr, "PresentSharedFrameBuffer"},
|
|
|
|
{8256, nullptr, "GetSharedFrameBufferAcquirableEvent"},
|
|
|
|
{8257, nullptr, "FillSharedFrameBufferColor"},
|
|
|
|
{8258, nullptr, "CancelSharedFrameBuffer"},
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
~ISystemDisplayService() = default;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetLayerZ(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 layer_id = rp.Pop<u64>();
|
|
|
|
u64 z_value = rp.Pop<u64>();
|
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
2018-01-07 21:27:58 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2018-04-16 05:04:34 -04:00
|
|
|
|
|
|
|
void SetLayerVisibility(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 layer_id = rp.Pop<u64>();
|
|
|
|
bool visibility = rp.Pop<bool>();
|
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called, layer_id=0x{:08X}, visibility={}", layer_id,
|
2018-07-02 12:20:50 -04:00
|
|
|
visibility);
|
2018-04-16 05:04:34 -04:00
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> {
|
|
|
|
public:
|
2018-01-22 11:54:58 -05:00
|
|
|
explicit IManagerDisplayService(std::shared_ptr<NVFlinger::NVFlinger> nv_flinger)
|
2018-01-08 18:18:50 -05:00
|
|
|
: ServiceFramework("IManagerDisplayService"), nv_flinger(std::move(nv_flinger)) {
|
2018-01-07 21:27:58 -05:00
|
|
|
static const FunctionInfo functions[] = {
|
2018-04-17 11:37:43 -04:00
|
|
|
{200, nullptr, "AllocateProcessHeapBlock"},
|
|
|
|
{201, nullptr, "FreeProcessHeapBlock"},
|
2018-01-15 01:29:00 -05:00
|
|
|
{1020, &IManagerDisplayService::CloseDisplay, "CloseDisplay"},
|
2018-01-07 21:27:58 -05:00
|
|
|
{1102, nullptr, "GetDisplayResolution"},
|
|
|
|
{2010, &IManagerDisplayService::CreateManagedLayer, "CreateManagedLayer"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{2011, nullptr, "DestroyManagedLayer"},
|
|
|
|
{2050, nullptr, "CreateIndirectLayer"},
|
|
|
|
{2051, nullptr, "DestroyIndirectLayer"},
|
|
|
|
{2052, nullptr, "CreateIndirectProducerEndPoint"},
|
|
|
|
{2053, nullptr, "DestroyIndirectProducerEndPoint"},
|
|
|
|
{2054, nullptr, "CreateIndirectConsumerEndPoint"},
|
|
|
|
{2055, nullptr, "DestroyIndirectConsumerEndPoint"},
|
|
|
|
{2300, nullptr, "AcquireLayerTexturePresentingEvent"},
|
|
|
|
{2301, nullptr, "ReleaseLayerTexturePresentingEvent"},
|
|
|
|
{2302, nullptr, "GetDisplayHotplugEvent"},
|
|
|
|
{2402, nullptr, "GetDisplayHotplugState"},
|
|
|
|
{2501, nullptr, "GetCompositorErrorInfo"},
|
|
|
|
{2601, nullptr, "GetDisplayErrorEvent"},
|
|
|
|
{4201, nullptr, "SetDisplayAlpha"},
|
|
|
|
{4203, nullptr, "SetDisplayLayerStack"},
|
|
|
|
{4205, nullptr, "SetDisplayPowerState"},
|
|
|
|
{4206, nullptr, "SetDefaultDisplay"},
|
2018-01-07 21:27:58 -05:00
|
|
|
{6000, &IManagerDisplayService::AddToLayerStack, "AddToLayerStack"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{6001, nullptr, "RemoveFromLayerStack"},
|
2018-04-16 05:04:34 -04:00
|
|
|
{6002, &IManagerDisplayService::SetLayerVisibility, "SetLayerVisibility"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{6003, nullptr, "SetLayerConfig"},
|
|
|
|
{6004, nullptr, "AttachLayerPresentationTracer"},
|
|
|
|
{6005, nullptr, "DetachLayerPresentationTracer"},
|
|
|
|
{6006, nullptr, "StartLayerPresentationRecording"},
|
|
|
|
{6007, nullptr, "StopLayerPresentationRecording"},
|
|
|
|
{6008, nullptr, "StartLayerPresentationFenceWait"},
|
|
|
|
{6009, nullptr, "StopLayerPresentationFenceWait"},
|
|
|
|
{6010, nullptr, "GetLayerPresentationAllFencesExpiredEvent"},
|
|
|
|
{7000, nullptr, "SetContentVisibility"},
|
|
|
|
{8000, nullptr, "SetConductorLayer"},
|
|
|
|
{8100, nullptr, "SetIndirectProducerFlipOffset"},
|
|
|
|
{8200, nullptr, "CreateSharedBufferStaticStorage"},
|
|
|
|
{8201, nullptr, "CreateSharedBufferTransferMemory"},
|
|
|
|
{8202, nullptr, "DestroySharedBuffer"},
|
|
|
|
{8203, nullptr, "BindSharedLowLevelLayerToManagedLayer"},
|
|
|
|
{8204, nullptr, "BindSharedLowLevelLayerToIndirectLayer"},
|
|
|
|
{8207, nullptr, "UnbindSharedLowLevelLayer"},
|
|
|
|
{8208, nullptr, "ConnectSharedLowLevelLayerToSharedBuffer"},
|
|
|
|
{8209, nullptr, "DisconnectSharedLowLevelLayerFromSharedBuffer"},
|
|
|
|
{8210, nullptr, "CreateSharedLayer"},
|
|
|
|
{8211, nullptr, "DestroySharedLayer"},
|
|
|
|
{8216, nullptr, "AttachSharedLayerToLowLevelLayer"},
|
|
|
|
{8217, nullptr, "ForceDetachSharedLayerFromLowLevelLayer"},
|
|
|
|
{8218, nullptr, "StartDetachSharedLayerFromLowLevelLayer"},
|
|
|
|
{8219, nullptr, "FinishDetachSharedLayerFromLowLevelLayer"},
|
|
|
|
{8220, nullptr, "GetSharedLayerDetachReadyEvent"},
|
|
|
|
{8221, nullptr, "GetSharedLowLevelLayerSynchronizedEvent"},
|
|
|
|
{8222, nullptr, "CheckSharedLowLevelLayerSynchronized"},
|
|
|
|
{8223, nullptr, "RegisterSharedBufferImporterAruid"},
|
|
|
|
{8224, nullptr, "UnregisterSharedBufferImporterAruid"},
|
|
|
|
{8227, nullptr, "CreateSharedBufferProcessHeap"},
|
|
|
|
{8228, nullptr, "GetSharedLayerLayerStacks"},
|
|
|
|
{8229, nullptr, "SetSharedLayerLayerStacks"},
|
|
|
|
{8291, nullptr, "PresentDetachedSharedFrameBufferToLowLevelLayer"},
|
|
|
|
{8292, nullptr, "FillDetachedSharedFrameBufferColor"},
|
|
|
|
{8293, nullptr, "GetDetachedSharedFrameBufferImage"},
|
|
|
|
{8294, nullptr, "SetDetachedSharedFrameBufferImage"},
|
|
|
|
{8295, nullptr, "CopyDetachedSharedFrameBufferImage"},
|
|
|
|
{8296, nullptr, "SetDetachedSharedFrameBufferSubImage"},
|
|
|
|
{8297, nullptr, "GetSharedFrameBufferContentParameter"},
|
|
|
|
{8298, nullptr, "ExpandStartupLogoOnSharedFrameBuffer"},
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
~IManagerDisplayService() = default;
|
|
|
|
|
|
|
|
private:
|
2018-01-15 01:29:00 -05:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-15 01:29:00 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 display = rp.Pop<u64>();
|
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
2018-01-15 01:29:00 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
void CreateManagedLayer(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 unknown = rp.Pop<u32>();
|
|
|
|
rp.Skip(1, false);
|
|
|
|
u64 display = rp.Pop<u64>();
|
|
|
|
u64 aruid = rp.Pop<u64>();
|
|
|
|
|
2018-01-08 18:18:50 -05:00
|
|
|
u64 layer_id = nv_flinger->CreateLayer(display);
|
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(4, 0, 0);
|
2018-01-07 21:27:58 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-01-08 18:18:50 -05:00
|
|
|
rb.Push(layer_id);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddToLayerStack(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 stack = rp.Pop<u32>();
|
|
|
|
u64 layer_id = rp.Pop<u64>();
|
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
2018-01-07 21:27:58 -05:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-04-16 05:04:34 -04:00
|
|
|
void SetLayerVisibility(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 layer_id = rp.Pop<u64>();
|
|
|
|
bool visibility = rp.Pop<bool>();
|
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called, layer_id=0x{:X}, visibility={}", layer_id,
|
2018-07-02 12:20:50 -04:00
|
|
|
visibility);
|
2018-04-16 05:04:34 -04:00
|
|
|
}
|
|
|
|
|
2018-01-22 11:54:58 -05:00
|
|
|
std::shared_ptr<NVFlinger::NVFlinger> nv_flinger;
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> {
|
|
|
|
public:
|
|
|
|
IApplicationDisplayService(std::shared_ptr<NVFlinger::NVFlinger> nv_flinger);
|
|
|
|
~IApplicationDisplayService() = default;
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
private:
|
|
|
|
void GetRelayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IHOSBinderDriver>(nv_flinger);
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void GetSystemDisplayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<ISystemDisplayService>();
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void GetManagerDisplayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IManagerDisplayService>(nv_flinger);
|
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void GetIndirectDisplayTransactionService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IHOSBinderDriver>(nv_flinger);
|
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void OpenDisplay(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
auto name_buf = rp.PopRaw<std::array<u8, 0x40>>();
|
|
|
|
auto end = std::find(name_buf.begin(), name_buf.end(), '\0');
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
std::string name(name_buf.begin(), end);
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
ASSERT_MSG(name == "Default", "Non-default displays aren't supported yet");
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(4, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push<u64>(nv_flinger->OpenDisplay(name));
|
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 display_id = rp.Pop<u64>();
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-04-02 23:28:45 -04:00
|
|
|
void GetDisplayResolution(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-04-02 23:28:45 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 display_id = rp.Pop<u64>();
|
|
|
|
|
2018-04-16 05:04:34 -04:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(6, 0, 0);
|
2018-04-02 23:28:45 -04:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
|
|
|
if (Settings::values.use_docked_mode) {
|
2018-04-16 05:04:34 -04:00
|
|
|
rb.Push(static_cast<u64>(DisplayResolution::DockedWidth));
|
|
|
|
rb.Push(static_cast<u64>(DisplayResolution::DockedHeight));
|
2018-04-02 23:28:45 -04:00
|
|
|
} else {
|
2018-04-16 05:04:34 -04:00
|
|
|
rb.Push(static_cast<u64>(DisplayResolution::UndockedWidth));
|
|
|
|
rb.Push(static_cast<u64>(DisplayResolution::UndockedHeight));
|
2018-04-02 23:28:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void SetLayerScalingMode(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 scaling_mode = rp.Pop<u32>();
|
|
|
|
u64 unknown = rp.Pop<u64>();
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void ListDisplays(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
DisplayInfo display_info;
|
|
|
|
ctx.WriteBuffer(&display_info, sizeof(DisplayInfo));
|
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(4, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push<u64>(1);
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void OpenLayer(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_DEBUG(Service_VI, "called");
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
auto name_buf = rp.PopRaw<std::array<u8, 0x40>>();
|
|
|
|
auto end = std::find(name_buf.begin(), name_buf.end(), '\0');
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
std::string display_name(name_buf.begin(), end);
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
u64 layer_id = rp.Pop<u64>();
|
|
|
|
u64 aruid = rp.Pop<u64>();
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
u64 display_id = nv_flinger->OpenDisplay(display_name);
|
|
|
|
u32 buffer_queue_id = nv_flinger->GetBufferQueueId(display_id, layer_id);
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
NativeWindow native_window{buffer_queue_id};
|
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(4, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push<u64>(ctx.WriteBuffer(native_window.Serialize()));
|
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void CreateStrayLayer(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_DEBUG(Service_VI, "called");
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u32 flags = rp.Pop<u32>();
|
|
|
|
rp.Pop<u32>(); // padding
|
|
|
|
u64 display_id = rp.Pop<u64>();
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
// TODO(Subv): What's the difference between a Stray and a Managed layer?
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
u64 layer_id = nv_flinger->CreateLayer(display_id);
|
|
|
|
u32 buffer_queue_id = nv_flinger->GetBufferQueueId(display_id, layer_id);
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
NativeWindow native_window{buffer_queue_id};
|
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(6, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push(layer_id);
|
|
|
|
rb.Push<u64>(ctx.WriteBuffer(native_window.Serialize()));
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void DestroyStrayLayer(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 layer_id = rp.Pop<u64>();
|
2018-02-07 07:11:17 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 0, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void GetDisplayVsyncEvent(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
u64 display_id = rp.Pop<u64>();
|
2018-01-08 18:29:43 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
auto vsync_event = nv_flinger->GetVsyncEvent(display_id);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(2, 1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(vsync_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<NVFlinger::NVFlinger> nv_flinger;
|
|
|
|
};
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-01-22 11:54:58 -05:00
|
|
|
IApplicationDisplayService::IApplicationDisplayService(
|
|
|
|
std::shared_ptr<NVFlinger::NVFlinger> nv_flinger)
|
2018-01-08 18:18:50 -05:00
|
|
|
: ServiceFramework("IApplicationDisplayService"), nv_flinger(std::move(nv_flinger)) {
|
2018-01-07 21:27:58 -05:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{100, &IApplicationDisplayService::GetRelayService, "GetRelayService"},
|
|
|
|
{101, &IApplicationDisplayService::GetSystemDisplayService, "GetSystemDisplayService"},
|
|
|
|
{102, &IApplicationDisplayService::GetManagerDisplayService, "GetManagerDisplayService"},
|
2018-01-15 17:20:08 -05:00
|
|
|
{103, &IApplicationDisplayService::GetIndirectDisplayTransactionService,
|
|
|
|
"GetIndirectDisplayTransactionService"},
|
2018-02-07 07:11:17 -05:00
|
|
|
{1000, &IApplicationDisplayService::ListDisplays, "ListDisplays"},
|
2018-01-07 21:27:58 -05:00
|
|
|
{1010, &IApplicationDisplayService::OpenDisplay, "OpenDisplay"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{1011, nullptr, "OpenDefaultDisplay"},
|
2018-01-15 17:20:08 -05:00
|
|
|
{1020, &IApplicationDisplayService::CloseDisplay, "CloseDisplay"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{1101, nullptr, "SetDisplayEnabled"},
|
2018-04-02 23:28:45 -04:00
|
|
|
{1102, &IApplicationDisplayService::GetDisplayResolution, "GetDisplayResolution"},
|
2018-01-07 21:27:58 -05:00
|
|
|
{2020, &IApplicationDisplayService::OpenLayer, "OpenLayer"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{2021, nullptr, "CloseLayer"},
|
2018-01-15 17:20:08 -05:00
|
|
|
{2030, &IApplicationDisplayService::CreateStrayLayer, "CreateStrayLayer"},
|
|
|
|
{2031, &IApplicationDisplayService::DestroyStrayLayer, "DestroyStrayLayer"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{2101, &IApplicationDisplayService::SetLayerScalingMode, "SetLayerScalingMode"},
|
|
|
|
{2102, nullptr, "ConvertScalingMode"},
|
|
|
|
{2450, nullptr, "GetIndirectLayerImageMap"},
|
|
|
|
{2451, nullptr, "GetIndirectLayerImageCropMap"},
|
|
|
|
{2460, nullptr, "GetIndirectLayerImageRequiredMemoryInfo"},
|
2018-01-07 21:27:58 -05:00
|
|
|
{5202, &IApplicationDisplayService::GetDisplayVsyncEvent, "GetDisplayVsyncEvent"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{5203, nullptr, "GetDisplayVsyncEventForDebug"},
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> module, const char* name,
|
|
|
|
std::shared_ptr<NVFlinger::NVFlinger> nv_flinger)
|
|
|
|
: ServiceFramework(name), module(std::move(module)), nv_flinger(std::move(nv_flinger)) {}
|
|
|
|
|
|
|
|
void Module::Interface::GetDisplayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-03-21 06:09:40 -04:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushIpcInterface<IApplicationDisplayService>(nv_flinger);
|
|
|
|
}
|
|
|
|
|
2018-01-22 13:40:02 -05:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager,
|
|
|
|
std::shared_ptr<NVFlinger::NVFlinger> nv_flinger) {
|
2018-03-21 06:09:40 -04:00
|
|
|
auto module = std::make_shared<Module>();
|
|
|
|
std::make_shared<VI_M>(module, nv_flinger)->InstallAsService(service_manager);
|
|
|
|
std::make_shared<VI_S>(module, nv_flinger)->InstallAsService(service_manager);
|
|
|
|
std::make_shared<VI_U>(module, nv_flinger)->InstallAsService(service_manager);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::VI
|