2018-01-13 21:22:39 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2018-01-08 02:27:58 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-01-12 03:36:56 +00:00
|
|
|
#include <algorithm>
|
2018-02-12 00:03:31 +00:00
|
|
|
#include <array>
|
2018-09-13 20:43:31 +00:00
|
|
|
#include <cstring>
|
2018-03-21 10:09:40 +00:00
|
|
|
#include <memory>
|
2018-10-30 04:03:25 +00:00
|
|
|
#include <optional>
|
2018-07-23 18:52:32 +00:00
|
|
|
#include <type_traits>
|
2018-07-23 18:48:53 +00:00
|
|
|
#include <utility>
|
2018-10-30 04:03:25 +00:00
|
|
|
|
2018-01-08 02:27:58 +00:00
|
|
|
#include "common/alignment.h"
|
2018-09-13 20:43:31 +00:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/logging/log.h"
|
2018-07-18 00:11:41 +00:00
|
|
|
#include "common/math_util.h"
|
2021-04-14 23:07:40 +00:00
|
|
|
#include "common/settings.h"
|
2018-09-13 20:43:31 +00:00
|
|
|
#include "common/swap.h"
|
2018-01-09 00:12:28 +00:00
|
|
|
#include "core/core_timing.h"
|
2018-01-08 02:27:58 +00:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2021-01-30 06:48:06 +00:00
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
2020-12-31 07:01:08 +00:00
|
|
|
#include "core/hle/kernel/k_thread.h"
|
2019-06-07 15:34:55 +00:00
|
|
|
#include "core/hle/service/nvdrv/nvdata.h"
|
2021-11-12 03:15:51 +00:00
|
|
|
#include "core/hle/service/nvflinger/binder.h"
|
|
|
|
#include "core/hle/service/nvflinger/buffer_queue_producer.h"
|
|
|
|
#include "core/hle/service/nvflinger/hos_binder_driver_server.h"
|
2018-09-13 20:43:31 +00:00
|
|
|
#include "core/hle/service/nvflinger/nvflinger.h"
|
2021-11-12 03:15:51 +00:00
|
|
|
#include "core/hle/service/nvflinger/parcel.h"
|
2019-02-26 22:20:02 +00:00
|
|
|
#include "core/hle/service/service.h"
|
2018-01-08 02:27:58 +00:00
|
|
|
#include "core/hle/service/vi/vi.h"
|
|
|
|
#include "core/hle/service/vi/vi_m.h"
|
2018-02-02 09:59:50 +00:00
|
|
|
#include "core/hle/service/vi/vi_s.h"
|
|
|
|
#include "core/hle/service/vi/vi_u.h"
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-04-20 01:41:44 +00:00
|
|
|
namespace Service::VI {
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2019-01-05 00:31:14 +00:00
|
|
|
constexpr ResultCode ERR_OPERATION_FAILED{ErrorModule::VI, 1};
|
2019-02-26 22:49:32 +00:00
|
|
|
constexpr ResultCode ERR_PERMISSION_DENIED{ErrorModule::VI, 5};
|
2019-01-05 00:31:14 +00:00
|
|
|
constexpr ResultCode ERR_UNSUPPORTED{ErrorModule::VI, 6};
|
2019-02-05 21:20:04 +00:00
|
|
|
constexpr ResultCode ERR_NOT_FOUND{ErrorModule::VI, 7};
|
2019-01-05 00:31:14 +00:00
|
|
|
|
2018-02-07 12:11:17 +00:00
|
|
|
struct DisplayInfo {
|
2019-01-02 20:26:41 +00:00
|
|
|
/// The name of this particular display.
|
2018-02-07 12:11:17 +00:00
|
|
|
char display_name[0x40]{"Default"};
|
2019-01-02 20:26:41 +00:00
|
|
|
|
|
|
|
/// Whether or not the display has a limited number of layers.
|
|
|
|
u8 has_limited_layers{1};
|
2019-11-03 23:54:03 +00:00
|
|
|
INSERT_PADDING_BYTES(7);
|
2019-01-02 20:26:41 +00:00
|
|
|
|
|
|
|
/// Indicates the total amount of layers supported by the display.
|
|
|
|
/// @note This is only valid if has_limited_layers is set.
|
|
|
|
u64 max_layers{1};
|
|
|
|
|
|
|
|
/// Maximum width in pixels.
|
2019-01-02 21:14:40 +00:00
|
|
|
u64 width{1920};
|
2019-01-02 20:26:41 +00:00
|
|
|
|
|
|
|
/// Maximum height in pixels.
|
2019-01-02 21:14:40 +00:00
|
|
|
u64 height{1080};
|
2018-02-07 12:11:17 +00:00
|
|
|
};
|
|
|
|
static_assert(sizeof(DisplayInfo) == 0x60, "DisplayInfo has wrong size");
|
|
|
|
|
2021-11-12 03:15:51 +00:00
|
|
|
class NativeWindow final {
|
2018-01-08 02:27:58 +00:00
|
|
|
public:
|
2021-11-12 03:15:51 +00:00
|
|
|
constexpr explicit NativeWindow(u32 id_) : id{id_} {}
|
2018-01-21 16:13:47 +00:00
|
|
|
|
|
|
|
private:
|
2021-11-12 03:15:51 +00:00
|
|
|
const u32 magic = 2;
|
|
|
|
const u32 process_id = 1;
|
|
|
|
const u32 id;
|
2022-03-20 07:48:02 +00:00
|
|
|
INSERT_PADDING_WORDS(3);
|
|
|
|
std::array<u8, 8> dispdrv = {'d', 'i', 's', 'p', 'd', 'r', 'v', '\0'};
|
|
|
|
INSERT_PADDING_WORDS(2);
|
2018-01-21 16:13:47 +00:00
|
|
|
};
|
2022-03-20 07:48:02 +00:00
|
|
|
static_assert(sizeof(NativeWindow) == 0x28, "NativeWindow has wrong size");
|
2018-01-21 16:13:47 +00:00
|
|
|
|
2018-01-08 02:27:58 +00:00
|
|
|
class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> {
|
|
|
|
public:
|
2021-11-12 03:15:51 +00:00
|
|
|
explicit IHOSBinderDriver(Core::System& system_, NVFlinger::HosBinderDriverServer& server_)
|
|
|
|
: ServiceFramework{system_, "IHOSBinderDriver"}, server(server_) {
|
2018-01-08 02:27:58 +00:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &IHOSBinderDriver::TransactParcel, "TransactParcel"},
|
|
|
|
{1, &IHOSBinderDriver::AdjustRefcount, "AdjustRefcount"},
|
2018-01-15 22:20:08 +00:00
|
|
|
{2, &IHOSBinderDriver::GetNativeHandle, "GetNativeHandle"},
|
2018-02-14 02:39:58 +00:00
|
|
|
{3, &IHOSBinderDriver::TransactParcel, "TransactParcelAuto"},
|
2018-01-08 02:27:58 +00:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-02-14 02:54:12 +00:00
|
|
|
void TransactParcel(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 id = rp.Pop<u32>();
|
2021-11-12 03:15:51 +00:00
|
|
|
const auto transaction = static_cast<android::TransactionId>(rp.Pop<u32>());
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 flags = rp.Pop<u32>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id,
|
2020-12-08 03:00:34 +00:00
|
|
|
transaction, flags);
|
2018-02-14 02:54:12 +00:00
|
|
|
|
2021-11-12 03:15:51 +00:00
|
|
|
server.TryGetProducer(id)->Transact(ctx, transaction, flags);
|
2018-02-10 03:50:29 +00:00
|
|
|
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-08 02:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdjustRefcount(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 id = rp.Pop<u32>();
|
|
|
|
const s32 addval = rp.PopRaw<s32>();
|
|
|
|
const u32 type = rp.Pop<u32>();
|
|
|
|
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={:08X}, type={:08X}", id, addval,
|
2018-07-02 16:20:50 +00:00
|
|
|
type);
|
2018-11-26 06:06:13 +00:00
|
|
|
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-08 02:27:58 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 22:20:08 +00:00
|
|
|
void GetNativeHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 id = rp.Pop<u32>();
|
|
|
|
const u32 unknown = rp.Pop<u32>();
|
|
|
|
|
2018-11-26 06:06:13 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called id={}, unknown={:08X}", id, unknown);
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2018-01-24 00:52:18 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-12 03:15:51 +00:00
|
|
|
rb.PushCopyObjects(server.TryGetProducer(id)->GetNativeHandle());
|
2018-01-15 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 03:15:51 +00:00
|
|
|
private:
|
|
|
|
NVFlinger::HosBinderDriverServer& server;
|
2020-11-24 22:31:58 +00:00
|
|
|
};
|
2018-01-08 02:27:58 +00:00
|
|
|
|
|
|
|
class ISystemDisplayService final : public ServiceFramework<ISystemDisplayService> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit ISystemDisplayService(Core::System& system_)
|
|
|
|
: ServiceFramework{system_, "ISystemDisplayService"} {
|
2018-01-08 02:27:58 +00:00
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{1200, nullptr, "GetZOrderCountMin"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{1202, nullptr, "GetZOrderCountMax"},
|
|
|
|
{1203, nullptr, "GetDisplayLogicalResolution"},
|
|
|
|
{1204, nullptr, "SetDisplayMagnification"},
|
|
|
|
{2201, nullptr, "SetLayerPosition"},
|
|
|
|
{2203, nullptr, "SetLayerSize"},
|
|
|
|
{2204, nullptr, "GetLayerZ"},
|
2018-01-08 02:27:58 +00:00
|
|
|
{2205, &ISystemDisplayService::SetLayerZ, "SetLayerZ"},
|
2018-04-16 09:04:34 +00:00
|
|
|
{2207, &ISystemDisplayService::SetLayerVisibility, "SetLayerVisibility"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{2209, nullptr, "SetLayerAlpha"},
|
2021-04-07 14:41:20 +00:00
|
|
|
{2210, nullptr, "SetLayerPositionAndSize"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{2312, nullptr, "CreateStrayLayer"},
|
|
|
|
{2400, nullptr, "OpenIndirectLayer"},
|
|
|
|
{2401, nullptr, "CloseIndirectLayer"},
|
|
|
|
{2402, nullptr, "FlipIndirectLayer"},
|
|
|
|
{3000, nullptr, "ListDisplayModes"},
|
|
|
|
{3001, nullptr, "ListDisplayRgbRanges"},
|
|
|
|
{3002, nullptr, "ListDisplayContentTypes"},
|
2018-09-17 15:19:31 +00:00
|
|
|
{3200, &ISystemDisplayService::GetDisplayMode, "GetDisplayMode"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{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"},
|
2021-04-07 14:41:20 +00:00
|
|
|
{3218, nullptr, "SetDisplayCrcMode"},
|
2020-06-29 02:01:34 +00:00
|
|
|
{6013, nullptr, "GetLayerPresentationSubmissionTimestamps"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{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"},
|
2021-04-07 14:41:20 +00:00
|
|
|
{9000, nullptr, "GetDp2hdmiController"},
|
2018-01-08 02:27:58 +00:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetLayerZ(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const u64 z_value = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}, z_value=0x{:016X}", layer_id,
|
|
|
|
z_value);
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-08 02:27:58 +00:00
|
|
|
}
|
2018-04-16 09:04:34 +00:00
|
|
|
|
2019-01-28 13:21:34 +00:00
|
|
|
// This function currently does nothing but return a success error code in
|
|
|
|
// the vi library itself, so do the same thing, but log out the passed in values.
|
2018-04-16 09:04:34 +00:00
|
|
|
void SetLayerVisibility(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const bool visibility = rp.Pop<bool>();
|
|
|
|
|
2019-01-28 13:21:34 +00:00
|
|
|
LOG_DEBUG(Service_VI, "called, layer_id=0x{:08X}, visibility={}", layer_id, visibility);
|
2018-11-26 06:06:13 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-16 09:04:34 +00:00
|
|
|
}
|
2018-09-17 15:19:31 +00:00
|
|
|
|
|
|
|
void GetDisplayMode(Kernel::HLERequestContext& ctx) {
|
2018-11-26 06:06:13 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
|
|
|
|
2018-09-17 15:19:31 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-09-17 15:19:31 +00:00
|
|
|
|
2020-09-28 14:00:15 +00:00
|
|
|
if (Settings::values.use_docked_mode.GetValue()) {
|
2021-07-20 16:29:52 +00:00
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
|
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
|
2018-09-17 15:19:31 +00:00
|
|
|
} else {
|
2021-07-20 16:29:52 +00:00
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
|
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
|
2018-09-17 15:19:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 06:06:13 +00:00
|
|
|
rb.PushRaw<float>(60.0f); // This wouldn't seem to be correct for 30 fps games.
|
2018-09-17 15:19:31 +00:00
|
|
|
rb.Push<u32>(0);
|
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit IManagerDisplayService(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_)
|
|
|
|
: ServiceFramework{system_, "IManagerDisplayService"}, nv_flinger{nv_flinger_} {
|
2019-11-12 13:54:58 +00:00
|
|
|
// clang-format off
|
2018-01-08 02:27:58 +00:00
|
|
|
static const FunctionInfo functions[] = {
|
2018-04-17 15:37:43 +00:00
|
|
|
{200, nullptr, "AllocateProcessHeapBlock"},
|
|
|
|
{201, nullptr, "FreeProcessHeapBlock"},
|
2018-01-15 06:29:00 +00:00
|
|
|
{1020, &IManagerDisplayService::CloseDisplay, "CloseDisplay"},
|
2018-01-08 02:27:58 +00:00
|
|
|
{1102, nullptr, "GetDisplayResolution"},
|
|
|
|
{2010, &IManagerDisplayService::CreateManagedLayer, "CreateManagedLayer"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{2011, nullptr, "DestroyManagedLayer"},
|
2019-02-25 13:06:47 +00:00
|
|
|
{2012, nullptr, "CreateStrayLayer"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{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"},
|
2020-06-29 02:01:34 +00:00
|
|
|
{2303, nullptr, "GetDisplayModeChangedEvent"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{2402, nullptr, "GetDisplayHotplugState"},
|
|
|
|
{2501, nullptr, "GetCompositorErrorInfo"},
|
|
|
|
{2601, nullptr, "GetDisplayErrorEvent"},
|
2021-04-07 14:41:20 +00:00
|
|
|
{2701, nullptr, "GetDisplayFatalErrorEvent"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{4201, nullptr, "SetDisplayAlpha"},
|
|
|
|
{4203, nullptr, "SetDisplayLayerStack"},
|
|
|
|
{4205, nullptr, "SetDisplayPowerState"},
|
|
|
|
{4206, nullptr, "SetDefaultDisplay"},
|
2021-04-07 14:41:20 +00:00
|
|
|
{4207, nullptr, "ResetDisplayPanel"},
|
|
|
|
{4208, nullptr, "SetDisplayFatalErrorEnabled"},
|
|
|
|
{4209, nullptr, "IsDisplayPanelOn"},
|
|
|
|
{4300, nullptr, "GetInternalPanelId"},
|
2018-01-08 02:27:58 +00:00
|
|
|
{6000, &IManagerDisplayService::AddToLayerStack, "AddToLayerStack"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{6001, nullptr, "RemoveFromLayerStack"},
|
2018-04-16 09:04:34 +00:00
|
|
|
{6002, &IManagerDisplayService::SetLayerVisibility, "SetLayerVisibility"},
|
2018-04-17 15:37:43 +00: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"},
|
2019-11-12 13:54:58 +00:00
|
|
|
{6011, nullptr, "EnableLayerAutoClearTransitionBuffer"},
|
|
|
|
{6012, nullptr, "DisableLayerAutoClearTransitionBuffer"},
|
2021-09-27 01:11:39 +00:00
|
|
|
{6013, nullptr, "SetLayerOpacity"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{7000, nullptr, "SetContentVisibility"},
|
|
|
|
{8000, nullptr, "SetConductorLayer"},
|
2019-11-12 13:54:58 +00:00
|
|
|
{8001, nullptr, "SetTimestampTracking"},
|
2018-04-17 15:37:43 +00:00
|
|
|
{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-08 02:27:58 +00:00
|
|
|
};
|
2019-11-12 13:54:58 +00:00
|
|
|
// clang-format on
|
|
|
|
|
2018-01-08 02:27:58 +00:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-01-15 06:29:00 +00:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 display = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. display=0x{:016X}", display);
|
2018-01-15 06:29:00 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-15 06:29:00 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 02:27:58 +00:00
|
|
|
void CreateManagedLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 unknown = rp.Pop<u32>();
|
2018-01-08 02:27:58 +00:00
|
|
|
rp.Skip(1, false);
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 display = rp.Pop<u64>();
|
|
|
|
const u64 aruid = rp.Pop<u64>();
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2019-01-03 00:42:08 +00:00
|
|
|
LOG_WARNING(Service_VI,
|
|
|
|
"(STUBBED) called. unknown=0x{:08X}, display=0x{:016X}, aruid=0x{:016X}",
|
|
|
|
unknown, display, aruid);
|
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto layer_id = nv_flinger.CreateLayer(display);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!layer_id) {
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Layer not found! display=0x{:016X}", display);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2019-02-05 21:20:04 +00:00
|
|
|
rb.Push(*layer_id);
|
2018-01-08 02:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddToLayerStack(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 stack = rp.Pop<u32>();
|
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. stack=0x{:08X}, layer_id=0x{:016X}", stack,
|
|
|
|
layer_id);
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-08 02:27:58 +00:00
|
|
|
}
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2018-04-16 09:04:34 +00:00
|
|
|
void SetLayerVisibility(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const bool visibility = rp.Pop<bool>();
|
|
|
|
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called, layer_id=0x{:X}, visibility={}", layer_id,
|
2018-07-02 16:20:50 +00:00
|
|
|
visibility);
|
2018-11-26 06:06:13 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-16 09:04:34 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
NVFlinger::NVFlinger& nv_flinger;
|
2018-01-08 02:27:58 +00:00
|
|
|
};
|
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> {
|
|
|
|
public:
|
2021-11-12 03:15:51 +00:00
|
|
|
IApplicationDisplayService(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_,
|
|
|
|
NVFlinger::HosBinderDriverServer& hos_binder_driver_server_)
|
|
|
|
: ServiceFramework{system_, "IApplicationDisplayService"}, nv_flinger{nv_flinger_},
|
|
|
|
hos_binder_driver_server{hos_binder_driver_server_} {
|
|
|
|
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{100, &IApplicationDisplayService::GetRelayService, "GetRelayService"},
|
|
|
|
{101, &IApplicationDisplayService::GetSystemDisplayService, "GetSystemDisplayService"},
|
|
|
|
{102, &IApplicationDisplayService::GetManagerDisplayService,
|
|
|
|
"GetManagerDisplayService"},
|
|
|
|
{103, &IApplicationDisplayService::GetIndirectDisplayTransactionService,
|
|
|
|
"GetIndirectDisplayTransactionService"},
|
|
|
|
{1000, &IApplicationDisplayService::ListDisplays, "ListDisplays"},
|
|
|
|
{1010, &IApplicationDisplayService::OpenDisplay, "OpenDisplay"},
|
|
|
|
{1011, &IApplicationDisplayService::OpenDefaultDisplay, "OpenDefaultDisplay"},
|
|
|
|
{1020, &IApplicationDisplayService::CloseDisplay, "CloseDisplay"},
|
|
|
|
{1101, &IApplicationDisplayService::SetDisplayEnabled, "SetDisplayEnabled"},
|
|
|
|
{1102, &IApplicationDisplayService::GetDisplayResolution, "GetDisplayResolution"},
|
|
|
|
{2020, &IApplicationDisplayService::OpenLayer, "OpenLayer"},
|
|
|
|
{2021, &IApplicationDisplayService::CloseLayer, "CloseLayer"},
|
|
|
|
{2030, &IApplicationDisplayService::CreateStrayLayer, "CreateStrayLayer"},
|
|
|
|
{2031, &IApplicationDisplayService::DestroyStrayLayer, "DestroyStrayLayer"},
|
|
|
|
{2101, &IApplicationDisplayService::SetLayerScalingMode, "SetLayerScalingMode"},
|
|
|
|
{2102, &IApplicationDisplayService::ConvertScalingMode, "ConvertScalingMode"},
|
|
|
|
{2450, &IApplicationDisplayService::GetIndirectLayerImageMap,
|
|
|
|
"GetIndirectLayerImageMap"},
|
|
|
|
{2451, nullptr, "GetIndirectLayerImageCropMap"},
|
|
|
|
{2460, &IApplicationDisplayService::GetIndirectLayerImageRequiredMemoryInfo,
|
|
|
|
"GetIndirectLayerImageRequiredMemoryInfo"},
|
|
|
|
{5202, &IApplicationDisplayService::GetDisplayVsyncEvent, "GetDisplayVsyncEvent"},
|
|
|
|
{5203, nullptr, "GetDisplayVsyncEventForDebug"},
|
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
private:
|
2019-01-05 00:31:14 +00:00
|
|
|
enum class ConvertedScaleMode : u64 {
|
2019-01-05 01:32:29 +00:00
|
|
|
Freeze = 0,
|
|
|
|
ScaleToWindow = 1,
|
|
|
|
ScaleAndCrop = 2,
|
|
|
|
None = 3,
|
|
|
|
PreserveAspectRatio = 4,
|
2019-01-05 00:31:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class NintendoScaleMode : u32 {
|
|
|
|
None = 0,
|
|
|
|
Freeze = 1,
|
|
|
|
ScaleToWindow = 2,
|
2019-01-05 01:32:29 +00:00
|
|
|
ScaleAndCrop = 3,
|
|
|
|
PreserveAspectRatio = 4,
|
2019-01-05 00:31:14 +00:00
|
|
|
};
|
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void GetRelayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-12 03:15:51 +00:00
|
|
|
rb.PushIpcInterface<IHOSBinderDriver>(system, hos_binder_driver_server);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void GetSystemDisplayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 20:19:08 +00:00
|
|
|
rb.PushIpcInterface<ISystemDisplayService>(system);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void GetManagerDisplayService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 20:19:08 +00:00
|
|
|
rb.PushIpcInterface<IManagerDisplayService>(system, nv_flinger);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void GetIndirectDisplayTransactionService(Kernel::HLERequestContext& ctx) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-12 03:15:51 +00:00
|
|
|
rb.PushIpcInterface<IHOSBinderDriver>(system, hos_binder_driver_server);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void OpenDisplay(Kernel::HLERequestContext& ctx) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-11-26 06:06:13 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 23:05:15 +00:00
|
|
|
const auto name_buf = rp.PopRaw<std::array<char, 0x40>>();
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2019-01-02 23:05:15 +00:00
|
|
|
OpenDisplayImpl(ctx, std::string_view{name_buf.data(), name_buf.size()});
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenDefaultDisplay(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_VI, "called");
|
|
|
|
|
|
|
|
OpenDisplayImpl(ctx, "Default");
|
|
|
|
}
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2019-01-02 23:05:15 +00:00
|
|
|
void OpenDisplayImpl(Kernel::HLERequestContext& ctx, std::string_view name) {
|
|
|
|
const auto trim_pos = name.find('\0');
|
|
|
|
|
|
|
|
if (trim_pos != std::string_view::npos) {
|
|
|
|
name.remove_suffix(name.size() - trim_pos);
|
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
ASSERT_MSG(name == "Default", "Non-default displays aren't supported yet");
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto display_id = nv_flinger.OpenDisplay(name);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!display_id) {
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Display not found! display_name={}", name);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2019-02-05 21:20:04 +00:00
|
|
|
rb.Push<u64>(*display_id);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. display_id=0x{:016X}", display_id);
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2019-01-03 01:45:40 +00:00
|
|
|
// This literally does nothing internally in the actual service itself,
|
|
|
|
// and just returns a successful result code regardless of the input.
|
|
|
|
void SetDisplayEnabled(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_VI, "called.");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2019-01-03 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 03:28:45 +00:00
|
|
|
void GetDisplayResolution(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
2019-01-04 23:43:15 +00:00
|
|
|
LOG_DEBUG(Service_VI, "called. display_id=0x{:016X}", display_id);
|
2018-04-03 03:28:45 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-03 03:28:45 +00:00
|
|
|
|
2019-01-04 23:43:15 +00:00
|
|
|
// This only returns the fixed values of 1280x720 and makes no distinguishing
|
|
|
|
// between docked and undocked dimensions. We take the liberty of applying
|
|
|
|
// the resolution scaling factor here.
|
2021-07-20 16:29:52 +00:00
|
|
|
rb.Push(static_cast<u64>(DisplayResolution::UndockedWidth));
|
|
|
|
rb.Push(static_cast<u64>(DisplayResolution::UndockedHeight));
|
2018-04-03 03:28:45 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void SetLayerScalingMode(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-05 00:31:14 +00:00
|
|
|
const auto scaling_mode = rp.PopEnum<NintendoScaleMode>();
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 unknown = rp.Pop<u64>();
|
|
|
|
|
2020-12-08 03:00:34 +00:00
|
|
|
LOG_DEBUG(Service_VI, "called. scaling_mode=0x{:08X}, unknown=0x{:016X}", scaling_mode,
|
|
|
|
unknown);
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2019-01-05 00:31:14 +00:00
|
|
|
|
2019-01-05 01:32:29 +00:00
|
|
|
if (scaling_mode > NintendoScaleMode::PreserveAspectRatio) {
|
2019-01-05 00:31:14 +00:00
|
|
|
LOG_ERROR(Service_VI, "Invalid scaling mode provided.");
|
|
|
|
rb.Push(ERR_OPERATION_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scaling_mode != NintendoScaleMode::ScaleToWindow &&
|
2019-01-05 01:32:29 +00:00
|
|
|
scaling_mode != NintendoScaleMode::PreserveAspectRatio) {
|
2019-01-05 00:31:14 +00:00
|
|
|
LOG_ERROR(Service_VI, "Unsupported scaling mode supplied.");
|
|
|
|
rb.Push(ERR_UNSUPPORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void ListDisplays(Kernel::HLERequestContext& ctx) {
|
2018-11-26 06:06:13 +00:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
|
|
|
|
2021-11-12 03:15:51 +00:00
|
|
|
const DisplayInfo display_info;
|
2018-03-21 10:09:40 +00:00
|
|
|
ctx.WriteBuffer(&display_info, sizeof(DisplayInfo));
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 10:09:40 +00:00
|
|
|
rb.Push<u64>(1);
|
|
|
|
}
|
2018-01-08 23:18:50 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void OpenLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const auto name_buf = rp.PopRaw<std::array<u8, 0x40>>();
|
|
|
|
const auto end = std::find(name_buf.begin(), name_buf.end(), '\0');
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2019-01-03 00:42:08 +00:00
|
|
|
const std::string display_name(name_buf.begin(), end);
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const u64 aruid = rp.Pop<u64>();
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2019-01-03 00:42:08 +00:00
|
|
|
LOG_DEBUG(Service_VI, "called. layer_id=0x{:016X}, aruid=0x{:016X}", layer_id, aruid);
|
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto display_id = nv_flinger.OpenDisplay(display_name);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!display_id) {
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Layer not found! layer_id={}", layer_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto buffer_queue_id = nv_flinger.FindBufferQueueId(*display_id, layer_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!buffer_queue_id) {
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", *display_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-12 03:15:51 +00:00
|
|
|
const auto parcel = android::Parcel{NativeWindow{*buffer_queue_id}};
|
|
|
|
const auto buffer_size = ctx.WriteBuffer(parcel.Serialize());
|
2021-04-19 16:45:26 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-04-19 16:45:26 +00:00
|
|
|
rb.Push<u64>(buffer_size);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2020-01-04 05:45:06 +00:00
|
|
|
void CloseLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto layer_id{rp.Pop<u64>()};
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_VI, "called. layer_id=0x{:016X}", layer_id);
|
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
nv_flinger.CloseLayer(layer_id);
|
2020-01-04 05:45:06 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2020-01-04 05:45:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void CreateStrayLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u32 flags = rp.Pop<u32>();
|
2018-03-21 10:09:40 +00:00
|
|
|
rp.Pop<u32>(); // padding
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_VI, "called. flags=0x{:08X}, display_id=0x{:016X}", flags, display_id);
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
// TODO(Subv): What's the difference between a Stray and a Managed layer?
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto layer_id = nv_flinger.CreateLayer(display_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!layer_id) {
|
2021-08-19 16:33:07 +00:00
|
|
|
LOG_ERROR(Service_VI, "Layer not found! display_id={}", display_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto buffer_queue_id = nv_flinger.FindBufferQueueId(display_id, *layer_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!buffer_queue_id) {
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", display_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-15 22:20:08 +00:00
|
|
|
|
2021-11-12 03:15:51 +00:00
|
|
|
const auto parcel = android::Parcel{NativeWindow{*buffer_queue_id}};
|
|
|
|
const auto buffer_size = ctx.WriteBuffer(parcel.Serialize());
|
2021-04-19 16:45:26 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2019-02-05 21:20:04 +00:00
|
|
|
rb.Push(*layer_id);
|
2021-04-19 16:45:26 +00:00
|
|
|
rb.Push<u64>(buffer_size);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void DestroyStrayLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}", layer_id);
|
2018-02-07 12:11:17 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2018-03-21 10:09:40 +00:00
|
|
|
void GetDisplayVsyncEvent(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-03 00:42:08 +00:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. display_id=0x{:016X}", display_id);
|
2018-01-08 23:29:43 +00:00
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
const auto vsync_event = nv_flinger.FindVsyncEvent(display_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
if (!vsync_event) {
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Vsync event was not found for display_id={}", display_id);
|
2019-02-05 21:20:04 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-21 10:09:40 +00:00
|
|
|
|
2018-09-19 05:09:59 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-04-10 09:34:26 +00:00
|
|
|
rb.PushCopyObjects(vsync_event);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 15:25:42 +00:00
|
|
|
void ConvertScalingMode(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-05 00:55:01 +00:00
|
|
|
const auto mode = rp.PopEnum<NintendoScaleMode>();
|
2020-12-08 03:00:34 +00:00
|
|
|
LOG_DEBUG(Service_VI, "called mode={}", mode);
|
2018-10-16 15:25:42 +00:00
|
|
|
|
2019-01-05 00:55:01 +00:00
|
|
|
const auto converted_mode = ConvertScalingModeImpl(mode);
|
|
|
|
|
|
|
|
if (converted_mode.Succeeded()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2019-01-05 00:55:01 +00:00
|
|
|
rb.PushEnum(*converted_mode);
|
|
|
|
} else {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(converted_mode.Code());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 12:07:24 +00:00
|
|
|
void GetIndirectLayerImageMap(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto width = rp.Pop<s64>();
|
|
|
|
const auto height = rp.Pop<s64>();
|
|
|
|
const auto indirect_layer_consumer_handle = rp.Pop<u64>();
|
|
|
|
const auto applet_resource_user_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI,
|
|
|
|
"(STUBBED) called, width={}, height={}, indirect_layer_consumer_handle={}, "
|
|
|
|
"applet_resource_user_id={}",
|
|
|
|
width, height, indirect_layer_consumer_handle, applet_resource_user_id);
|
|
|
|
|
|
|
|
std::vector<u8> out_buffer(0x46);
|
|
|
|
ctx.WriteBuffer(out_buffer);
|
|
|
|
|
|
|
|
// TODO: Figure out what these are
|
|
|
|
|
|
|
|
constexpr s64 unknown_result_1 = 0;
|
|
|
|
constexpr s64 unknown_result_2 = 0;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
|
|
|
rb.Push(unknown_result_1);
|
|
|
|
rb.Push(unknown_result_2);
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-03-10 12:07:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 13:06:18 +00:00
|
|
|
void GetIndirectLayerImageRequiredMemoryInfo(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto width = rp.Pop<u64>();
|
|
|
|
const auto height = rp.Pop<u64>();
|
|
|
|
LOG_DEBUG(Service_VI, "called width={}, height={}", width, height);
|
|
|
|
|
2020-08-31 14:34:46 +00:00
|
|
|
constexpr u64 base_size = 0x20000;
|
|
|
|
constexpr u64 alignment = 0x1000;
|
2020-07-21 13:06:18 +00:00
|
|
|
const auto texture_size = width * height * 4;
|
|
|
|
const auto out_size = (texture_size + base_size - 1) / base_size * base_size;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-21 13:06:18 +00:00
|
|
|
rb.Push(out_size);
|
|
|
|
rb.Push(alignment);
|
|
|
|
}
|
|
|
|
|
2019-01-05 00:55:01 +00:00
|
|
|
static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) {
|
2018-10-16 15:25:42 +00:00
|
|
|
switch (mode) {
|
|
|
|
case NintendoScaleMode::None:
|
2021-11-02 21:23:19 +00:00
|
|
|
return ConvertedScaleMode::None;
|
2018-10-16 15:25:42 +00:00
|
|
|
case NintendoScaleMode::Freeze:
|
2021-11-02 21:23:19 +00:00
|
|
|
return ConvertedScaleMode::Freeze;
|
2018-10-16 15:25:42 +00:00
|
|
|
case NintendoScaleMode::ScaleToWindow:
|
2021-11-02 21:23:19 +00:00
|
|
|
return ConvertedScaleMode::ScaleToWindow;
|
2019-01-05 01:32:29 +00:00
|
|
|
case NintendoScaleMode::ScaleAndCrop:
|
2021-11-02 21:23:19 +00:00
|
|
|
return ConvertedScaleMode::ScaleAndCrop;
|
2019-01-05 01:32:29 +00:00
|
|
|
case NintendoScaleMode::PreserveAspectRatio:
|
2021-11-02 21:23:19 +00:00
|
|
|
return ConvertedScaleMode::PreserveAspectRatio;
|
2018-10-16 15:25:42 +00:00
|
|
|
default:
|
2020-04-29 01:15:21 +00:00
|
|
|
LOG_ERROR(Service_VI, "Invalid scaling mode specified, mode={}", mode);
|
2019-01-05 00:55:01 +00:00
|
|
|
return ERR_OPERATION_FAILED;
|
2018-10-16 15:25:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:31:58 +00:00
|
|
|
NVFlinger::NVFlinger& nv_flinger;
|
2021-11-12 03:15:51 +00:00
|
|
|
NVFlinger::HosBinderDriverServer& hos_binder_driver_server;
|
2018-03-21 10:09:40 +00:00
|
|
|
};
|
2018-01-08 02:27:58 +00:00
|
|
|
|
2019-02-26 22:49:32 +00:00
|
|
|
static bool IsValidServiceAccess(Permission permission, Policy policy) {
|
|
|
|
if (permission == Permission::User) {
|
|
|
|
return policy == Policy::User;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (permission == Permission::System || permission == Permission::Manager) {
|
|
|
|
return policy == Policy::User || policy == Policy::Compositor;
|
|
|
|
}
|
2018-03-21 10:09:40 +00:00
|
|
|
|
2019-02-26 22:49:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.
The cause of the above mentioned non-obvious errors can be demonstrated
as follows:
------- Demonstrative example, if you know how the described error happens, skip forwards -------
Assume we have the following in the header, which we'll call "thing.h":
\#include <memory>
// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;
class Thing {
public:
// assume no constructors or destructors are specified here,
// or the constructors/destructors are defined as:
//
// Thing() = default;
// ~Thing() = default;
//
// ... Some interface member functions would be defined here
private:
std::shared_ptr<Object> obj;
};
If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:
1. Decrement the shared reference count of the object being pointed to,
and if the reference count decrements to zero,
2. Free the Object instance's memory (aka deallocate the memory it's
pointing to).
And so the compiler generates the code for the destructor doing this inside main.cpp.
Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.
Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.
---------------------- End example ----------------------------
Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-11 01:20:52 +00:00
|
|
|
|
2020-11-26 20:19:08 +00:00
|
|
|
void detail::GetDisplayServiceImpl(Kernel::HLERequestContext& ctx, Core::System& system,
|
2021-11-12 03:15:51 +00:00
|
|
|
NVFlinger::NVFlinger& nv_flinger,
|
|
|
|
NVFlinger::HosBinderDriverServer& hos_binder_driver_server,
|
|
|
|
Permission permission) {
|
2019-02-26 22:49:32 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto policy = rp.PopEnum<Policy>();
|
|
|
|
|
|
|
|
if (!IsValidServiceAccess(permission, policy)) {
|
2020-12-08 03:00:34 +00:00
|
|
|
LOG_ERROR(Service_VI, "Permission denied for policy {}", policy);
|
2019-02-26 22:49:32 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-21 10:09:40 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-12 03:15:51 +00:00
|
|
|
rb.PushIpcInterface<IApplicationDisplayService>(system, nv_flinger, hos_binder_driver_server);
|
2018-03-21 10:09:40 +00:00
|
|
|
}
|
|
|
|
|
2020-11-26 20:19:08 +00:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system,
|
2021-11-12 03:15:51 +00:00
|
|
|
NVFlinger::NVFlinger& nv_flinger,
|
|
|
|
NVFlinger::HosBinderDriverServer& hos_binder_driver_server) {
|
|
|
|
std::make_shared<VI_M>(system, nv_flinger, hos_binder_driver_server)
|
|
|
|
->InstallAsService(service_manager);
|
|
|
|
std::make_shared<VI_S>(system, nv_flinger, hos_binder_driver_server)
|
|
|
|
->InstallAsService(service_manager);
|
|
|
|
std::make_shared<VI_U>(system, nv_flinger, hos_binder_driver_server)
|
|
|
|
->InstallAsService(service_manager);
|
2018-01-08 02:27:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 01:41:44 +00:00
|
|
|
} // namespace Service::VI
|