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-09-13 16:43:31 -04:00
|
|
|
#include <cstring>
|
2018-03-21 06:09:40 -04:00
|
|
|
#include <memory>
|
2018-10-30 00:03:25 -04:00
|
|
|
#include <optional>
|
2018-07-23 14:52:32 -04:00
|
|
|
#include <type_traits>
|
2018-07-23 14:48:53 -04:00
|
|
|
#include <utility>
|
2018-10-30 00:03:25 -04:00
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
#include "common/alignment.h"
|
2018-09-13 16:43:31 -04:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/logging/log.h"
|
2018-07-17 20:11:41 -04:00
|
|
|
#include "common/math_util.h"
|
2021-04-14 19:07:40 -04:00
|
|
|
#include "common/settings.h"
|
2018-09-13 16:43:31 -04:00
|
|
|
#include "common/swap.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"
|
2021-01-30 01:48:06 -05:00
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
2020-12-31 02:01:08 -05:00
|
|
|
#include "core/hle/kernel/k_thread.h"
|
2019-06-07 11:34:55 -04:00
|
|
|
#include "core/hle/service/nvdrv/nvdata.h"
|
2021-11-11 22:15:51 -05: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 16:43:31 -04:00
|
|
|
#include "core/hle/service/nvflinger/nvflinger.h"
|
2021-11-11 22:15:51 -05:00
|
|
|
#include "core/hle/service/nvflinger/parcel.h"
|
2019-02-26 17:20:02 -05:00
|
|
|
#include "core/hle/service/service.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-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
|
|
|
|
2019-01-04 19:31:14 -05:00
|
|
|
constexpr ResultCode ERR_OPERATION_FAILED{ErrorModule::VI, 1};
|
2019-02-26 17:49:32 -05:00
|
|
|
constexpr ResultCode ERR_PERMISSION_DENIED{ErrorModule::VI, 5};
|
2019-01-04 19:31:14 -05:00
|
|
|
constexpr ResultCode ERR_UNSUPPORTED{ErrorModule::VI, 6};
|
2019-02-05 16:20:04 -05:00
|
|
|
constexpr ResultCode ERR_NOT_FOUND{ErrorModule::VI, 7};
|
2019-01-04 19:31:14 -05:00
|
|
|
|
2018-02-07 07:11:17 -05:00
|
|
|
struct DisplayInfo {
|
2019-01-02 15:26:41 -05:00
|
|
|
/// The name of this particular display.
|
2018-02-07 07:11:17 -05:00
|
|
|
char display_name[0x40]{"Default"};
|
2019-01-02 15:26:41 -05:00
|
|
|
|
|
|
|
/// Whether or not the display has a limited number of layers.
|
|
|
|
u8 has_limited_layers{1};
|
2019-11-03 18:54:03 -05:00
|
|
|
INSERT_PADDING_BYTES(7);
|
2019-01-02 15:26:41 -05: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 16:14:40 -05:00
|
|
|
u64 width{1920};
|
2019-01-02 15:26:41 -05:00
|
|
|
|
|
|
|
/// Maximum height in pixels.
|
2019-01-02 16:14:40 -05:00
|
|
|
u64 height{1080};
|
2018-02-07 07:11:17 -05:00
|
|
|
};
|
|
|
|
static_assert(sizeof(DisplayInfo) == 0x60, "DisplayInfo has wrong size");
|
|
|
|
|
2021-11-11 22:15:51 -05:00
|
|
|
class NativeWindow final {
|
2018-01-07 21:27:58 -05:00
|
|
|
public:
|
2021-11-11 22:15:51 -05:00
|
|
|
constexpr explicit NativeWindow(u32 id_) : id{id_} {}
|
2018-01-21 11:13:47 -05:00
|
|
|
|
|
|
|
private:
|
2021-11-11 22:15:51 -05:00
|
|
|
const u32 magic = 2;
|
|
|
|
const u32 process_id = 1;
|
|
|
|
const u32 id;
|
2022-03-20 03:48:02 -04: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 11:13:47 -05:00
|
|
|
};
|
2022-03-20 03:48:02 -04:00
|
|
|
static_assert(sizeof(NativeWindow) == 0x28, "NativeWindow has wrong size");
|
2018-01-21 11:13:47 -05:00
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> {
|
|
|
|
public:
|
2021-11-11 22:15:51 -05:00
|
|
|
explicit IHOSBinderDriver(Core::System& system_, NVFlinger::HosBinderDriverServer& server_)
|
|
|
|
: ServiceFramework{system_, "IHOSBinderDriver"}, server(server_) {
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-02-13 21:54:12 -05:00
|
|
|
void TransactParcel(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u32 id = rp.Pop<u32>();
|
2021-11-11 22:15:51 -05:00
|
|
|
const auto transaction = static_cast<android::TransactionId>(rp.Pop<u32>());
|
2019-01-02 19:42:08 -05:00
|
|
|
const u32 flags = rp.Pop<u32>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id,
|
2020-12-07 22:00:34 -05:00
|
|
|
transaction, flags);
|
2018-02-13 21:54:12 -05:00
|
|
|
|
2021-11-11 22:15:51 -05:00
|
|
|
server.TryGetProducer(id)->Transact(ctx, transaction, flags);
|
2018-02-09 22:50:29 -05:00
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdjustRefcount(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u32 id = rp.Pop<u32>();
|
|
|
|
const s32 addval = rp.PopRaw<s32>();
|
|
|
|
const 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-11-26 01:06:13 -05:00
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
2018-01-15 17:20:08 -05:00
|
|
|
void GetNativeHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u32 id = rp.Pop<u32>();
|
|
|
|
const u32 unknown = rp.Pop<u32>();
|
|
|
|
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called id={}, unknown={:08X}", id, unknown);
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-01-23 19:52:18 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-11 22:15:51 -05:00
|
|
|
rb.PushCopyObjects(server.TryGetProducer(id)->GetNativeHandle());
|
2018-01-15 17:20:08 -05:00
|
|
|
}
|
|
|
|
|
2021-11-11 22:15:51 -05:00
|
|
|
private:
|
|
|
|
NVFlinger::HosBinderDriverServer& server;
|
2020-11-24 17:31:58 -05:00
|
|
|
};
|
2018-01-07 21:27:58 -05:00
|
|
|
|
|
|
|
class ISystemDisplayService final : public ServiceFramework<ISystemDisplayService> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit ISystemDisplayService(Core::System& system_)
|
|
|
|
: ServiceFramework{system_, "ISystemDisplayService"} {
|
2018-01-07 21:27:58 -05:00
|
|
|
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"},
|
2021-04-07 10:41:20 -04:00
|
|
|
{2210, nullptr, "SetLayerPositionAndSize"},
|
2018-04-17 11:37:43 -04: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 11:19:31 -04:00
|
|
|
{3200, &ISystemDisplayService::GetDisplayMode, "GetDisplayMode"},
|
2018-04-17 11:37:43 -04: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 10:41:20 -04:00
|
|
|
{3218, nullptr, "SetDisplayCrcMode"},
|
2020-06-28 22:01:34 -04:00
|
|
|
{6013, nullptr, "GetLayerPresentationSubmissionTimestamps"},
|
2018-04-17 11:37:43 -04: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 10:41:20 -04:00
|
|
|
{9000, nullptr, "GetDp2hdmiController"},
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SetLayerZ(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05: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-07 21:27:58 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
2018-04-16 05:04:34 -04:00
|
|
|
|
2019-01-28 08:21:34 -05: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 05:04:34 -04:00
|
|
|
void SetLayerVisibility(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const bool visibility = rp.Pop<bool>();
|
|
|
|
|
2019-01-28 08:21:34 -05:00
|
|
|
LOG_DEBUG(Service_VI, "called, layer_id=0x{:08X}, visibility={}", layer_id, visibility);
|
2018-11-26 01:06:13 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-16 05:04:34 -04:00
|
|
|
}
|
2018-09-17 11:19:31 -04:00
|
|
|
|
|
|
|
void GetDisplayMode(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
|
|
|
|
2018-09-17 11:19:31 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-09-17 11:19:31 -04:00
|
|
|
|
2020-09-28 10:00:15 -04:00
|
|
|
if (Settings::values.use_docked_mode.GetValue()) {
|
2021-07-20 12:29:52 -04:00
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedWidth));
|
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::DockedHeight));
|
2018-09-17 11:19:31 -04:00
|
|
|
} else {
|
2021-07-20 12:29:52 -04:00
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedWidth));
|
|
|
|
rb.Push(static_cast<u32>(Service::VI::DisplayResolution::UndockedHeight));
|
2018-09-17 11:19:31 -04:00
|
|
|
}
|
|
|
|
|
2018-11-26 01:06:13 -05:00
|
|
|
rb.PushRaw<float>(60.0f); // This wouldn't seem to be correct for 30 fps games.
|
2018-09-17 11:19:31 -04:00
|
|
|
rb.Push<u32>(0);
|
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit IManagerDisplayService(Core::System& system_, NVFlinger::NVFlinger& nv_flinger_)
|
|
|
|
: ServiceFramework{system_, "IManagerDisplayService"}, nv_flinger{nv_flinger_} {
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format off
|
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"},
|
2019-02-25 08:06:47 -05:00
|
|
|
{2012, nullptr, "CreateStrayLayer"},
|
2018-04-17 11:37:43 -04: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-28 22:01:34 -04:00
|
|
|
{2303, nullptr, "GetDisplayModeChangedEvent"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{2402, nullptr, "GetDisplayHotplugState"},
|
|
|
|
{2501, nullptr, "GetCompositorErrorInfo"},
|
|
|
|
{2601, nullptr, "GetDisplayErrorEvent"},
|
2021-04-07 10:41:20 -04:00
|
|
|
{2701, nullptr, "GetDisplayFatalErrorEvent"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{4201, nullptr, "SetDisplayAlpha"},
|
|
|
|
{4203, nullptr, "SetDisplayLayerStack"},
|
|
|
|
{4205, nullptr, "SetDisplayPowerState"},
|
|
|
|
{4206, nullptr, "SetDefaultDisplay"},
|
2021-04-07 10:41:20 -04:00
|
|
|
{4207, nullptr, "ResetDisplayPanel"},
|
|
|
|
{4208, nullptr, "SetDisplayFatalErrorEnabled"},
|
|
|
|
{4209, nullptr, "IsDisplayPanelOn"},
|
|
|
|
{4300, nullptr, "GetInternalPanelId"},
|
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"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{6011, nullptr, "EnableLayerAutoClearTransitionBuffer"},
|
|
|
|
{6012, nullptr, "DisableLayerAutoClearTransitionBuffer"},
|
2021-09-26 21:11:39 -04:00
|
|
|
{6013, nullptr, "SetLayerOpacity"},
|
2018-04-17 11:37:43 -04:00
|
|
|
{7000, nullptr, "SetContentVisibility"},
|
|
|
|
{8000, nullptr, "SetConductorLayer"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{8001, nullptr, "SetTimestampTracking"},
|
2018-04-17 11:37:43 -04: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-07 21:27:58 -05:00
|
|
|
};
|
2019-11-12 08:54:58 -05:00
|
|
|
// clang-format on
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-01-15 01:29:00 -05:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 display = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. display=0x{:016X}", display);
|
2018-01-15 01:29:00 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-15 01:29:00 -05:00
|
|
|
}
|
|
|
|
|
2018-01-07 21:27:58 -05:00
|
|
|
void CreateManagedLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u32 unknown = rp.Pop<u32>();
|
2018-01-07 21:27:58 -05:00
|
|
|
rp.Skip(1, false);
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 display = rp.Pop<u64>();
|
|
|
|
const u64 aruid = rp.Pop<u64>();
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2019-01-02 19:42:08 -05:00
|
|
|
LOG_WARNING(Service_VI,
|
|
|
|
"(STUBBED) called. unknown=0x{:08X}, display=0x{:016X}, aruid=0x{:016X}",
|
|
|
|
unknown, display, aruid);
|
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto layer_id = nv_flinger.CreateLayer(display);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!layer_id) {
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Layer not found! display=0x{:016X}", display);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-02-05 16:20:04 -05:00
|
|
|
rb.Push(*layer_id);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddToLayerStack(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05: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-07 21:27:58 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-01-07 21:27:58 -05:00
|
|
|
}
|
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};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const bool visibility = rp.Pop<bool>();
|
|
|
|
|
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-11-26 01:06:13 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-16 05:04:34 -04:00
|
|
|
}
|
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
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:
|
2021-11-11 22:15:51 -05: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-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
private:
|
2019-01-04 19:31:14 -05:00
|
|
|
enum class ConvertedScaleMode : u64 {
|
2019-01-04 20:32:29 -05:00
|
|
|
Freeze = 0,
|
|
|
|
ScaleToWindow = 1,
|
|
|
|
ScaleAndCrop = 2,
|
|
|
|
None = 3,
|
|
|
|
PreserveAspectRatio = 4,
|
2019-01-04 19:31:14 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class NintendoScaleMode : u32 {
|
|
|
|
None = 0,
|
|
|
|
Freeze = 1,
|
|
|
|
ScaleToWindow = 2,
|
2019-01-04 20:32:29 -05:00
|
|
|
ScaleAndCrop = 3,
|
|
|
|
PreserveAspectRatio = 4,
|
2019-01-04 19:31:14 -05:00
|
|
|
};
|
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
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};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-11 22:15:51 -05:00
|
|
|
rb.PushIpcInterface<IHOSBinderDriver>(system, hos_binder_driver_server);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
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};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<ISystemDisplayService>(system);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
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};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<IManagerDisplayService>(system, nv_flinger);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
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};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-11 22:15:51 -05:00
|
|
|
rb.PushIpcInterface<IHOSBinderDriver>(system, hos_binder_driver_server);
|
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 OpenDisplay(Kernel::HLERequestContext& ctx) {
|
2018-07-02 12:13:26 -04:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
2018-11-26 01:06:13 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 18:05:15 -05:00
|
|
|
const auto name_buf = rp.PopRaw<std::array<char, 0x40>>();
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2019-01-02 18:05:15 -05: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 18:18:50 -05:00
|
|
|
|
2019-01-02 18:05:15 -05: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-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
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto display_id = nv_flinger.OpenDisplay(name);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!display_id) {
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Display not found! display_name={}", name);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-02-05 16:20:04 -05:00
|
|
|
rb.Push<u64>(*display_id);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void CloseDisplay(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. display_id=0x{:016X}", display_id);
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2019-01-02 20:45:40 -05: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 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-01-02 20:45:40 -05:00
|
|
|
}
|
|
|
|
|
2018-04-02 23:28:45 -04:00
|
|
|
void GetDisplayResolution(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
2019-01-04 18:43:15 -05:00
|
|
|
LOG_DEBUG(Service_VI, "called. display_id=0x{:016X}", display_id);
|
2018-04-02 23:28:45 -04:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-04-02 23:28:45 -04:00
|
|
|
|
2019-01-04 18:43:15 -05: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 12:29:52 -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) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-04 19:31:14 -05:00
|
|
|
const auto scaling_mode = rp.PopEnum<NintendoScaleMode>();
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 unknown = rp.Pop<u64>();
|
|
|
|
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_DEBUG(Service_VI, "called. scaling_mode=0x{:08X}, unknown=0x{:016X}", scaling_mode,
|
|
|
|
unknown);
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2019-01-04 19:31:14 -05:00
|
|
|
|
2019-01-04 20:32:29 -05:00
|
|
|
if (scaling_mode > NintendoScaleMode::PreserveAspectRatio) {
|
2019-01-04 19:31:14 -05:00
|
|
|
LOG_ERROR(Service_VI, "Invalid scaling mode provided.");
|
|
|
|
rb.Push(ERR_OPERATION_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scaling_mode != NintendoScaleMode::ScaleToWindow &&
|
2019-01-04 20:32:29 -05:00
|
|
|
scaling_mode != NintendoScaleMode::PreserveAspectRatio) {
|
2019-01-04 19:31:14 -05:00
|
|
|
LOG_ERROR(Service_VI, "Unsupported scaling mode supplied.");
|
|
|
|
rb.Push(ERR_UNSUPPORTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void ListDisplays(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called");
|
|
|
|
|
2021-11-11 22:15:51 -05:00
|
|
|
const DisplayInfo display_info;
|
2018-03-21 06:09:40 -04:00
|
|
|
ctx.WriteBuffer(&display_info, sizeof(DisplayInfo));
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 06:09:40 -04:00
|
|
|
rb.Push<u64>(1);
|
|
|
|
}
|
2018-01-08 18:18:50 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void OpenLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05: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-07 21:27:58 -05:00
|
|
|
|
2019-01-02 19:42:08 -05:00
|
|
|
const std::string display_name(name_buf.begin(), end);
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
const u64 aruid = rp.Pop<u64>();
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2019-01-02 19:42:08 -05:00
|
|
|
LOG_DEBUG(Service_VI, "called. layer_id=0x{:016X}, aruid=0x{:016X}", layer_id, aruid);
|
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto display_id = nv_flinger.OpenDisplay(display_name);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!display_id) {
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Layer not found! layer_id={}", layer_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto buffer_queue_id = nv_flinger.FindBufferQueueId(*display_id, layer_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!buffer_queue_id) {
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", *display_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-11 22:15:51 -05:00
|
|
|
const auto parcel = android::Parcel{NativeWindow{*buffer_queue_id}};
|
|
|
|
const auto buffer_size = ctx.WriteBuffer(parcel.Serialize());
|
2021-04-19 12:45:26 -04:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-04-19 12:45:26 -04:00
|
|
|
rb.Push<u64>(buffer_size);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2020-01-04 00:45:06 -05: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 17:31:58 -05:00
|
|
|
nv_flinger.CloseLayer(layer_id);
|
2020-01-04 00:45:06 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-01-04 00:45:06 -05:00
|
|
|
}
|
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void CreateStrayLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u32 flags = rp.Pop<u32>();
|
2018-03-21 06:09:40 -04:00
|
|
|
rp.Pop<u32>(); // padding
|
2019-01-02 19:42:08 -05: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 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
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto layer_id = nv_flinger.CreateLayer(display_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!layer_id) {
|
2021-08-19 12:33:07 -04:00
|
|
|
LOG_ERROR(Service_VI, "Layer not found! display_id={}", display_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto buffer_queue_id = nv_flinger.FindBufferQueueId(display_id, *layer_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!buffer_queue_id) {
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", display_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-15 17:20:08 -05:00
|
|
|
|
2021-11-11 22:15:51 -05:00
|
|
|
const auto parcel = android::Parcel{NativeWindow{*buffer_queue_id}};
|
|
|
|
const auto buffer_size = ctx.WriteBuffer(parcel.Serialize());
|
2021-04-19 12:45:26 -04:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-02-05 16:20:04 -05:00
|
|
|
rb.Push(*layer_id);
|
2021-04-19 12:45:26 -04:00
|
|
|
rb.Push<u64>(buffer_size);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void DestroyStrayLayer(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 layer_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}", layer_id);
|
2018-02-07 07:11:17 -05:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2018-03-21 06:09:40 -04:00
|
|
|
void GetDisplayVsyncEvent(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-02 19:42:08 -05:00
|
|
|
const u64 display_id = rp.Pop<u64>();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_VI, "(STUBBED) called. display_id=0x{:016X}", display_id);
|
2018-01-08 18:29:43 -05:00
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
const auto vsync_event = nv_flinger.FindVsyncEvent(display_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
if (!vsync_event) {
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Vsync event was not found for display_id={}", display_id);
|
2019-02-05 16:20:04 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_NOT_FOUND);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-21 06:09:40 -04:00
|
|
|
|
2018-09-19 01:09:59 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-04-10 05:34:26 -04:00
|
|
|
rb.PushCopyObjects(vsync_event);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
|
|
|
|
2018-10-16 11:25:42 -04:00
|
|
|
void ConvertScalingMode(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2019-01-04 19:55:01 -05:00
|
|
|
const auto mode = rp.PopEnum<NintendoScaleMode>();
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_DEBUG(Service_VI, "called mode={}", mode);
|
2018-10-16 11:25:42 -04:00
|
|
|
|
2019-01-04 19:55:01 -05:00
|
|
|
const auto converted_mode = ConvertScalingModeImpl(mode);
|
|
|
|
|
|
|
|
if (converted_mode.Succeeded()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 4};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-01-04 19:55:01 -05:00
|
|
|
rb.PushEnum(*converted_mode);
|
|
|
|
} else {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(converted_mode.Code());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 07:07:24 -05: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 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-03-10 07:07:24 -05:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:06:18 -04: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 10:34:46 -04:00
|
|
|
constexpr u64 base_size = 0x20000;
|
|
|
|
constexpr u64 alignment = 0x1000;
|
2020-07-21 09:06:18 -04: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 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-21 09:06:18 -04:00
|
|
|
rb.Push(out_size);
|
|
|
|
rb.Push(alignment);
|
|
|
|
}
|
|
|
|
|
2019-01-04 19:55:01 -05:00
|
|
|
static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) {
|
2018-10-16 11:25:42 -04:00
|
|
|
switch (mode) {
|
|
|
|
case NintendoScaleMode::None:
|
2021-11-02 17:23:19 -04:00
|
|
|
return ConvertedScaleMode::None;
|
2018-10-16 11:25:42 -04:00
|
|
|
case NintendoScaleMode::Freeze:
|
2021-11-02 17:23:19 -04:00
|
|
|
return ConvertedScaleMode::Freeze;
|
2018-10-16 11:25:42 -04:00
|
|
|
case NintendoScaleMode::ScaleToWindow:
|
2021-11-02 17:23:19 -04:00
|
|
|
return ConvertedScaleMode::ScaleToWindow;
|
2019-01-04 20:32:29 -05:00
|
|
|
case NintendoScaleMode::ScaleAndCrop:
|
2021-11-02 17:23:19 -04:00
|
|
|
return ConvertedScaleMode::ScaleAndCrop;
|
2019-01-04 20:32:29 -05:00
|
|
|
case NintendoScaleMode::PreserveAspectRatio:
|
2021-11-02 17:23:19 -04:00
|
|
|
return ConvertedScaleMode::PreserveAspectRatio;
|
2018-10-16 11:25:42 -04:00
|
|
|
default:
|
2020-04-28 21:15:21 -04:00
|
|
|
LOG_ERROR(Service_VI, "Invalid scaling mode specified, mode={}", mode);
|
2019-01-04 19:55:01 -05:00
|
|
|
return ERR_OPERATION_FAILED;
|
2018-10-16 11:25:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 17:31:58 -05:00
|
|
|
NVFlinger::NVFlinger& nv_flinger;
|
2021-11-11 22:15:51 -05:00
|
|
|
NVFlinger::HosBinderDriverServer& hos_binder_driver_server;
|
2018-03-21 06:09:40 -04:00
|
|
|
};
|
2018-01-07 21:27:58 -05:00
|
|
|
|
2019-02-26 17:49:32 -05: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 06:09:40 -04:00
|
|
|
|
2019-02-26 17:49:32 -05: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-10 21:20:52 -04:00
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
void detail::GetDisplayServiceImpl(Kernel::HLERequestContext& ctx, Core::System& system,
|
2021-11-11 22:15:51 -05:00
|
|
|
NVFlinger::NVFlinger& nv_flinger,
|
|
|
|
NVFlinger::HosBinderDriverServer& hos_binder_driver_server,
|
|
|
|
Permission permission) {
|
2019-02-26 17:49:32 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto policy = rp.PopEnum<Policy>();
|
|
|
|
|
|
|
|
if (!IsValidServiceAccess(permission, policy)) {
|
2020-12-07 22:00:34 -05:00
|
|
|
LOG_ERROR(Service_VI, "Permission denied for policy {}", policy);
|
2019-02-26 17:49:32 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERR_PERMISSION_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-21 06:09:40 -04:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-11-11 22:15:51 -05:00
|
|
|
rb.PushIpcInterface<IApplicationDisplayService>(system, nv_flinger, hos_binder_driver_server);
|
2018-03-21 06:09:40 -04:00
|
|
|
}
|
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, Core::System& system,
|
2021-11-11 22:15:51 -05: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-07 21:27:58 -05:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::VI
|