diff options
Diffstat (limited to 'src')
45 files changed, 1636 insertions, 314 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 416203c59..8a1861051 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -189,6 +189,14 @@ if(ARCHITECTURE_x86_64) | |||
| 189 | target_link_libraries(common PRIVATE xbyak::xbyak) | 189 | target_link_libraries(common PRIVATE xbyak::xbyak) |
| 190 | endif() | 190 | endif() |
| 191 | 191 | ||
| 192 | if (ARCHITECTURE_arm64 AND (ANDROID OR LINUX)) | ||
| 193 | target_sources(common | ||
| 194 | PRIVATE | ||
| 195 | arm64/native_clock.cpp | ||
| 196 | arm64/native_clock.h | ||
| 197 | ) | ||
| 198 | endif() | ||
| 199 | |||
| 192 | if (MSVC) | 200 | if (MSVC) |
| 193 | target_compile_definitions(common PRIVATE | 201 | target_compile_definitions(common PRIVATE |
| 194 | # The standard library doesn't provide any replacement for codecvt yet | 202 | # The standard library doesn't provide any replacement for codecvt yet |
diff --git a/src/common/arm64/native_clock.cpp b/src/common/arm64/native_clock.cpp new file mode 100644 index 000000000..88fdba527 --- /dev/null +++ b/src/common/arm64/native_clock.cpp | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "common/arm64/native_clock.h" | ||
| 5 | |||
| 6 | namespace Common::Arm64 { | ||
| 7 | |||
| 8 | namespace { | ||
| 9 | |||
| 10 | NativeClock::FactorType GetFixedPointFactor(u64 num, u64 den) { | ||
| 11 | return (static_cast<NativeClock::FactorType>(num) << 64) / den; | ||
| 12 | } | ||
| 13 | |||
| 14 | u64 MultiplyHigh(u64 m, NativeClock::FactorType factor) { | ||
| 15 | return static_cast<u64>((m * factor) >> 64); | ||
| 16 | } | ||
| 17 | |||
| 18 | } // namespace | ||
| 19 | |||
| 20 | NativeClock::NativeClock() { | ||
| 21 | const u64 host_cntfrq = GetHostCNTFRQ(); | ||
| 22 | ns_cntfrq_factor = GetFixedPointFactor(NsRatio::den, host_cntfrq); | ||
| 23 | us_cntfrq_factor = GetFixedPointFactor(UsRatio::den, host_cntfrq); | ||
| 24 | ms_cntfrq_factor = GetFixedPointFactor(MsRatio::den, host_cntfrq); | ||
| 25 | guest_cntfrq_factor = GetFixedPointFactor(CNTFRQ, host_cntfrq); | ||
| 26 | gputick_cntfrq_factor = GetFixedPointFactor(GPUTickFreq, host_cntfrq); | ||
| 27 | } | ||
| 28 | |||
| 29 | std::chrono::nanoseconds NativeClock::GetTimeNS() const { | ||
| 30 | return std::chrono::nanoseconds{MultiplyHigh(GetHostTicksElapsed(), ns_cntfrq_factor)}; | ||
| 31 | } | ||
| 32 | |||
| 33 | std::chrono::microseconds NativeClock::GetTimeUS() const { | ||
| 34 | return std::chrono::microseconds{MultiplyHigh(GetHostTicksElapsed(), us_cntfrq_factor)}; | ||
| 35 | } | ||
| 36 | |||
| 37 | std::chrono::milliseconds NativeClock::GetTimeMS() const { | ||
| 38 | return std::chrono::milliseconds{MultiplyHigh(GetHostTicksElapsed(), ms_cntfrq_factor)}; | ||
| 39 | } | ||
| 40 | |||
| 41 | u64 NativeClock::GetCNTPCT() const { | ||
| 42 | return MultiplyHigh(GetHostTicksElapsed(), guest_cntfrq_factor); | ||
| 43 | } | ||
| 44 | |||
| 45 | u64 NativeClock::GetGPUTick() const { | ||
| 46 | return MultiplyHigh(GetHostTicksElapsed(), gputick_cntfrq_factor); | ||
| 47 | } | ||
| 48 | |||
| 49 | u64 NativeClock::GetHostTicksNow() const { | ||
| 50 | u64 cntvct_el0 = 0; | ||
| 51 | asm volatile("dsb ish\n\t" | ||
| 52 | "mrs %[cntvct_el0], cntvct_el0\n\t" | ||
| 53 | "dsb ish\n\t" | ||
| 54 | : [cntvct_el0] "=r"(cntvct_el0)); | ||
| 55 | return cntvct_el0; | ||
| 56 | } | ||
| 57 | |||
| 58 | u64 NativeClock::GetHostTicksElapsed() const { | ||
| 59 | return GetHostTicksNow(); | ||
| 60 | } | ||
| 61 | |||
| 62 | bool NativeClock::IsNative() const { | ||
| 63 | return true; | ||
| 64 | } | ||
| 65 | |||
| 66 | u64 NativeClock::GetHostCNTFRQ() { | ||
| 67 | u64 cntfrq_el0 = 0; | ||
| 68 | asm("mrs %[cntfrq_el0], cntfrq_el0" : [cntfrq_el0] "=r"(cntfrq_el0)); | ||
| 69 | return cntfrq_el0; | ||
| 70 | } | ||
| 71 | |||
| 72 | } // namespace Common::Arm64 | ||
diff --git a/src/common/arm64/native_clock.h b/src/common/arm64/native_clock.h new file mode 100644 index 000000000..a28b419f2 --- /dev/null +++ b/src/common/arm64/native_clock.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/wall_clock.h" | ||
| 7 | |||
| 8 | namespace Common::Arm64 { | ||
| 9 | |||
| 10 | class NativeClock final : public WallClock { | ||
| 11 | public: | ||
| 12 | explicit NativeClock(); | ||
| 13 | |||
| 14 | std::chrono::nanoseconds GetTimeNS() const override; | ||
| 15 | |||
| 16 | std::chrono::microseconds GetTimeUS() const override; | ||
| 17 | |||
| 18 | std::chrono::milliseconds GetTimeMS() const override; | ||
| 19 | |||
| 20 | u64 GetCNTPCT() const override; | ||
| 21 | |||
| 22 | u64 GetGPUTick() const override; | ||
| 23 | |||
| 24 | u64 GetHostTicksNow() const override; | ||
| 25 | |||
| 26 | u64 GetHostTicksElapsed() const override; | ||
| 27 | |||
| 28 | bool IsNative() const override; | ||
| 29 | |||
| 30 | static u64 GetHostCNTFRQ(); | ||
| 31 | |||
| 32 | public: | ||
| 33 | using FactorType = unsigned __int128; | ||
| 34 | |||
| 35 | FactorType GetGuestCNTFRQFactor() const { | ||
| 36 | return guest_cntfrq_factor; | ||
| 37 | } | ||
| 38 | |||
| 39 | private: | ||
| 40 | FactorType ns_cntfrq_factor; | ||
| 41 | FactorType us_cntfrq_factor; | ||
| 42 | FactorType ms_cntfrq_factor; | ||
| 43 | FactorType guest_cntfrq_factor; | ||
| 44 | FactorType gputick_cntfrq_factor; | ||
| 45 | }; | ||
| 46 | |||
| 47 | } // namespace Common::Arm64 | ||
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp index 71e15ab4c..caca9a123 100644 --- a/src/common/wall_clock.cpp +++ b/src/common/wall_clock.cpp | |||
| @@ -10,6 +10,10 @@ | |||
| 10 | #include "common/x64/rdtsc.h" | 10 | #include "common/x64/rdtsc.h" |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | #if defined(ARCHITECTURE_arm64) && defined(__linux__) | ||
| 14 | #include "common/arm64/native_clock.h" | ||
| 15 | #endif | ||
| 16 | |||
| 13 | namespace Common { | 17 | namespace Common { |
| 14 | 18 | ||
| 15 | class StandardWallClock final : public WallClock { | 19 | class StandardWallClock final : public WallClock { |
| @@ -53,7 +57,7 @@ private: | |||
| 53 | }; | 57 | }; |
| 54 | 58 | ||
| 55 | std::unique_ptr<WallClock> CreateOptimalClock() { | 59 | std::unique_ptr<WallClock> CreateOptimalClock() { |
| 56 | #ifdef ARCHITECTURE_x86_64 | 60 | #if defined(ARCHITECTURE_x86_64) |
| 57 | const auto& caps = GetCPUCaps(); | 61 | const auto& caps = GetCPUCaps(); |
| 58 | 62 | ||
| 59 | if (caps.invariant_tsc && caps.tsc_frequency >= std::nano::den) { | 63 | if (caps.invariant_tsc && caps.tsc_frequency >= std::nano::den) { |
| @@ -64,6 +68,8 @@ std::unique_ptr<WallClock> CreateOptimalClock() { | |||
| 64 | // - Is not more precise than 1 GHz (1ns resolution) | 68 | // - Is not more precise than 1 GHz (1ns resolution) |
| 65 | return std::make_unique<StandardWallClock>(); | 69 | return std::make_unique<StandardWallClock>(); |
| 66 | } | 70 | } |
| 71 | #elif defined(ARCHITECTURE_arm64) && defined(__linux__) | ||
| 72 | return std::make_unique<Arm64::NativeClock>(); | ||
| 67 | #else | 73 | #else |
| 68 | return std::make_unique<StandardWallClock>(); | 74 | return std::make_unique<StandardWallClock>(); |
| 69 | #endif | 75 | #endif |
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e02ededfc..e4f499135 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -466,14 +466,18 @@ add_library(core STATIC | |||
| 466 | hle/service/caps/caps_a.h | 466 | hle/service/caps/caps_a.h |
| 467 | hle/service/caps/caps_c.cpp | 467 | hle/service/caps/caps_c.cpp |
| 468 | hle/service/caps/caps_c.h | 468 | hle/service/caps/caps_c.h |
| 469 | hle/service/caps/caps_u.cpp | 469 | hle/service/caps/caps_manager.cpp |
| 470 | hle/service/caps/caps_u.h | 470 | hle/service/caps/caps_manager.h |
| 471 | hle/service/caps/caps_result.h | ||
| 471 | hle/service/caps/caps_sc.cpp | 472 | hle/service/caps/caps_sc.cpp |
| 472 | hle/service/caps/caps_sc.h | 473 | hle/service/caps/caps_sc.h |
| 473 | hle/service/caps/caps_ss.cpp | 474 | hle/service/caps/caps_ss.cpp |
| 474 | hle/service/caps/caps_ss.h | 475 | hle/service/caps/caps_ss.h |
| 475 | hle/service/caps/caps_su.cpp | 476 | hle/service/caps/caps_su.cpp |
| 476 | hle/service/caps/caps_su.h | 477 | hle/service/caps/caps_su.h |
| 478 | hle/service/caps/caps_types.h | ||
| 479 | hle/service/caps/caps_u.cpp | ||
| 480 | hle/service/caps/caps_u.h | ||
| 477 | hle/service/erpt/erpt.cpp | 481 | hle/service/erpt/erpt.cpp |
| 478 | hle/service/erpt/erpt.h | 482 | hle/service/erpt/erpt.h |
| 479 | hle/service/es/es.cpp | 483 | hle/service/es/es.cpp |
diff --git a/src/core/hle/kernel/k_page_table.cpp b/src/core/hle/kernel/k_page_table.cpp index 5b51edf30..1fbfbf31f 100644 --- a/src/core/hle/kernel/k_page_table.cpp +++ b/src/core/hle/kernel/k_page_table.cpp | |||
| @@ -2949,6 +2949,23 @@ Result KPageTable::UnlockForIpcUserBuffer(KProcessAddress address, size_t size) | |||
| 2949 | KMemoryAttribute::Locked, nullptr)); | 2949 | KMemoryAttribute::Locked, nullptr)); |
| 2950 | } | 2950 | } |
| 2951 | 2951 | ||
| 2952 | Result KPageTable::LockForTransferMemory(KPageGroup* out, KProcessAddress address, size_t size, | ||
| 2953 | KMemoryPermission perm) { | ||
| 2954 | R_RETURN(this->LockMemoryAndOpen(out, nullptr, address, size, KMemoryState::FlagCanTransfer, | ||
| 2955 | KMemoryState::FlagCanTransfer, KMemoryPermission::All, | ||
| 2956 | KMemoryPermission::UserReadWrite, KMemoryAttribute::All, | ||
| 2957 | KMemoryAttribute::None, perm, KMemoryAttribute::Locked)); | ||
| 2958 | } | ||
| 2959 | |||
| 2960 | Result KPageTable::UnlockForTransferMemory(KProcessAddress address, size_t size, | ||
| 2961 | const KPageGroup& pg) { | ||
| 2962 | R_RETURN(this->UnlockMemory(address, size, KMemoryState::FlagCanTransfer, | ||
| 2963 | KMemoryState::FlagCanTransfer, KMemoryPermission::None, | ||
| 2964 | KMemoryPermission::None, KMemoryAttribute::All, | ||
| 2965 | KMemoryAttribute::Locked, KMemoryPermission::UserReadWrite, | ||
| 2966 | KMemoryAttribute::Locked, std::addressof(pg))); | ||
| 2967 | } | ||
| 2968 | |||
| 2952 | Result KPageTable::LockForCodeMemory(KPageGroup* out, KProcessAddress addr, size_t size) { | 2969 | Result KPageTable::LockForCodeMemory(KPageGroup* out, KProcessAddress addr, size_t size) { |
| 2953 | R_RETURN(this->LockMemoryAndOpen( | 2970 | R_RETURN(this->LockMemoryAndOpen( |
| 2954 | out, nullptr, addr, size, KMemoryState::FlagCanCodeMemory, KMemoryState::FlagCanCodeMemory, | 2971 | out, nullptr, addr, size, KMemoryState::FlagCanCodeMemory, KMemoryState::FlagCanCodeMemory, |
diff --git a/src/core/hle/kernel/k_page_table.h b/src/core/hle/kernel/k_page_table.h index b9e8c6042..7da675f27 100644 --- a/src/core/hle/kernel/k_page_table.h +++ b/src/core/hle/kernel/k_page_table.h | |||
| @@ -104,6 +104,9 @@ public: | |||
| 104 | Result CleanupForIpcServer(KProcessAddress address, size_t size, KMemoryState dst_state); | 104 | Result CleanupForIpcServer(KProcessAddress address, size_t size, KMemoryState dst_state); |
| 105 | Result CleanupForIpcClient(KProcessAddress address, size_t size, KMemoryState dst_state); | 105 | Result CleanupForIpcClient(KProcessAddress address, size_t size, KMemoryState dst_state); |
| 106 | 106 | ||
| 107 | Result LockForTransferMemory(KPageGroup* out, KProcessAddress address, size_t size, | ||
| 108 | KMemoryPermission perm); | ||
| 109 | Result UnlockForTransferMemory(KProcessAddress address, size_t size, const KPageGroup& pg); | ||
| 107 | Result LockForCodeMemory(KPageGroup* out, KProcessAddress addr, size_t size); | 110 | Result LockForCodeMemory(KPageGroup* out, KProcessAddress addr, size_t size); |
| 108 | Result UnlockForCodeMemory(KProcessAddress addr, size_t size, const KPageGroup& pg); | 111 | Result UnlockForCodeMemory(KProcessAddress addr, size_t size, const KPageGroup& pg); |
| 109 | Result MakeAndOpenPageGroup(KPageGroup* out, KProcessAddress address, size_t num_pages, | 112 | Result MakeAndOpenPageGroup(KPageGroup* out, KProcessAddress address, size_t num_pages, |
diff --git a/src/core/hle/kernel/k_transfer_memory.cpp b/src/core/hle/kernel/k_transfer_memory.cpp index 13d34125c..0e2e11743 100644 --- a/src/core/hle/kernel/k_transfer_memory.cpp +++ b/src/core/hle/kernel/k_transfer_memory.cpp | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/scope_exit.h" | ||
| 4 | #include "core/hle/kernel/k_process.h" | 5 | #include "core/hle/kernel/k_process.h" |
| 5 | #include "core/hle/kernel/k_resource_limit.h" | 6 | #include "core/hle/kernel/k_resource_limit.h" |
| 6 | #include "core/hle/kernel/k_transfer_memory.h" | 7 | #include "core/hle/kernel/k_transfer_memory.h" |
| @@ -9,28 +10,50 @@ | |||
| 9 | namespace Kernel { | 10 | namespace Kernel { |
| 10 | 11 | ||
| 11 | KTransferMemory::KTransferMemory(KernelCore& kernel) | 12 | KTransferMemory::KTransferMemory(KernelCore& kernel) |
| 12 | : KAutoObjectWithSlabHeapAndContainer{kernel} {} | 13 | : KAutoObjectWithSlabHeapAndContainer{kernel}, m_lock{kernel} {} |
| 13 | 14 | ||
| 14 | KTransferMemory::~KTransferMemory() = default; | 15 | KTransferMemory::~KTransferMemory() = default; |
| 15 | 16 | ||
| 16 | Result KTransferMemory::Initialize(KProcessAddress address, std::size_t size, | 17 | Result KTransferMemory::Initialize(KProcessAddress addr, std::size_t size, |
| 17 | Svc::MemoryPermission owner_perm) { | 18 | Svc::MemoryPermission own_perm) { |
| 18 | // Set members. | 19 | // Set members. |
| 19 | m_owner = GetCurrentProcessPointer(m_kernel); | 20 | m_owner = GetCurrentProcessPointer(m_kernel); |
| 20 | 21 | ||
| 21 | // TODO(bunnei): Lock for transfer memory | 22 | // Get the owner page table. |
| 23 | auto& page_table = m_owner->GetPageTable(); | ||
| 24 | |||
| 25 | // Construct the page group, guarding to make sure our state is valid on exit. | ||
| 26 | m_page_group.emplace(m_kernel, page_table.GetBlockInfoManager()); | ||
| 27 | auto pg_guard = SCOPE_GUARD({ m_page_group.reset(); }); | ||
| 28 | |||
| 29 | // Lock the memory. | ||
| 30 | R_TRY(page_table.LockForTransferMemory(std::addressof(*m_page_group), addr, size, | ||
| 31 | ConvertToKMemoryPermission(own_perm))); | ||
| 22 | 32 | ||
| 23 | // Set remaining tracking members. | 33 | // Set remaining tracking members. |
| 24 | m_owner->Open(); | 34 | m_owner->Open(); |
| 25 | m_owner_perm = owner_perm; | 35 | m_owner_perm = own_perm; |
| 26 | m_address = address; | 36 | m_address = addr; |
| 27 | m_size = size; | ||
| 28 | m_is_initialized = true; | 37 | m_is_initialized = true; |
| 38 | m_is_mapped = false; | ||
| 29 | 39 | ||
| 40 | // We succeeded. | ||
| 41 | pg_guard.Cancel(); | ||
| 30 | R_SUCCEED(); | 42 | R_SUCCEED(); |
| 31 | } | 43 | } |
| 32 | 44 | ||
| 33 | void KTransferMemory::Finalize() {} | 45 | void KTransferMemory::Finalize() { |
| 46 | // Unlock. | ||
| 47 | if (!m_is_mapped) { | ||
| 48 | const size_t size = m_page_group->GetNumPages() * PageSize; | ||
| 49 | ASSERT(R_SUCCEEDED( | ||
| 50 | m_owner->GetPageTable().UnlockForTransferMemory(m_address, size, *m_page_group))); | ||
| 51 | } | ||
| 52 | |||
| 53 | // Close the page group. | ||
| 54 | m_page_group->Close(); | ||
| 55 | m_page_group->Finalize(); | ||
| 56 | } | ||
| 34 | 57 | ||
| 35 | void KTransferMemory::PostDestroy(uintptr_t arg) { | 58 | void KTransferMemory::PostDestroy(uintptr_t arg) { |
| 36 | KProcess* owner = reinterpret_cast<KProcess*>(arg); | 59 | KProcess* owner = reinterpret_cast<KProcess*>(arg); |
| @@ -38,4 +61,54 @@ void KTransferMemory::PostDestroy(uintptr_t arg) { | |||
| 38 | owner->Close(); | 61 | owner->Close(); |
| 39 | } | 62 | } |
| 40 | 63 | ||
| 64 | Result KTransferMemory::Map(KProcessAddress address, size_t size, Svc::MemoryPermission map_perm) { | ||
| 65 | // Validate the size. | ||
| 66 | R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize); | ||
| 67 | |||
| 68 | // Validate the permission. | ||
| 69 | R_UNLESS(m_owner_perm == map_perm, ResultInvalidState); | ||
| 70 | |||
| 71 | // Lock ourselves. | ||
| 72 | KScopedLightLock lk(m_lock); | ||
| 73 | |||
| 74 | // Ensure we're not already mapped. | ||
| 75 | R_UNLESS(!m_is_mapped, ResultInvalidState); | ||
| 76 | |||
| 77 | // Map the memory. | ||
| 78 | const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None) | ||
| 79 | ? KMemoryState::Transfered | ||
| 80 | : KMemoryState::SharedTransfered; | ||
| 81 | R_TRY(GetCurrentProcess(m_kernel).GetPageTable().MapPageGroup( | ||
| 82 | address, *m_page_group, state, KMemoryPermission::UserReadWrite)); | ||
| 83 | |||
| 84 | // Mark ourselves as mapped. | ||
| 85 | m_is_mapped = true; | ||
| 86 | |||
| 87 | R_SUCCEED(); | ||
| 88 | } | ||
| 89 | |||
| 90 | Result KTransferMemory::Unmap(KProcessAddress address, size_t size) { | ||
| 91 | // Validate the size. | ||
| 92 | R_UNLESS(m_page_group->GetNumPages() == Common::DivideUp(size, PageSize), ResultInvalidSize); | ||
| 93 | |||
| 94 | // Lock ourselves. | ||
| 95 | KScopedLightLock lk(m_lock); | ||
| 96 | |||
| 97 | // Unmap the memory. | ||
| 98 | const KMemoryState state = (m_owner_perm == Svc::MemoryPermission::None) | ||
| 99 | ? KMemoryState::Transfered | ||
| 100 | : KMemoryState::SharedTransfered; | ||
| 101 | R_TRY(GetCurrentProcess(m_kernel).GetPageTable().UnmapPageGroup(address, *m_page_group, state)); | ||
| 102 | |||
| 103 | // Mark ourselves as unmapped. | ||
| 104 | ASSERT(m_is_mapped); | ||
| 105 | m_is_mapped = false; | ||
| 106 | |||
| 107 | R_SUCCEED(); | ||
| 108 | } | ||
| 109 | |||
| 110 | size_t KTransferMemory::GetSize() const { | ||
| 111 | return m_is_initialized ? m_page_group->GetNumPages() * PageSize : 0; | ||
| 112 | } | ||
| 113 | |||
| 41 | } // namespace Kernel | 114 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/k_transfer_memory.h b/src/core/hle/kernel/k_transfer_memory.h index 54f97ccb4..8a0b08761 100644 --- a/src/core/hle/kernel/k_transfer_memory.h +++ b/src/core/hle/kernel/k_transfer_memory.h | |||
| @@ -3,6 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <optional> | ||
| 7 | |||
| 8 | #include "core/hle/kernel/k_page_group.h" | ||
| 6 | #include "core/hle/kernel/slab_helpers.h" | 9 | #include "core/hle/kernel/slab_helpers.h" |
| 7 | #include "core/hle/kernel/svc_types.h" | 10 | #include "core/hle/kernel/svc_types.h" |
| 8 | #include "core/hle/result.h" | 11 | #include "core/hle/result.h" |
| @@ -48,16 +51,19 @@ public: | |||
| 48 | return m_address; | 51 | return m_address; |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | size_t GetSize() const { | 54 | size_t GetSize() const; |
| 52 | return m_is_initialized ? m_size : 0; | 55 | |
| 53 | } | 56 | Result Map(KProcessAddress address, size_t size, Svc::MemoryPermission map_perm); |
| 57 | Result Unmap(KProcessAddress address, size_t size); | ||
| 54 | 58 | ||
| 55 | private: | 59 | private: |
| 60 | std::optional<KPageGroup> m_page_group{}; | ||
| 56 | KProcess* m_owner{}; | 61 | KProcess* m_owner{}; |
| 57 | KProcessAddress m_address{}; | 62 | KProcessAddress m_address{}; |
| 63 | KLightLock m_lock; | ||
| 58 | Svc::MemoryPermission m_owner_perm{}; | 64 | Svc::MemoryPermission m_owner_perm{}; |
| 59 | size_t m_size{}; | ||
| 60 | bool m_is_initialized{}; | 65 | bool m_is_initialized{}; |
| 66 | bool m_is_mapped{}; | ||
| 61 | }; | 67 | }; |
| 62 | 68 | ||
| 63 | } // namespace Kernel | 69 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/svc/svc_transfer_memory.cpp b/src/core/hle/kernel/svc/svc_transfer_memory.cpp index 7d94e7f09..1f97121b3 100644 --- a/src/core/hle/kernel/svc/svc_transfer_memory.cpp +++ b/src/core/hle/kernel/svc/svc_transfer_memory.cpp | |||
| @@ -71,15 +71,59 @@ Result CreateTransferMemory(Core::System& system, Handle* out, u64 address, u64 | |||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size, | 73 | Result MapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, uint64_t size, |
| 74 | MemoryPermission owner_perm) { | 74 | MemoryPermission map_perm) { |
| 75 | UNIMPLEMENTED(); | 75 | // Validate the address/size. |
| 76 | R_THROW(ResultNotImplemented); | 76 | R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress); |
| 77 | R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize); | ||
| 78 | R_UNLESS(size > 0, ResultInvalidSize); | ||
| 79 | R_UNLESS((address < address + size), ResultInvalidCurrentMemory); | ||
| 80 | |||
| 81 | // Validate the permission. | ||
| 82 | R_UNLESS(IsValidTransferMemoryPermission(map_perm), ResultInvalidState); | ||
| 83 | |||
| 84 | // Get the transfer memory. | ||
| 85 | KScopedAutoObject trmem = GetCurrentProcess(system.Kernel()) | ||
| 86 | .GetHandleTable() | ||
| 87 | .GetObject<KTransferMemory>(trmem_handle); | ||
| 88 | R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle); | ||
| 89 | |||
| 90 | // Verify that the mapping is in range. | ||
| 91 | R_UNLESS(GetCurrentProcess(system.Kernel()) | ||
| 92 | .GetPageTable() | ||
| 93 | .CanContain(address, size, KMemoryState::Transfered), | ||
| 94 | ResultInvalidMemoryRegion); | ||
| 95 | |||
| 96 | // Map the transfer memory. | ||
| 97 | R_TRY(trmem->Map(address, size, map_perm)); | ||
| 98 | |||
| 99 | // We succeeded. | ||
| 100 | R_SUCCEED(); | ||
| 77 | } | 101 | } |
| 78 | 102 | ||
| 79 | Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, | 103 | Result UnmapTransferMemory(Core::System& system, Handle trmem_handle, uint64_t address, |
| 80 | uint64_t size) { | 104 | uint64_t size) { |
| 81 | UNIMPLEMENTED(); | 105 | // Validate the address/size. |
| 82 | R_THROW(ResultNotImplemented); | 106 | R_UNLESS(Common::IsAligned(address, PageSize), ResultInvalidAddress); |
| 107 | R_UNLESS(Common::IsAligned(size, PageSize), ResultInvalidSize); | ||
| 108 | R_UNLESS(size > 0, ResultInvalidSize); | ||
| 109 | R_UNLESS((address < address + size), ResultInvalidCurrentMemory); | ||
| 110 | |||
| 111 | // Get the transfer memory. | ||
| 112 | KScopedAutoObject trmem = GetCurrentProcess(system.Kernel()) | ||
| 113 | .GetHandleTable() | ||
| 114 | .GetObject<KTransferMemory>(trmem_handle); | ||
| 115 | R_UNLESS(trmem.IsNotNull(), ResultInvalidHandle); | ||
| 116 | |||
| 117 | // Verify that the mapping is in range. | ||
| 118 | R_UNLESS(GetCurrentProcess(system.Kernel()) | ||
| 119 | .GetPageTable() | ||
| 120 | .CanContain(address, size, KMemoryState::Transfered), | ||
| 121 | ResultInvalidMemoryRegion); | ||
| 122 | |||
| 123 | // Unmap the transfer memory. | ||
| 124 | R_TRY(trmem->Unmap(address, size)); | ||
| 125 | |||
| 126 | R_SUCCEED(); | ||
| 83 | } | 127 | } |
| 84 | 128 | ||
| 85 | Result MapTransferMemory64(Core::System& system, Handle trmem_handle, uint64_t address, | 129 | Result MapTransferMemory64(Core::System& system, Handle trmem_handle, uint64_t address, |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 819dea6a7..ac376b55a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -31,7 +31,7 @@ | |||
| 31 | #include "core/hle/service/apm/apm_controller.h" | 31 | #include "core/hle/service/apm/apm_controller.h" |
| 32 | #include "core/hle/service/apm/apm_interface.h" | 32 | #include "core/hle/service/apm/apm_interface.h" |
| 33 | #include "core/hle/service/bcat/backend/backend.h" | 33 | #include "core/hle/service/bcat/backend/backend.h" |
| 34 | #include "core/hle/service/caps/caps.h" | 34 | #include "core/hle/service/caps/caps_types.h" |
| 35 | #include "core/hle/service/filesystem/filesystem.h" | 35 | #include "core/hle/service/filesystem/filesystem.h" |
| 36 | #include "core/hle/service/ipc_helpers.h" | 36 | #include "core/hle/service/ipc_helpers.h" |
| 37 | #include "core/hle/service/ns/ns.h" | 37 | #include "core/hle/service/ns/ns.h" |
| @@ -764,6 +764,66 @@ void AppletMessageQueue::OperationModeChanged() { | |||
| 764 | on_operation_mode_changed->Signal(); | 764 | on_operation_mode_changed->Signal(); |
| 765 | } | 765 | } |
| 766 | 766 | ||
| 767 | ILockAccessor::ILockAccessor(Core::System& system_) | ||
| 768 | : ServiceFramework{system_, "ILockAccessor"}, service_context{system_, "ILockAccessor"} { | ||
| 769 | // clang-format off | ||
| 770 | static const FunctionInfo functions[] = { | ||
| 771 | {1, &ILockAccessor::TryLock, "TryLock"}, | ||
| 772 | {2, &ILockAccessor::Unlock, "Unlock"}, | ||
| 773 | {3, &ILockAccessor::GetEvent, "GetEvent"}, | ||
| 774 | {4,&ILockAccessor::IsLocked, "IsLocked"}, | ||
| 775 | }; | ||
| 776 | // clang-format on | ||
| 777 | |||
| 778 | RegisterHandlers(functions); | ||
| 779 | |||
| 780 | lock_event = service_context.CreateEvent("ILockAccessor::LockEvent"); | ||
| 781 | } | ||
| 782 | |||
| 783 | ILockAccessor::~ILockAccessor() = default; | ||
| 784 | |||
| 785 | void ILockAccessor::TryLock(HLERequestContext& ctx) { | ||
| 786 | IPC::RequestParser rp{ctx}; | ||
| 787 | const auto return_handle = rp.Pop<bool>(); | ||
| 788 | |||
| 789 | LOG_WARNING(Service_AM, "(STUBBED) called, return_handle={}", return_handle); | ||
| 790 | |||
| 791 | // TODO: When return_handle is true this function should return the lock handle | ||
| 792 | |||
| 793 | is_locked = true; | ||
| 794 | |||
| 795 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 796 | rb.Push(ResultSuccess); | ||
| 797 | rb.Push<u8>(is_locked); | ||
| 798 | } | ||
| 799 | |||
| 800 | void ILockAccessor::Unlock(HLERequestContext& ctx) { | ||
| 801 | LOG_INFO(Service_AM, "called"); | ||
| 802 | |||
| 803 | is_locked = false; | ||
| 804 | |||
| 805 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 806 | rb.Push(ResultSuccess); | ||
| 807 | } | ||
| 808 | |||
| 809 | void ILockAccessor::GetEvent(HLERequestContext& ctx) { | ||
| 810 | LOG_INFO(Service_AM, "called"); | ||
| 811 | |||
| 812 | lock_event->Signal(); | ||
| 813 | |||
| 814 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 815 | rb.Push(ResultSuccess); | ||
| 816 | rb.PushCopyObjects(lock_event->GetReadableEvent()); | ||
| 817 | } | ||
| 818 | |||
| 819 | void ILockAccessor::IsLocked(HLERequestContext& ctx) { | ||
| 820 | LOG_INFO(Service_AM, "called"); | ||
| 821 | |||
| 822 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 823 | rb.Push(ResultSuccess); | ||
| 824 | rb.Push<u8>(is_locked); | ||
| 825 | } | ||
| 826 | |||
| 767 | ICommonStateGetter::ICommonStateGetter(Core::System& system_, | 827 | ICommonStateGetter::ICommonStateGetter(Core::System& system_, |
| 768 | std::shared_ptr<AppletMessageQueue> msg_queue_) | 828 | std::shared_ptr<AppletMessageQueue> msg_queue_) |
| 769 | : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)}, | 829 | : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)}, |
| @@ -787,7 +847,7 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, | |||
| 787 | {14, nullptr, "GetWakeupCount"}, | 847 | {14, nullptr, "GetWakeupCount"}, |
| 788 | {20, nullptr, "PushToGeneralChannel"}, | 848 | {20, nullptr, "PushToGeneralChannel"}, |
| 789 | {30, nullptr, "GetHomeButtonReaderLockAccessor"}, | 849 | {30, nullptr, "GetHomeButtonReaderLockAccessor"}, |
| 790 | {31, nullptr, "GetReaderLockAccessorEx"}, | 850 | {31, &ICommonStateGetter::GetReaderLockAccessorEx, "GetReaderLockAccessorEx"}, |
| 791 | {32, nullptr, "GetWriterLockAccessorEx"}, | 851 | {32, nullptr, "GetWriterLockAccessorEx"}, |
| 792 | {40, nullptr, "GetCradleFwVersion"}, | 852 | {40, nullptr, "GetCradleFwVersion"}, |
| 793 | {50, &ICommonStateGetter::IsVrModeEnabled, "IsVrModeEnabled"}, | 853 | {50, &ICommonStateGetter::IsVrModeEnabled, "IsVrModeEnabled"}, |
| @@ -805,7 +865,7 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_, | |||
| 805 | {65, nullptr, "GetApplicationIdByContentActionName"}, | 865 | {65, nullptr, "GetApplicationIdByContentActionName"}, |
| 806 | {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"}, | 866 | {66, &ICommonStateGetter::SetCpuBoostMode, "SetCpuBoostMode"}, |
| 807 | {67, nullptr, "CancelCpuBoostMode"}, | 867 | {67, nullptr, "CancelCpuBoostMode"}, |
| 808 | {68, nullptr, "GetBuiltInDisplayType"}, | 868 | {68, &ICommonStateGetter::GetBuiltInDisplayType, "GetBuiltInDisplayType"}, |
| 809 | {80, &ICommonStateGetter::PerformSystemButtonPressingIfInFocus, "PerformSystemButtonPressingIfInFocus"}, | 869 | {80, &ICommonStateGetter::PerformSystemButtonPressingIfInFocus, "PerformSystemButtonPressingIfInFocus"}, |
| 810 | {90, nullptr, "SetPerformanceConfigurationChangedNotification"}, | 870 | {90, nullptr, "SetPerformanceConfigurationChangedNotification"}, |
| 811 | {91, nullptr, "GetCurrentPerformanceConfiguration"}, | 871 | {91, nullptr, "GetCurrentPerformanceConfiguration"}, |
| @@ -886,6 +946,18 @@ void ICommonStateGetter::RequestToAcquireSleepLock(HLERequestContext& ctx) { | |||
| 886 | rb.Push(ResultSuccess); | 946 | rb.Push(ResultSuccess); |
| 887 | } | 947 | } |
| 888 | 948 | ||
| 949 | void ICommonStateGetter::GetReaderLockAccessorEx(HLERequestContext& ctx) { | ||
| 950 | IPC::RequestParser rp{ctx}; | ||
| 951 | const auto unknown = rp.Pop<u32>(); | ||
| 952 | |||
| 953 | LOG_INFO(Service_AM, "called, unknown={}", unknown); | ||
| 954 | |||
| 955 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 956 | |||
| 957 | rb.Push(ResultSuccess); | ||
| 958 | rb.PushIpcInterface<ILockAccessor>(system); | ||
| 959 | } | ||
| 960 | |||
| 889 | void ICommonStateGetter::GetAcquiredSleepLockEvent(HLERequestContext& ctx) { | 961 | void ICommonStateGetter::GetAcquiredSleepLockEvent(HLERequestContext& ctx) { |
| 890 | LOG_WARNING(Service_AM, "called"); | 962 | LOG_WARNING(Service_AM, "called"); |
| 891 | 963 | ||
| @@ -970,6 +1042,14 @@ void ICommonStateGetter::SetCpuBoostMode(HLERequestContext& ctx) { | |||
| 970 | apm_sys->SetCpuBoostMode(ctx); | 1042 | apm_sys->SetCpuBoostMode(ctx); |
| 971 | } | 1043 | } |
| 972 | 1044 | ||
| 1045 | void ICommonStateGetter::GetBuiltInDisplayType(HLERequestContext& ctx) { | ||
| 1046 | LOG_WARNING(Service_AM, "(STUBBED) called"); | ||
| 1047 | |||
| 1048 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 1049 | rb.Push(ResultSuccess); | ||
| 1050 | rb.Push(0); | ||
| 1051 | } | ||
| 1052 | |||
| 973 | void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx) { | 1053 | void ICommonStateGetter::PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx) { |
| 974 | IPC::RequestParser rp{ctx}; | 1054 | IPC::RequestParser rp{ctx}; |
| 975 | const auto system_button{rp.PopEnum<SystemButtonType>()}; | 1055 | const auto system_button{rp.PopEnum<SystemButtonType>()}; |
| @@ -1493,6 +1573,9 @@ ILibraryAppletSelfAccessor::ILibraryAppletSelfAccessor(Core::System& system_) | |||
| 1493 | case Applets::AppletId::MiiEdit: | 1573 | case Applets::AppletId::MiiEdit: |
| 1494 | PushInShowMiiEditData(); | 1574 | PushInShowMiiEditData(); |
| 1495 | break; | 1575 | break; |
| 1576 | case Applets::AppletId::PhotoViewer: | ||
| 1577 | PushInShowAlbum(); | ||
| 1578 | break; | ||
| 1496 | default: | 1579 | default: |
| 1497 | break; | 1580 | break; |
| 1498 | } | 1581 | } |
| @@ -1569,6 +1652,23 @@ void ILibraryAppletSelfAccessor::GetCallerAppletIdentityInfo(HLERequestContext& | |||
| 1569 | rb.PushRaw(applet_info); | 1652 | rb.PushRaw(applet_info); |
| 1570 | } | 1653 | } |
| 1571 | 1654 | ||
| 1655 | void ILibraryAppletSelfAccessor::PushInShowAlbum() { | ||
| 1656 | const Applets::CommonArguments arguments{ | ||
| 1657 | .arguments_version = Applets::CommonArgumentVersion::Version3, | ||
| 1658 | .size = Applets::CommonArgumentSize::Version3, | ||
| 1659 | .library_version = 1, | ||
| 1660 | .theme_color = Applets::ThemeColor::BasicBlack, | ||
| 1661 | .play_startup_sound = true, | ||
| 1662 | .system_tick = system.CoreTiming().GetClockTicks(), | ||
| 1663 | }; | ||
| 1664 | |||
| 1665 | std::vector<u8> argument_data(sizeof(arguments)); | ||
| 1666 | std::vector<u8> settings_data{2}; | ||
| 1667 | std::memcpy(argument_data.data(), &arguments, sizeof(arguments)); | ||
| 1668 | queue_data.emplace_back(std::move(argument_data)); | ||
| 1669 | queue_data.emplace_back(std::move(settings_data)); | ||
| 1670 | } | ||
| 1671 | |||
| 1572 | void ILibraryAppletSelfAccessor::PushInShowCabinetData() { | 1672 | void ILibraryAppletSelfAccessor::PushInShowCabinetData() { |
| 1573 | const Applets::CommonArguments arguments{ | 1673 | const Applets::CommonArguments arguments{ |
| 1574 | .arguments_version = Applets::CommonArgumentVersion::Version3, | 1674 | .arguments_version = Applets::CommonArgumentVersion::Version3, |
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 349482dcc..4a045cfd4 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h | |||
| @@ -195,6 +195,23 @@ private: | |||
| 195 | ScreenshotPermission screenshot_permission = ScreenshotPermission::Inherit; | 195 | ScreenshotPermission screenshot_permission = ScreenshotPermission::Inherit; |
| 196 | }; | 196 | }; |
| 197 | 197 | ||
| 198 | class ILockAccessor final : public ServiceFramework<ILockAccessor> { | ||
| 199 | public: | ||
| 200 | explicit ILockAccessor(Core::System& system_); | ||
| 201 | ~ILockAccessor() override; | ||
| 202 | |||
| 203 | private: | ||
| 204 | void TryLock(HLERequestContext& ctx); | ||
| 205 | void Unlock(HLERequestContext& ctx); | ||
| 206 | void GetEvent(HLERequestContext& ctx); | ||
| 207 | void IsLocked(HLERequestContext& ctx); | ||
| 208 | |||
| 209 | bool is_locked{}; | ||
| 210 | |||
| 211 | Kernel::KEvent* lock_event; | ||
| 212 | KernelHelpers::ServiceContext service_context; | ||
| 213 | }; | ||
| 214 | |||
| 198 | class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> { | 215 | class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> { |
| 199 | public: | 216 | public: |
| 200 | explicit ICommonStateGetter(Core::System& system_, | 217 | explicit ICommonStateGetter(Core::System& system_, |
| @@ -237,6 +254,7 @@ private: | |||
| 237 | void GetCurrentFocusState(HLERequestContext& ctx); | 254 | void GetCurrentFocusState(HLERequestContext& ctx); |
| 238 | void RequestToAcquireSleepLock(HLERequestContext& ctx); | 255 | void RequestToAcquireSleepLock(HLERequestContext& ctx); |
| 239 | void GetAcquiredSleepLockEvent(HLERequestContext& ctx); | 256 | void GetAcquiredSleepLockEvent(HLERequestContext& ctx); |
| 257 | void GetReaderLockAccessorEx(HLERequestContext& ctx); | ||
| 240 | void GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx); | 258 | void GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx); |
| 241 | void GetOperationMode(HLERequestContext& ctx); | 259 | void GetOperationMode(HLERequestContext& ctx); |
| 242 | void GetPerformanceMode(HLERequestContext& ctx); | 260 | void GetPerformanceMode(HLERequestContext& ctx); |
| @@ -248,6 +266,7 @@ private: | |||
| 248 | void EndVrModeEx(HLERequestContext& ctx); | 266 | void EndVrModeEx(HLERequestContext& ctx); |
| 249 | void GetDefaultDisplayResolution(HLERequestContext& ctx); | 267 | void GetDefaultDisplayResolution(HLERequestContext& ctx); |
| 250 | void SetCpuBoostMode(HLERequestContext& ctx); | 268 | void SetCpuBoostMode(HLERequestContext& ctx); |
| 269 | void GetBuiltInDisplayType(HLERequestContext& ctx); | ||
| 251 | void PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx); | 270 | void PerformSystemButtonPressingIfInFocus(HLERequestContext& ctx); |
| 252 | void GetSettingsPlatformRegion(HLERequestContext& ctx); | 271 | void GetSettingsPlatformRegion(HLERequestContext& ctx); |
| 253 | void SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(HLERequestContext& ctx); | 272 | void SetRequestExitToLibraryAppletAtExecuteNextProgramEnabled(HLERequestContext& ctx); |
| @@ -327,6 +346,7 @@ private: | |||
| 327 | void ExitProcessAndReturn(HLERequestContext& ctx); | 346 | void ExitProcessAndReturn(HLERequestContext& ctx); |
| 328 | void GetCallerAppletIdentityInfo(HLERequestContext& ctx); | 347 | void GetCallerAppletIdentityInfo(HLERequestContext& ctx); |
| 329 | 348 | ||
| 349 | void PushInShowAlbum(); | ||
| 330 | void PushInShowCabinetData(); | 350 | void PushInShowCabinetData(); |
| 331 | void PushInShowMiiEditData(); | 351 | void PushInShowMiiEditData(); |
| 332 | 352 | ||
diff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cpp index eb12312cc..e30e6478a 100644 --- a/src/core/hle/service/am/applet_ae.cpp +++ b/src/core/hle/service/am/applet_ae.cpp | |||
| @@ -28,8 +28,8 @@ public: | |||
| 28 | {11, &ILibraryAppletProxy::GetLibraryAppletCreator, "GetLibraryAppletCreator"}, | 28 | {11, &ILibraryAppletProxy::GetLibraryAppletCreator, "GetLibraryAppletCreator"}, |
| 29 | {20, &ILibraryAppletProxy::OpenLibraryAppletSelfAccessor, "OpenLibraryAppletSelfAccessor"}, | 29 | {20, &ILibraryAppletProxy::OpenLibraryAppletSelfAccessor, "OpenLibraryAppletSelfAccessor"}, |
| 30 | {21, &ILibraryAppletProxy::GetAppletCommonFunctions, "GetAppletCommonFunctions"}, | 30 | {21, &ILibraryAppletProxy::GetAppletCommonFunctions, "GetAppletCommonFunctions"}, |
| 31 | {22, nullptr, "GetHomeMenuFunctions"}, | 31 | {22, &ILibraryAppletProxy::GetHomeMenuFunctions, "GetHomeMenuFunctions"}, |
| 32 | {23, nullptr, "GetGlobalStateController"}, | 32 | {23, &ILibraryAppletProxy::GetGlobalStateController, "GetGlobalStateController"}, |
| 33 | {1000, &ILibraryAppletProxy::GetDebugFunctions, "GetDebugFunctions"}, | 33 | {1000, &ILibraryAppletProxy::GetDebugFunctions, "GetDebugFunctions"}, |
| 34 | }; | 34 | }; |
| 35 | // clang-format on | 35 | // clang-format on |
| @@ -110,6 +110,22 @@ private: | |||
| 110 | rb.PushIpcInterface<IAppletCommonFunctions>(system); | 110 | rb.PushIpcInterface<IAppletCommonFunctions>(system); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | void GetHomeMenuFunctions(HLERequestContext& ctx) { | ||
| 114 | LOG_DEBUG(Service_AM, "called"); | ||
| 115 | |||
| 116 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 117 | rb.Push(ResultSuccess); | ||
| 118 | rb.PushIpcInterface<IHomeMenuFunctions>(system); | ||
| 119 | } | ||
| 120 | |||
| 121 | void GetGlobalStateController(HLERequestContext& ctx) { | ||
| 122 | LOG_DEBUG(Service_AM, "called"); | ||
| 123 | |||
| 124 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 125 | rb.Push(ResultSuccess); | ||
| 126 | rb.PushIpcInterface<IGlobalStateController>(system); | ||
| 127 | } | ||
| 128 | |||
| 113 | void GetDebugFunctions(HLERequestContext& ctx) { | 129 | void GetDebugFunctions(HLERequestContext& ctx) { |
| 114 | LOG_DEBUG(Service_AM, "called"); | 130 | LOG_DEBUG(Service_AM, "called"); |
| 115 | 131 | ||
diff --git a/src/core/hle/service/am/applets/applet_error.cpp b/src/core/hle/service/am/applets/applet_error.cpp index b46ea840c..5d17c353f 100644 --- a/src/core/hle/service/am/applets/applet_error.cpp +++ b/src/core/hle/service/am/applets/applet_error.cpp | |||
| @@ -138,6 +138,10 @@ void Error::Initialize() { | |||
| 138 | CopyArgumentData(data, args->application_error); | 138 | CopyArgumentData(data, args->application_error); |
| 139 | error_code = Result(args->application_error.error_code); | 139 | error_code = Result(args->application_error.error_code); |
| 140 | break; | 140 | break; |
| 141 | case ErrorAppletMode::ShowErrorPctl: | ||
| 142 | CopyArgumentData(data, args->error_record); | ||
| 143 | error_code = Decode64BitError(args->error_record.error_code_64); | ||
| 144 | break; | ||
| 141 | case ErrorAppletMode::ShowErrorRecord: | 145 | case ErrorAppletMode::ShowErrorRecord: |
| 142 | CopyArgumentData(data, args->error_record); | 146 | CopyArgumentData(data, args->error_record); |
| 143 | error_code = Decode64BitError(args->error_record.error_code_64); | 147 | error_code = Decode64BitError(args->error_record.error_code_64); |
| @@ -191,6 +195,7 @@ void Error::Execute() { | |||
| 191 | frontend.ShowCustomErrorText(error_code, main_text_string, detail_text_string, callback); | 195 | frontend.ShowCustomErrorText(error_code, main_text_string, detail_text_string, callback); |
| 192 | break; | 196 | break; |
| 193 | } | 197 | } |
| 198 | case ErrorAppletMode::ShowErrorPctl: | ||
| 194 | case ErrorAppletMode::ShowErrorRecord: | 199 | case ErrorAppletMode::ShowErrorRecord: |
| 195 | reporter.SaveErrorReport(title_id, error_code, | 200 | reporter.SaveErrorReport(title_id, error_code, |
| 196 | fmt::format("{:016X}", args->error_record.posix_time)); | 201 | fmt::format("{:016X}", args->error_record.posix_time)); |
diff --git a/src/core/hle/service/caps/caps.cpp b/src/core/hle/service/caps/caps.cpp index 610fe9940..286f9fd10 100644 --- a/src/core/hle/service/caps/caps.cpp +++ b/src/core/hle/service/caps/caps.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "core/hle/service/caps/caps.h" | 4 | #include "core/hle/service/caps/caps.h" |
| 5 | #include "core/hle/service/caps/caps_a.h" | 5 | #include "core/hle/service/caps/caps_a.h" |
| 6 | #include "core/hle/service/caps/caps_c.h" | 6 | #include "core/hle/service/caps/caps_c.h" |
| 7 | #include "core/hle/service/caps/caps_manager.h" | ||
| 7 | #include "core/hle/service/caps/caps_sc.h" | 8 | #include "core/hle/service/caps/caps_sc.h" |
| 8 | #include "core/hle/service/caps/caps_ss.h" | 9 | #include "core/hle/service/caps/caps_ss.h" |
| 9 | #include "core/hle/service/caps/caps_su.h" | 10 | #include "core/hle/service/caps/caps_su.h" |
| @@ -15,13 +16,21 @@ namespace Service::Capture { | |||
| 15 | 16 | ||
| 16 | void LoopProcess(Core::System& system) { | 17 | void LoopProcess(Core::System& system) { |
| 17 | auto server_manager = std::make_unique<ServerManager>(system); | 18 | auto server_manager = std::make_unique<ServerManager>(system); |
| 19 | auto album_manager = std::make_shared<AlbumManager>(); | ||
| 20 | |||
| 21 | server_manager->RegisterNamedService( | ||
| 22 | "caps:a", std::make_shared<IAlbumAccessorService>(system, album_manager)); | ||
| 23 | server_manager->RegisterNamedService( | ||
| 24 | "caps:c", std::make_shared<IAlbumControlService>(system, album_manager)); | ||
| 25 | server_manager->RegisterNamedService( | ||
| 26 | "caps:u", std::make_shared<IAlbumApplicationService>(system, album_manager)); | ||
| 27 | |||
| 28 | server_manager->RegisterNamedService("caps:ss", std::make_shared<IScreenShotService>(system)); | ||
| 29 | server_manager->RegisterNamedService("caps:sc", | ||
| 30 | std::make_shared<IScreenShotControlService>(system)); | ||
| 31 | server_manager->RegisterNamedService("caps:su", | ||
| 32 | std::make_shared<IScreenShotApplicationService>(system)); | ||
| 18 | 33 | ||
| 19 | server_manager->RegisterNamedService("caps:a", std::make_shared<CAPS_A>(system)); | ||
| 20 | server_manager->RegisterNamedService("caps:c", std::make_shared<CAPS_C>(system)); | ||
| 21 | server_manager->RegisterNamedService("caps:u", std::make_shared<CAPS_U>(system)); | ||
| 22 | server_manager->RegisterNamedService("caps:sc", std::make_shared<CAPS_SC>(system)); | ||
| 23 | server_manager->RegisterNamedService("caps:ss", std::make_shared<CAPS_SS>(system)); | ||
| 24 | server_manager->RegisterNamedService("caps:su", std::make_shared<CAPS_SU>(system)); | ||
| 25 | ServerManager::RunServer(std::move(server_manager)); | 34 | ServerManager::RunServer(std::move(server_manager)); |
| 26 | } | 35 | } |
| 27 | 36 | ||
diff --git a/src/core/hle/service/caps/caps.h b/src/core/hle/service/caps/caps.h index 15f0ecfaa..58e9725b8 100644 --- a/src/core/hle/service/caps/caps.h +++ b/src/core/hle/service/caps/caps.h | |||
| @@ -3,93 +3,12 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | namespace Core { | 6 | namespace Core { |
| 10 | class System; | 7 | class System; |
| 11 | } | 8 | } |
| 12 | 9 | ||
| 13 | namespace Service::SM { | ||
| 14 | class ServiceManager; | ||
| 15 | } | ||
| 16 | |||
| 17 | namespace Service::Capture { | 10 | namespace Service::Capture { |
| 18 | 11 | ||
| 19 | enum class AlbumImageOrientation { | ||
| 20 | Orientation0 = 0, | ||
| 21 | Orientation1 = 1, | ||
| 22 | Orientation2 = 2, | ||
| 23 | Orientation3 = 3, | ||
| 24 | }; | ||
| 25 | |||
| 26 | enum class AlbumReportOption : s32 { | ||
| 27 | Disable = 0, | ||
| 28 | Enable = 1, | ||
| 29 | }; | ||
| 30 | |||
| 31 | enum class ContentType : u8 { | ||
| 32 | Screenshot = 0, | ||
| 33 | Movie = 1, | ||
| 34 | ExtraMovie = 3, | ||
| 35 | }; | ||
| 36 | |||
| 37 | enum class AlbumStorage : u8 { | ||
| 38 | NAND = 0, | ||
| 39 | SD = 1, | ||
| 40 | }; | ||
| 41 | |||
| 42 | struct AlbumFileDateTime { | ||
| 43 | s16 year{}; | ||
| 44 | s8 month{}; | ||
| 45 | s8 day{}; | ||
| 46 | s8 hour{}; | ||
| 47 | s8 minute{}; | ||
| 48 | s8 second{}; | ||
| 49 | s8 uid{}; | ||
| 50 | }; | ||
| 51 | static_assert(sizeof(AlbumFileDateTime) == 0x8, "AlbumFileDateTime has incorrect size."); | ||
| 52 | |||
| 53 | struct AlbumEntry { | ||
| 54 | u64 size{}; | ||
| 55 | u64 application_id{}; | ||
| 56 | AlbumFileDateTime datetime{}; | ||
| 57 | AlbumStorage storage{}; | ||
| 58 | ContentType content{}; | ||
| 59 | INSERT_PADDING_BYTES(6); | ||
| 60 | }; | ||
| 61 | static_assert(sizeof(AlbumEntry) == 0x20, "AlbumEntry has incorrect size."); | ||
| 62 | |||
| 63 | struct AlbumFileEntry { | ||
| 64 | u64 size{}; // Size of the entry | ||
| 65 | u64 hash{}; // AES256 with hardcoded key over AlbumEntry | ||
| 66 | AlbumFileDateTime datetime{}; | ||
| 67 | AlbumStorage storage{}; | ||
| 68 | ContentType content{}; | ||
| 69 | INSERT_PADDING_BYTES(5); | ||
| 70 | u8 unknown{1}; // Set to 1 on official SW | ||
| 71 | }; | ||
| 72 | static_assert(sizeof(AlbumFileEntry) == 0x20, "AlbumFileEntry has incorrect size."); | ||
| 73 | |||
| 74 | struct ApplicationAlbumEntry { | ||
| 75 | u64 size{}; // Size of the entry | ||
| 76 | u64 hash{}; // AES256 with hardcoded key over AlbumEntry | ||
| 77 | AlbumFileDateTime datetime{}; | ||
| 78 | AlbumStorage storage{}; | ||
| 79 | ContentType content{}; | ||
| 80 | INSERT_PADDING_BYTES(5); | ||
| 81 | u8 unknown{1}; // Set to 1 on official SW | ||
| 82 | }; | ||
| 83 | static_assert(sizeof(ApplicationAlbumEntry) == 0x20, "ApplicationAlbumEntry has incorrect size."); | ||
| 84 | |||
| 85 | struct ApplicationAlbumFileEntry { | ||
| 86 | ApplicationAlbumEntry entry{}; | ||
| 87 | AlbumFileDateTime datetime{}; | ||
| 88 | u64 unknown{}; | ||
| 89 | }; | ||
| 90 | static_assert(sizeof(ApplicationAlbumFileEntry) == 0x30, | ||
| 91 | "ApplicationAlbumFileEntry has incorrect size."); | ||
| 92 | |||
| 93 | void LoopProcess(Core::System& system); | 12 | void LoopProcess(Core::System& system); |
| 94 | 13 | ||
| 95 | } // namespace Service::Capture | 14 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_a.cpp b/src/core/hle/service/caps/caps_a.cpp index 44267b284..e22f72bf6 100644 --- a/src/core/hle/service/caps/caps_a.cpp +++ b/src/core/hle/service/caps/caps_a.cpp | |||
| @@ -1,40 +1,26 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/logging/log.h" | ||
| 4 | #include "core/hle/service/caps/caps_a.h" | 5 | #include "core/hle/service/caps/caps_a.h" |
| 6 | #include "core/hle/service/caps/caps_manager.h" | ||
| 7 | #include "core/hle/service/caps/caps_result.h" | ||
| 8 | #include "core/hle/service/caps/caps_types.h" | ||
| 9 | #include "core/hle/service/ipc_helpers.h" | ||
| 5 | 10 | ||
| 6 | namespace Service::Capture { | 11 | namespace Service::Capture { |
| 7 | 12 | ||
| 8 | class IAlbumAccessorSession final : public ServiceFramework<IAlbumAccessorSession> { | 13 | IAlbumAccessorService::IAlbumAccessorService(Core::System& system_, |
| 9 | public: | 14 | std::shared_ptr<AlbumManager> album_manager) |
| 10 | explicit IAlbumAccessorSession(Core::System& system_) | 15 | : ServiceFramework{system_, "caps:a"}, manager{album_manager} { |
| 11 | : ServiceFramework{system_, "IAlbumAccessorSession"} { | ||
| 12 | // clang-format off | ||
| 13 | static const FunctionInfo functions[] = { | ||
| 14 | {2001, nullptr, "OpenAlbumMovieReadStream"}, | ||
| 15 | {2002, nullptr, "CloseAlbumMovieReadStream"}, | ||
| 16 | {2003, nullptr, "GetAlbumMovieReadStreamMovieDataSize"}, | ||
| 17 | {2004, nullptr, "ReadMovieDataFromAlbumMovieReadStream"}, | ||
| 18 | {2005, nullptr, "GetAlbumMovieReadStreamBrokenReason"}, | ||
| 19 | {2006, nullptr, "GetAlbumMovieReadStreamImageDataSize"}, | ||
| 20 | {2007, nullptr, "ReadImageDataFromAlbumMovieReadStream"}, | ||
| 21 | {2008, nullptr, "ReadFileAttributeFromAlbumMovieReadStream"}, | ||
| 22 | }; | ||
| 23 | // clang-format on | ||
| 24 | |||
| 25 | RegisterHandlers(functions); | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | CAPS_A::CAPS_A(Core::System& system_) : ServiceFramework{system_, "caps:a"} { | ||
| 30 | // clang-format off | 16 | // clang-format off |
| 31 | static const FunctionInfo functions[] = { | 17 | static const FunctionInfo functions[] = { |
| 32 | {0, nullptr, "GetAlbumFileCount"}, | 18 | {0, nullptr, "GetAlbumFileCount"}, |
| 33 | {1, nullptr, "GetAlbumFileList"}, | 19 | {1, nullptr, "GetAlbumFileList"}, |
| 34 | {2, nullptr, "LoadAlbumFile"}, | 20 | {2, nullptr, "LoadAlbumFile"}, |
| 35 | {3, nullptr, "DeleteAlbumFile"}, | 21 | {3, &IAlbumAccessorService::DeleteAlbumFile, "DeleteAlbumFile"}, |
| 36 | {4, nullptr, "StorageCopyAlbumFile"}, | 22 | {4, nullptr, "StorageCopyAlbumFile"}, |
| 37 | {5, nullptr, "IsAlbumMounted"}, | 23 | {5, &IAlbumAccessorService::IsAlbumMounted, "IsAlbumMounted"}, |
| 38 | {6, nullptr, "GetAlbumUsage"}, | 24 | {6, nullptr, "GetAlbumUsage"}, |
| 39 | {7, nullptr, "GetAlbumFileSize"}, | 25 | {7, nullptr, "GetAlbumFileSize"}, |
| 40 | {8, nullptr, "LoadAlbumFileThumbnail"}, | 26 | {8, nullptr, "LoadAlbumFileThumbnail"}, |
| @@ -47,18 +33,18 @@ CAPS_A::CAPS_A(Core::System& system_) : ServiceFramework{system_, "caps:a"} { | |||
| 47 | {15, nullptr, "GetAlbumUsage3"}, | 33 | {15, nullptr, "GetAlbumUsage3"}, |
| 48 | {16, nullptr, "GetAlbumMountResult"}, | 34 | {16, nullptr, "GetAlbumMountResult"}, |
| 49 | {17, nullptr, "GetAlbumUsage16"}, | 35 | {17, nullptr, "GetAlbumUsage16"}, |
| 50 | {18, nullptr, "Unknown18"}, | 36 | {18, &IAlbumAccessorService::Unknown18, "Unknown18"}, |
| 51 | {19, nullptr, "Unknown19"}, | 37 | {19, nullptr, "Unknown19"}, |
| 52 | {100, nullptr, "GetAlbumFileCountEx0"}, | 38 | {100, nullptr, "GetAlbumFileCountEx0"}, |
| 53 | {101, nullptr, "GetAlbumFileListEx0"}, | 39 | {101, &IAlbumAccessorService::GetAlbumFileListEx0, "GetAlbumFileListEx0"}, |
| 54 | {202, nullptr, "SaveEditedScreenShot"}, | 40 | {202, nullptr, "SaveEditedScreenShot"}, |
| 55 | {301, nullptr, "GetLastThumbnail"}, | 41 | {301, nullptr, "GetLastThumbnail"}, |
| 56 | {302, nullptr, "GetLastOverlayMovieThumbnail"}, | 42 | {302, nullptr, "GetLastOverlayMovieThumbnail"}, |
| 57 | {401, nullptr, "GetAutoSavingStorage"}, | 43 | {401, &IAlbumAccessorService::GetAutoSavingStorage, "GetAutoSavingStorage"}, |
| 58 | {501, nullptr, "GetRequiredStorageSpaceSizeToCopyAll"}, | 44 | {501, nullptr, "GetRequiredStorageSpaceSizeToCopyAll"}, |
| 59 | {1001, nullptr, "LoadAlbumScreenShotThumbnailImageEx0"}, | 45 | {1001, nullptr, "LoadAlbumScreenShotThumbnailImageEx0"}, |
| 60 | {1002, nullptr, "LoadAlbumScreenShotImageEx1"}, | 46 | {1002, &IAlbumAccessorService::LoadAlbumScreenShotImageEx1, "LoadAlbumScreenShotImageEx1"}, |
| 61 | {1003, nullptr, "LoadAlbumScreenShotThumbnailImageEx1"}, | 47 | {1003, &IAlbumAccessorService::LoadAlbumScreenShotThumbnailImageEx1, "LoadAlbumScreenShotThumbnailImageEx1"}, |
| 62 | {8001, nullptr, "ForceAlbumUnmounted"}, | 48 | {8001, nullptr, "ForceAlbumUnmounted"}, |
| 63 | {8002, nullptr, "ResetAlbumMountStatus"}, | 49 | {8002, nullptr, "ResetAlbumMountStatus"}, |
| 64 | {8011, nullptr, "RefreshAlbumCache"}, | 50 | {8011, nullptr, "RefreshAlbumCache"}, |
| @@ -74,6 +60,199 @@ CAPS_A::CAPS_A(Core::System& system_) : ServiceFramework{system_, "caps:a"} { | |||
| 74 | RegisterHandlers(functions); | 60 | RegisterHandlers(functions); |
| 75 | } | 61 | } |
| 76 | 62 | ||
| 77 | CAPS_A::~CAPS_A() = default; | 63 | IAlbumAccessorService::~IAlbumAccessorService() = default; |
| 64 | |||
| 65 | void IAlbumAccessorService::DeleteAlbumFile(HLERequestContext& ctx) { | ||
| 66 | IPC::RequestParser rp{ctx}; | ||
| 67 | const auto file_id{rp.PopRaw<AlbumFileId>()}; | ||
| 68 | |||
| 69 | LOG_INFO(Service_Capture, "called, application_id=0x{:0x}, storage={}, type={}", | ||
| 70 | file_id.application_id, file_id.storage, file_id.type); | ||
| 71 | |||
| 72 | Result result = manager->DeleteAlbumFile(file_id); | ||
| 73 | result = TranslateResult(result); | ||
| 74 | |||
| 75 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 76 | rb.Push(result); | ||
| 77 | } | ||
| 78 | |||
| 79 | void IAlbumAccessorService::IsAlbumMounted(HLERequestContext& ctx) { | ||
| 80 | IPC::RequestParser rp{ctx}; | ||
| 81 | const auto storage{rp.PopEnum<AlbumStorage>()}; | ||
| 82 | |||
| 83 | LOG_INFO(Service_Capture, "called, storage={}", storage); | ||
| 84 | |||
| 85 | Result result = manager->IsAlbumMounted(storage); | ||
| 86 | const bool is_mounted = result.IsSuccess(); | ||
| 87 | result = TranslateResult(result); | ||
| 88 | |||
| 89 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 90 | rb.Push(result); | ||
| 91 | rb.Push<u8>(is_mounted); | ||
| 92 | } | ||
| 93 | |||
| 94 | void IAlbumAccessorService::Unknown18(HLERequestContext& ctx) { | ||
| 95 | struct UnknownBuffer { | ||
| 96 | INSERT_PADDING_BYTES(0x10); | ||
| 97 | }; | ||
| 98 | static_assert(sizeof(UnknownBuffer) == 0x10, "UnknownBuffer is an invalid size"); | ||
| 99 | |||
| 100 | LOG_WARNING(Service_Capture, "(STUBBED) called"); | ||
| 101 | |||
| 102 | std::vector<UnknownBuffer> buffer{}; | ||
| 103 | |||
| 104 | if (!buffer.empty()) { | ||
| 105 | ctx.WriteBuffer(buffer); | ||
| 106 | } | ||
| 107 | |||
| 108 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 109 | rb.Push(ResultSuccess); | ||
| 110 | rb.Push(static_cast<u32>(buffer.size())); | ||
| 111 | } | ||
| 112 | |||
| 113 | void IAlbumAccessorService::GetAlbumFileListEx0(HLERequestContext& ctx) { | ||
| 114 | IPC::RequestParser rp{ctx}; | ||
| 115 | const auto storage{rp.PopEnum<AlbumStorage>()}; | ||
| 116 | const auto flags{rp.Pop<u8>()}; | ||
| 117 | const auto album_entry_size{ctx.GetWriteBufferNumElements<AlbumEntry>()}; | ||
| 118 | |||
| 119 | LOG_INFO(Service_Capture, "called, storage={}, flags={}", storage, flags); | ||
| 120 | |||
| 121 | std::vector<AlbumEntry> entries; | ||
| 122 | Result result = manager->GetAlbumFileList(entries, storage, flags); | ||
| 123 | result = TranslateResult(result); | ||
| 124 | |||
| 125 | entries.resize(std::min(album_entry_size, entries.size())); | ||
| 126 | |||
| 127 | if (!entries.empty()) { | ||
| 128 | ctx.WriteBuffer(entries); | ||
| 129 | } | ||
| 130 | |||
| 131 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 132 | rb.Push(result); | ||
| 133 | rb.Push(entries.size()); | ||
| 134 | } | ||
| 135 | |||
| 136 | void IAlbumAccessorService::GetAutoSavingStorage(HLERequestContext& ctx) { | ||
| 137 | LOG_WARNING(Service_Capture, "(STUBBED) called"); | ||
| 138 | |||
| 139 | bool is_autosaving{}; | ||
| 140 | Result result = manager->GetAutoSavingStorage(is_autosaving); | ||
| 141 | result = TranslateResult(result); | ||
| 142 | |||
| 143 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 144 | rb.Push(result); | ||
| 145 | rb.Push<u8>(is_autosaving); | ||
| 146 | } | ||
| 147 | |||
| 148 | void IAlbumAccessorService::LoadAlbumScreenShotImageEx1(HLERequestContext& ctx) { | ||
| 149 | IPC::RequestParser rp{ctx}; | ||
| 150 | const auto file_id{rp.PopRaw<AlbumFileId>()}; | ||
| 151 | const auto decoder_options{rp.PopRaw<ScreenShotDecodeOption>()}; | ||
| 152 | const auto image_buffer_size{ctx.GetWriteBufferSize(1)}; | ||
| 153 | |||
| 154 | LOG_INFO(Service_Capture, "called, application_id=0x{:0x}, storage={}, type={}, flags={}", | ||
| 155 | file_id.application_id, file_id.storage, file_id.type, decoder_options.flags); | ||
| 156 | |||
| 157 | std::vector<u8> image; | ||
| 158 | LoadAlbumScreenShotImageOutput image_output; | ||
| 159 | Result result = | ||
| 160 | manager->LoadAlbumScreenShotImage(image_output, image, file_id, decoder_options); | ||
| 161 | result = TranslateResult(result); | ||
| 162 | |||
| 163 | if (image.size() > image_buffer_size) { | ||
| 164 | result = ResultWorkMemoryError; | ||
| 165 | } | ||
| 166 | |||
| 167 | if (result.IsSuccess()) { | ||
| 168 | ctx.WriteBuffer(image_output, 0); | ||
| 169 | ctx.WriteBuffer(image, 1); | ||
| 170 | } | ||
| 171 | |||
| 172 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 173 | rb.Push(result); | ||
| 174 | } | ||
| 175 | |||
| 176 | void IAlbumAccessorService::LoadAlbumScreenShotThumbnailImageEx1(HLERequestContext& ctx) { | ||
| 177 | IPC::RequestParser rp{ctx}; | ||
| 178 | const auto file_id{rp.PopRaw<AlbumFileId>()}; | ||
| 179 | const auto decoder_options{rp.PopRaw<ScreenShotDecodeOption>()}; | ||
| 180 | |||
| 181 | LOG_INFO(Service_Capture, "called, application_id=0x{:0x}, storage={}, type={}, flags={}", | ||
| 182 | file_id.application_id, file_id.storage, file_id.type, decoder_options.flags); | ||
| 183 | |||
| 184 | std::vector<u8> image(ctx.GetWriteBufferSize(1)); | ||
| 185 | LoadAlbumScreenShotImageOutput image_output; | ||
| 186 | Result result = | ||
| 187 | manager->LoadAlbumScreenShotThumbnail(image_output, image, file_id, decoder_options); | ||
| 188 | result = TranslateResult(result); | ||
| 189 | |||
| 190 | if (result.IsSuccess()) { | ||
| 191 | ctx.WriteBuffer(image_output, 0); | ||
| 192 | ctx.WriteBuffer(image, 1); | ||
| 193 | } | ||
| 194 | |||
| 195 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 196 | rb.Push(result); | ||
| 197 | } | ||
| 198 | |||
| 199 | Result IAlbumAccessorService::TranslateResult(Result in_result) { | ||
| 200 | if (in_result.IsSuccess()) { | ||
| 201 | return in_result; | ||
| 202 | } | ||
| 203 | |||
| 204 | if ((in_result.raw & 0x3801ff) == ResultUnknown1024.raw) { | ||
| 205 | if (in_result.description - 0x514 < 100) { | ||
| 206 | return ResultInvalidFileData; | ||
| 207 | } | ||
| 208 | if (in_result.description - 0x5dc < 100) { | ||
| 209 | return ResultInvalidFileData; | ||
| 210 | } | ||
| 211 | |||
| 212 | if (in_result.description - 0x578 < 100) { | ||
| 213 | if (in_result == ResultFileCountLimit) { | ||
| 214 | return ResultUnknown22; | ||
| 215 | } | ||
| 216 | return ResultUnknown25; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (in_result.raw < ResultUnknown1801.raw) { | ||
| 220 | if (in_result == ResultUnknown1202) { | ||
| 221 | return ResultUnknown810; | ||
| 222 | } | ||
| 223 | if (in_result == ResultUnknown1203) { | ||
| 224 | return ResultUnknown810; | ||
| 225 | } | ||
| 226 | if (in_result == ResultUnknown1701) { | ||
| 227 | return ResultUnknown5; | ||
| 228 | } | ||
| 229 | } else if (in_result.raw < ResultUnknown1803.raw) { | ||
| 230 | if (in_result == ResultUnknown1801) { | ||
| 231 | return ResultUnknown5; | ||
| 232 | } | ||
| 233 | if (in_result == ResultUnknown1802) { | ||
| 234 | return ResultUnknown6; | ||
| 235 | } | ||
| 236 | } else { | ||
| 237 | if (in_result == ResultUnknown1803) { | ||
| 238 | return ResultUnknown7; | ||
| 239 | } | ||
| 240 | if (in_result == ResultUnknown1804) { | ||
| 241 | return ResultOutOfRange; | ||
| 242 | } | ||
| 243 | } | ||
| 244 | return ResultUnknown1024; | ||
| 245 | } | ||
| 246 | |||
| 247 | if (in_result.module == ErrorModule::FS) { | ||
| 248 | if ((in_result.description >> 0xc < 0x7d) || (in_result.description - 1000 < 2000) || | ||
| 249 | (((in_result.description - 3000) >> 3) < 0x271)) { | ||
| 250 | // TODO: Translate FS error | ||
| 251 | return in_result; | ||
| 252 | } | ||
| 253 | } | ||
| 254 | |||
| 255 | return in_result; | ||
| 256 | } | ||
| 78 | 257 | ||
| 79 | } // namespace Service::Capture | 258 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_a.h b/src/core/hle/service/caps/caps_a.h index 98a21a5ad..c90cff71e 100644 --- a/src/core/hle/service/caps/caps_a.h +++ b/src/core/hle/service/caps/caps_a.h | |||
| @@ -10,11 +10,26 @@ class System; | |||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | namespace Service::Capture { | 12 | namespace Service::Capture { |
| 13 | class AlbumManager; | ||
| 13 | 14 | ||
| 14 | class CAPS_A final : public ServiceFramework<CAPS_A> { | 15 | class IAlbumAccessorService final : public ServiceFramework<IAlbumAccessorService> { |
| 15 | public: | 16 | public: |
| 16 | explicit CAPS_A(Core::System& system_); | 17 | explicit IAlbumAccessorService(Core::System& system_, |
| 17 | ~CAPS_A() override; | 18 | std::shared_ptr<AlbumManager> album_manager); |
| 19 | ~IAlbumAccessorService() override; | ||
| 20 | |||
| 21 | private: | ||
| 22 | void DeleteAlbumFile(HLERequestContext& ctx); | ||
| 23 | void IsAlbumMounted(HLERequestContext& ctx); | ||
| 24 | void Unknown18(HLERequestContext& ctx); | ||
| 25 | void GetAlbumFileListEx0(HLERequestContext& ctx); | ||
| 26 | void GetAutoSavingStorage(HLERequestContext& ctx); | ||
| 27 | void LoadAlbumScreenShotImageEx1(HLERequestContext& ctx); | ||
| 28 | void LoadAlbumScreenShotThumbnailImageEx1(HLERequestContext& ctx); | ||
| 29 | |||
| 30 | Result TranslateResult(Result in_result); | ||
| 31 | |||
| 32 | std::shared_ptr<AlbumManager> manager = nullptr; | ||
| 18 | }; | 33 | }; |
| 19 | 34 | ||
| 20 | } // namespace Service::Capture | 35 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_c.cpp b/src/core/hle/service/caps/caps_c.cpp index fc77e35cd..1e7fe6474 100644 --- a/src/core/hle/service/caps/caps_c.cpp +++ b/src/core/hle/service/caps/caps_c.cpp | |||
| @@ -3,53 +3,21 @@ | |||
| 3 | 3 | ||
| 4 | #include "common/logging/log.h" | 4 | #include "common/logging/log.h" |
| 5 | #include "core/hle/service/caps/caps_c.h" | 5 | #include "core/hle/service/caps/caps_c.h" |
| 6 | #include "core/hle/service/caps/caps_manager.h" | ||
| 7 | #include "core/hle/service/caps/caps_result.h" | ||
| 8 | #include "core/hle/service/caps/caps_types.h" | ||
| 6 | #include "core/hle/service/ipc_helpers.h" | 9 | #include "core/hle/service/ipc_helpers.h" |
| 7 | 10 | ||
| 8 | namespace Service::Capture { | 11 | namespace Service::Capture { |
| 9 | 12 | ||
| 10 | class IAlbumControlSession final : public ServiceFramework<IAlbumControlSession> { | 13 | IAlbumControlService::IAlbumControlService(Core::System& system_, |
| 11 | public: | 14 | std::shared_ptr<AlbumManager> album_manager) |
| 12 | explicit IAlbumControlSession(Core::System& system_) | 15 | : ServiceFramework{system_, "caps:c"}, manager{album_manager} { |
| 13 | : ServiceFramework{system_, "IAlbumControlSession"} { | ||
| 14 | // clang-format off | ||
| 15 | static const FunctionInfo functions[] = { | ||
| 16 | {2001, nullptr, "OpenAlbumMovieReadStream"}, | ||
| 17 | {2002, nullptr, "CloseAlbumMovieReadStream"}, | ||
| 18 | {2003, nullptr, "GetAlbumMovieReadStreamMovieDataSize"}, | ||
| 19 | {2004, nullptr, "ReadMovieDataFromAlbumMovieReadStream"}, | ||
| 20 | {2005, nullptr, "GetAlbumMovieReadStreamBrokenReason"}, | ||
| 21 | {2006, nullptr, "GetAlbumMovieReadStreamImageDataSize"}, | ||
| 22 | {2007, nullptr, "ReadImageDataFromAlbumMovieReadStream"}, | ||
| 23 | {2008, nullptr, "ReadFileAttributeFromAlbumMovieReadStream"}, | ||
| 24 | {2401, nullptr, "OpenAlbumMovieWriteStream"}, | ||
| 25 | {2402, nullptr, "FinishAlbumMovieWriteStream"}, | ||
| 26 | {2403, nullptr, "CommitAlbumMovieWriteStream"}, | ||
| 27 | {2404, nullptr, "DiscardAlbumMovieWriteStream"}, | ||
| 28 | {2405, nullptr, "DiscardAlbumMovieWriteStreamNoDelete"}, | ||
| 29 | {2406, nullptr, "CommitAlbumMovieWriteStreamEx"}, | ||
| 30 | {2411, nullptr, "StartAlbumMovieWriteStreamDataSection"}, | ||
| 31 | {2412, nullptr, "EndAlbumMovieWriteStreamDataSection"}, | ||
| 32 | {2413, nullptr, "StartAlbumMovieWriteStreamMetaSection"}, | ||
| 33 | {2414, nullptr, "EndAlbumMovieWriteStreamMetaSection"}, | ||
| 34 | {2421, nullptr, "ReadDataFromAlbumMovieWriteStream"}, | ||
| 35 | {2422, nullptr, "WriteDataToAlbumMovieWriteStream"}, | ||
| 36 | {2424, nullptr, "WriteMetaToAlbumMovieWriteStream"}, | ||
| 37 | {2431, nullptr, "GetAlbumMovieWriteStreamBrokenReason"}, | ||
| 38 | {2433, nullptr, "GetAlbumMovieWriteStreamDataSize"}, | ||
| 39 | {2434, nullptr, "SetAlbumMovieWriteStreamDataSize"}, | ||
| 40 | }; | ||
| 41 | // clang-format on | ||
| 42 | |||
| 43 | RegisterHandlers(functions); | ||
| 44 | } | ||
| 45 | }; | ||
| 46 | |||
| 47 | CAPS_C::CAPS_C(Core::System& system_) : ServiceFramework{system_, "caps:c"} { | ||
| 48 | // clang-format off | 16 | // clang-format off |
| 49 | static const FunctionInfo functions[] = { | 17 | static const FunctionInfo functions[] = { |
| 50 | {1, nullptr, "CaptureRawImage"}, | 18 | {1, nullptr, "CaptureRawImage"}, |
| 51 | {2, nullptr, "CaptureRawImageWithTimeout"}, | 19 | {2, nullptr, "CaptureRawImageWithTimeout"}, |
| 52 | {33, &CAPS_C::SetShimLibraryVersion, "SetShimLibraryVersion"}, | 20 | {33, &IAlbumControlService::SetShimLibraryVersion, "SetShimLibraryVersion"}, |
| 53 | {1001, nullptr, "RequestTakingScreenShot"}, | 21 | {1001, nullptr, "RequestTakingScreenShot"}, |
| 54 | {1002, nullptr, "RequestTakingScreenShotWithTimeout"}, | 22 | {1002, nullptr, "RequestTakingScreenShotWithTimeout"}, |
| 55 | {1011, nullptr, "NotifyTakingScreenShotRefused"}, | 23 | {1011, nullptr, "NotifyTakingScreenShotRefused"}, |
| @@ -72,9 +40,9 @@ CAPS_C::CAPS_C(Core::System& system_) : ServiceFramework{system_, "caps:c"} { | |||
| 72 | RegisterHandlers(functions); | 40 | RegisterHandlers(functions); |
| 73 | } | 41 | } |
| 74 | 42 | ||
| 75 | CAPS_C::~CAPS_C() = default; | 43 | IAlbumControlService::~IAlbumControlService() = default; |
| 76 | 44 | ||
| 77 | void CAPS_C::SetShimLibraryVersion(HLERequestContext& ctx) { | 45 | void IAlbumControlService::SetShimLibraryVersion(HLERequestContext& ctx) { |
| 78 | IPC::RequestParser rp{ctx}; | 46 | IPC::RequestParser rp{ctx}; |
| 79 | const auto library_version{rp.Pop<u64>()}; | 47 | const auto library_version{rp.Pop<u64>()}; |
| 80 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 48 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
diff --git a/src/core/hle/service/caps/caps_c.h b/src/core/hle/service/caps/caps_c.h index 537b3a2e3..92ba242db 100644 --- a/src/core/hle/service/caps/caps_c.h +++ b/src/core/hle/service/caps/caps_c.h | |||
| @@ -10,14 +10,18 @@ class System; | |||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | namespace Service::Capture { | 12 | namespace Service::Capture { |
| 13 | class AlbumManager; | ||
| 13 | 14 | ||
| 14 | class CAPS_C final : public ServiceFramework<CAPS_C> { | 15 | class IAlbumControlService final : public ServiceFramework<IAlbumControlService> { |
| 15 | public: | 16 | public: |
| 16 | explicit CAPS_C(Core::System& system_); | 17 | explicit IAlbumControlService(Core::System& system_, |
| 17 | ~CAPS_C() override; | 18 | std::shared_ptr<AlbumManager> album_manager); |
| 19 | ~IAlbumControlService() override; | ||
| 18 | 20 | ||
| 19 | private: | 21 | private: |
| 20 | void SetShimLibraryVersion(HLERequestContext& ctx); | 22 | void SetShimLibraryVersion(HLERequestContext& ctx); |
| 23 | |||
| 24 | std::shared_ptr<AlbumManager> manager = nullptr; | ||
| 21 | }; | 25 | }; |
| 22 | 26 | ||
| 23 | } // namespace Service::Capture | 27 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_manager.cpp b/src/core/hle/service/caps/caps_manager.cpp new file mode 100644 index 000000000..2df6a930a --- /dev/null +++ b/src/core/hle/service/caps/caps_manager.cpp | |||
| @@ -0,0 +1,342 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <sstream> | ||
| 5 | #include <stb_image.h> | ||
| 6 | #include <stb_image_resize.h> | ||
| 7 | |||
| 8 | #include "common/fs/file.h" | ||
| 9 | #include "common/fs/path_util.h" | ||
| 10 | #include "common/logging/log.h" | ||
| 11 | #include "core/hle/service/caps/caps_manager.h" | ||
| 12 | #include "core/hle/service/caps/caps_result.h" | ||
| 13 | |||
| 14 | namespace Service::Capture { | ||
| 15 | |||
| 16 | AlbumManager::AlbumManager() {} | ||
| 17 | |||
| 18 | AlbumManager::~AlbumManager() = default; | ||
| 19 | |||
| 20 | Result AlbumManager::DeleteAlbumFile(const AlbumFileId& file_id) { | ||
| 21 | if (file_id.storage > AlbumStorage::Sd) { | ||
| 22 | return ResultInvalidStorage; | ||
| 23 | } | ||
| 24 | |||
| 25 | if (!is_mounted) { | ||
| 26 | return ResultIsNotMounted; | ||
| 27 | } | ||
| 28 | |||
| 29 | std::filesystem::path path; | ||
| 30 | const auto result = GetFile(path, file_id); | ||
| 31 | |||
| 32 | if (result.IsError()) { | ||
| 33 | return result; | ||
| 34 | } | ||
| 35 | |||
| 36 | if (!Common::FS::RemoveFile(path)) { | ||
| 37 | return ResultFileNotFound; | ||
| 38 | } | ||
| 39 | |||
| 40 | return ResultSuccess; | ||
| 41 | } | ||
| 42 | |||
| 43 | Result AlbumManager::IsAlbumMounted(AlbumStorage storage) { | ||
| 44 | if (storage > AlbumStorage::Sd) { | ||
| 45 | return ResultInvalidStorage; | ||
| 46 | } | ||
| 47 | |||
| 48 | is_mounted = true; | ||
| 49 | |||
| 50 | if (storage == AlbumStorage::Sd) { | ||
| 51 | FindScreenshots(); | ||
| 52 | } | ||
| 53 | |||
| 54 | return is_mounted ? ResultSuccess : ResultIsNotMounted; | ||
| 55 | } | ||
| 56 | |||
| 57 | Result AlbumManager::GetAlbumFileList(std::vector<AlbumEntry>& out_entries, AlbumStorage storage, | ||
| 58 | u8 flags) const { | ||
| 59 | if (storage > AlbumStorage::Sd) { | ||
| 60 | return ResultInvalidStorage; | ||
| 61 | } | ||
| 62 | |||
| 63 | if (!is_mounted) { | ||
| 64 | return ResultIsNotMounted; | ||
| 65 | } | ||
| 66 | |||
| 67 | for (auto& [file_id, path] : album_files) { | ||
| 68 | if (file_id.storage != storage) { | ||
| 69 | continue; | ||
| 70 | } | ||
| 71 | if (out_entries.size() >= SdAlbumFileLimit) { | ||
| 72 | break; | ||
| 73 | } | ||
| 74 | |||
| 75 | const auto entry_size = Common::FS::GetSize(path); | ||
| 76 | out_entries.push_back({ | ||
| 77 | .entry_size = entry_size, | ||
| 78 | .file_id = file_id, | ||
| 79 | }); | ||
| 80 | } | ||
| 81 | |||
| 82 | return ResultSuccess; | ||
| 83 | } | ||
| 84 | |||
| 85 | Result AlbumManager::GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries, | ||
| 86 | ContentType contex_type, AlbumFileDateTime start_date, | ||
| 87 | AlbumFileDateTime end_date, u64 aruid) const { | ||
| 88 | if (!is_mounted) { | ||
| 89 | return ResultIsNotMounted; | ||
| 90 | } | ||
| 91 | |||
| 92 | for (auto& [file_id, path] : album_files) { | ||
| 93 | if (file_id.type != contex_type) { | ||
| 94 | continue; | ||
| 95 | } | ||
| 96 | |||
| 97 | if (file_id.date > start_date) { | ||
| 98 | continue; | ||
| 99 | } | ||
| 100 | |||
| 101 | if (file_id.date < end_date) { | ||
| 102 | continue; | ||
| 103 | } | ||
| 104 | |||
| 105 | if (out_entries.size() >= SdAlbumFileLimit) { | ||
| 106 | break; | ||
| 107 | } | ||
| 108 | |||
| 109 | const auto entry_size = Common::FS::GetSize(path); | ||
| 110 | ApplicationAlbumFileEntry entry{.entry = | ||
| 111 | { | ||
| 112 | .size = entry_size, | ||
| 113 | .hash{}, | ||
| 114 | .datetime = file_id.date, | ||
| 115 | .storage = file_id.storage, | ||
| 116 | .content = contex_type, | ||
| 117 | .unknown = 1, | ||
| 118 | }, | ||
| 119 | .datetime = file_id.date, | ||
| 120 | .unknown = {}}; | ||
| 121 | out_entries.push_back(entry); | ||
| 122 | } | ||
| 123 | |||
| 124 | return ResultSuccess; | ||
| 125 | } | ||
| 126 | |||
| 127 | Result AlbumManager::GetAutoSavingStorage(bool& out_is_autosaving) const { | ||
| 128 | out_is_autosaving = false; | ||
| 129 | return ResultSuccess; | ||
| 130 | } | ||
| 131 | |||
| 132 | Result AlbumManager::LoadAlbumScreenShotImage(LoadAlbumScreenShotImageOutput& out_image_output, | ||
| 133 | std::vector<u8>& out_image, | ||
| 134 | const AlbumFileId& file_id, | ||
| 135 | const ScreenShotDecodeOption& decoder_options) const { | ||
| 136 | if (file_id.storage > AlbumStorage::Sd) { | ||
| 137 | return ResultInvalidStorage; | ||
| 138 | } | ||
| 139 | |||
| 140 | if (!is_mounted) { | ||
| 141 | return ResultIsNotMounted; | ||
| 142 | } | ||
| 143 | |||
| 144 | out_image_output = { | ||
| 145 | .width = 1280, | ||
| 146 | .height = 720, | ||
| 147 | .attribute = | ||
| 148 | { | ||
| 149 | .unknown_0{}, | ||
| 150 | .orientation = AlbumImageOrientation::None, | ||
| 151 | .unknown_1{}, | ||
| 152 | .unknown_2{}, | ||
| 153 | }, | ||
| 154 | }; | ||
| 155 | |||
| 156 | std::filesystem::path path; | ||
| 157 | const auto result = GetFile(path, file_id); | ||
| 158 | |||
| 159 | if (result.IsError()) { | ||
| 160 | return result; | ||
| 161 | } | ||
| 162 | |||
| 163 | out_image.resize(out_image_output.height * out_image_output.width * STBI_rgb_alpha); | ||
| 164 | |||
| 165 | return LoadImage(out_image, path, static_cast<int>(out_image_output.width), | ||
| 166 | +static_cast<int>(out_image_output.height), decoder_options.flags); | ||
| 167 | } | ||
| 168 | |||
| 169 | Result AlbumManager::LoadAlbumScreenShotThumbnail( | ||
| 170 | LoadAlbumScreenShotImageOutput& out_image_output, std::vector<u8>& out_image, | ||
| 171 | const AlbumFileId& file_id, const ScreenShotDecodeOption& decoder_options) const { | ||
| 172 | if (file_id.storage > AlbumStorage::Sd) { | ||
| 173 | return ResultInvalidStorage; | ||
| 174 | } | ||
| 175 | |||
| 176 | if (!is_mounted) { | ||
| 177 | return ResultIsNotMounted; | ||
| 178 | } | ||
| 179 | |||
| 180 | out_image_output = { | ||
| 181 | .width = 320, | ||
| 182 | .height = 180, | ||
| 183 | .attribute = | ||
| 184 | { | ||
| 185 | .unknown_0{}, | ||
| 186 | .orientation = AlbumImageOrientation::None, | ||
| 187 | .unknown_1{}, | ||
| 188 | .unknown_2{}, | ||
| 189 | }, | ||
| 190 | }; | ||
| 191 | |||
| 192 | std::filesystem::path path; | ||
| 193 | const auto result = GetFile(path, file_id); | ||
| 194 | |||
| 195 | if (result.IsError()) { | ||
| 196 | return result; | ||
| 197 | } | ||
| 198 | |||
| 199 | out_image.resize(out_image_output.height * out_image_output.width * STBI_rgb_alpha); | ||
| 200 | |||
| 201 | return LoadImage(out_image, path, static_cast<int>(out_image_output.width), | ||
| 202 | +static_cast<int>(out_image_output.height), decoder_options.flags); | ||
| 203 | } | ||
| 204 | |||
| 205 | Result AlbumManager::GetFile(std::filesystem::path& out_path, const AlbumFileId& file_id) const { | ||
| 206 | const auto file = album_files.find(file_id); | ||
| 207 | |||
| 208 | if (file == album_files.end()) { | ||
| 209 | return ResultFileNotFound; | ||
| 210 | } | ||
| 211 | |||
| 212 | out_path = file->second; | ||
| 213 | return ResultSuccess; | ||
| 214 | } | ||
| 215 | |||
| 216 | void AlbumManager::FindScreenshots() { | ||
| 217 | is_mounted = false; | ||
| 218 | album_files.clear(); | ||
| 219 | |||
| 220 | // TODO: Swap this with a blocking operation. | ||
| 221 | const auto screenshots_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir); | ||
| 222 | Common::FS::IterateDirEntries( | ||
| 223 | screenshots_dir, | ||
| 224 | [this](const std::filesystem::path& full_path) { | ||
| 225 | AlbumEntry entry; | ||
| 226 | if (GetAlbumEntry(entry, full_path).IsError()) { | ||
| 227 | return true; | ||
| 228 | } | ||
| 229 | while (album_files.contains(entry.file_id)) { | ||
| 230 | if (++entry.file_id.date.unique_id == 0) { | ||
| 231 | break; | ||
| 232 | } | ||
| 233 | } | ||
| 234 | album_files[entry.file_id] = full_path; | ||
| 235 | return true; | ||
| 236 | }, | ||
| 237 | Common::FS::DirEntryFilter::File); | ||
| 238 | |||
| 239 | is_mounted = true; | ||
| 240 | } | ||
| 241 | |||
| 242 | Result AlbumManager::GetAlbumEntry(AlbumEntry& out_entry, const std::filesystem::path& path) const { | ||
| 243 | std::istringstream line_stream(path.filename().string()); | ||
| 244 | std::string date; | ||
| 245 | std::string application; | ||
| 246 | std::string time; | ||
| 247 | |||
| 248 | // Parse filename to obtain entry properties | ||
| 249 | std::getline(line_stream, application, '_'); | ||
| 250 | std::getline(line_stream, date, '_'); | ||
| 251 | std::getline(line_stream, time, '_'); | ||
| 252 | |||
| 253 | std::istringstream date_stream(date); | ||
| 254 | std::istringstream time_stream(time); | ||
| 255 | std::string year; | ||
| 256 | std::string month; | ||
| 257 | std::string day; | ||
| 258 | std::string hour; | ||
| 259 | std::string minute; | ||
| 260 | std::string second; | ||
| 261 | |||
| 262 | std::getline(date_stream, year, '-'); | ||
| 263 | std::getline(date_stream, month, '-'); | ||
| 264 | std::getline(date_stream, day, '-'); | ||
| 265 | |||
| 266 | std::getline(time_stream, hour, '-'); | ||
| 267 | std::getline(time_stream, minute, '-'); | ||
| 268 | std::getline(time_stream, second, '-'); | ||
| 269 | |||
| 270 | try { | ||
| 271 | out_entry = { | ||
| 272 | .entry_size = 1, | ||
| 273 | .file_id{ | ||
| 274 | .application_id = static_cast<u64>(std::stoll(application, 0, 16)), | ||
| 275 | .date = | ||
| 276 | { | ||
| 277 | .year = static_cast<u16>(std::stoi(year)), | ||
| 278 | .month = static_cast<u8>(std::stoi(month)), | ||
| 279 | .day = static_cast<u8>(std::stoi(day)), | ||
| 280 | .hour = static_cast<u8>(std::stoi(hour)), | ||
| 281 | .minute = static_cast<u8>(std::stoi(minute)), | ||
| 282 | .second = static_cast<u8>(std::stoi(second)), | ||
| 283 | .unique_id = 0, | ||
| 284 | }, | ||
| 285 | .storage = AlbumStorage::Sd, | ||
| 286 | .type = ContentType::Screenshot, | ||
| 287 | .unknown = 1, | ||
| 288 | }, | ||
| 289 | }; | ||
| 290 | } catch (const std::invalid_argument&) { | ||
| 291 | return ResultUnknown; | ||
| 292 | } catch (const std::out_of_range&) { | ||
| 293 | return ResultUnknown; | ||
| 294 | } catch (const std::exception&) { | ||
| 295 | return ResultUnknown; | ||
| 296 | } | ||
| 297 | |||
| 298 | return ResultSuccess; | ||
| 299 | } | ||
| 300 | |||
| 301 | Result AlbumManager::LoadImage(std::span<u8> out_image, const std::filesystem::path& path, | ||
| 302 | int width, int height, ScreenShotDecoderFlag flag) const { | ||
| 303 | if (out_image.size() != static_cast<std::size_t>(width * height * STBI_rgb_alpha)) { | ||
| 304 | return ResultUnknown; | ||
| 305 | } | ||
| 306 | |||
| 307 | const Common::FS::IOFile db_file{path, Common::FS::FileAccessMode::Read, | ||
| 308 | Common::FS::FileType::BinaryFile}; | ||
| 309 | |||
| 310 | std::vector<u8> raw_file(db_file.GetSize()); | ||
| 311 | if (db_file.Read(raw_file) != raw_file.size()) { | ||
| 312 | return ResultUnknown; | ||
| 313 | } | ||
| 314 | |||
| 315 | int filter_flag = STBIR_FILTER_DEFAULT; | ||
| 316 | int original_width, original_height, color_channels; | ||
| 317 | const auto dbi_image = | ||
| 318 | stbi_load_from_memory(raw_file.data(), static_cast<int>(raw_file.size()), &original_width, | ||
| 319 | &original_height, &color_channels, STBI_rgb_alpha); | ||
| 320 | |||
| 321 | if (dbi_image == nullptr) { | ||
| 322 | return ResultUnknown; | ||
| 323 | } | ||
| 324 | |||
| 325 | switch (flag) { | ||
| 326 | case ScreenShotDecoderFlag::EnableFancyUpsampling: | ||
| 327 | filter_flag = STBIR_FILTER_TRIANGLE; | ||
| 328 | break; | ||
| 329 | case ScreenShotDecoderFlag::EnableBlockSmoothing: | ||
| 330 | filter_flag = STBIR_FILTER_BOX; | ||
| 331 | break; | ||
| 332 | default: | ||
| 333 | filter_flag = STBIR_FILTER_DEFAULT; | ||
| 334 | break; | ||
| 335 | } | ||
| 336 | |||
| 337 | stbir_resize_uint8_srgb(dbi_image, original_width, original_height, 0, out_image.data(), width, | ||
| 338 | height, 0, STBI_rgb_alpha, 3, filter_flag); | ||
| 339 | |||
| 340 | return ResultSuccess; | ||
| 341 | } | ||
| 342 | } // namespace Service::Capture | ||
diff --git a/src/core/hle/service/caps/caps_manager.h b/src/core/hle/service/caps/caps_manager.h new file mode 100644 index 000000000..8337c655c --- /dev/null +++ b/src/core/hle/service/caps/caps_manager.h | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <unordered_map> | ||
| 7 | |||
| 8 | #include "common/fs/fs.h" | ||
| 9 | #include "core/hle/result.h" | ||
| 10 | #include "core/hle/service/caps/caps_types.h" | ||
| 11 | |||
| 12 | namespace Core { | ||
| 13 | class System; | ||
| 14 | } | ||
| 15 | |||
| 16 | namespace std { | ||
| 17 | // Hash used to create lists from AlbumFileId data | ||
| 18 | template <> | ||
| 19 | struct hash<Service::Capture::AlbumFileId> { | ||
| 20 | size_t operator()(const Service::Capture::AlbumFileId& pad_id) const noexcept { | ||
| 21 | u64 hash_value = (static_cast<u64>(pad_id.date.year) << 8); | ||
| 22 | hash_value ^= (static_cast<u64>(pad_id.date.month) << 7); | ||
| 23 | hash_value ^= (static_cast<u64>(pad_id.date.day) << 6); | ||
| 24 | hash_value ^= (static_cast<u64>(pad_id.date.hour) << 5); | ||
| 25 | hash_value ^= (static_cast<u64>(pad_id.date.minute) << 4); | ||
| 26 | hash_value ^= (static_cast<u64>(pad_id.date.second) << 3); | ||
| 27 | hash_value ^= (static_cast<u64>(pad_id.date.unique_id) << 2); | ||
| 28 | hash_value ^= (static_cast<u64>(pad_id.storage) << 1); | ||
| 29 | hash_value ^= static_cast<u64>(pad_id.type); | ||
| 30 | return static_cast<size_t>(hash_value); | ||
| 31 | } | ||
| 32 | }; | ||
| 33 | |||
| 34 | } // namespace std | ||
| 35 | |||
| 36 | namespace Service::Capture { | ||
| 37 | |||
| 38 | class AlbumManager { | ||
| 39 | public: | ||
| 40 | explicit AlbumManager(); | ||
| 41 | ~AlbumManager(); | ||
| 42 | |||
| 43 | Result DeleteAlbumFile(const AlbumFileId& file_id); | ||
| 44 | Result IsAlbumMounted(AlbumStorage storage); | ||
| 45 | Result GetAlbumFileList(std::vector<AlbumEntry>& out_entries, AlbumStorage storage, | ||
| 46 | u8 flags) const; | ||
| 47 | Result GetAlbumFileList(std::vector<ApplicationAlbumFileEntry>& out_entries, | ||
| 48 | ContentType contex_type, AlbumFileDateTime start_date, | ||
| 49 | AlbumFileDateTime end_date, u64 aruid) const; | ||
| 50 | Result GetAutoSavingStorage(bool& out_is_autosaving) const; | ||
| 51 | Result LoadAlbumScreenShotImage(LoadAlbumScreenShotImageOutput& out_image_output, | ||
| 52 | std::vector<u8>& out_image, const AlbumFileId& file_id, | ||
| 53 | const ScreenShotDecodeOption& decoder_options) const; | ||
| 54 | Result LoadAlbumScreenShotThumbnail(LoadAlbumScreenShotImageOutput& out_image_output, | ||
| 55 | std::vector<u8>& out_image, const AlbumFileId& file_id, | ||
| 56 | const ScreenShotDecodeOption& decoder_options) const; | ||
| 57 | |||
| 58 | private: | ||
| 59 | static constexpr std::size_t NandAlbumFileLimit = 1000; | ||
| 60 | static constexpr std::size_t SdAlbumFileLimit = 10000; | ||
| 61 | |||
| 62 | void FindScreenshots(); | ||
| 63 | Result GetFile(std::filesystem::path& out_path, const AlbumFileId& file_id) const; | ||
| 64 | Result GetAlbumEntry(AlbumEntry& out_entry, const std::filesystem::path& path) const; | ||
| 65 | Result LoadImage(std::span<u8> out_image, const std::filesystem::path& path, int width, | ||
| 66 | int height, ScreenShotDecoderFlag flag) const; | ||
| 67 | |||
| 68 | bool is_mounted{}; | ||
| 69 | std::unordered_map<AlbumFileId, std::filesystem::path> album_files; | ||
| 70 | }; | ||
| 71 | |||
| 72 | } // namespace Service::Capture | ||
diff --git a/src/core/hle/service/caps/caps_result.h b/src/core/hle/service/caps/caps_result.h new file mode 100644 index 000000000..c65e5fb9a --- /dev/null +++ b/src/core/hle/service/caps/caps_result.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "core/hle/result.h" | ||
| 7 | |||
| 8 | namespace Service::Capture { | ||
| 9 | |||
| 10 | constexpr Result ResultWorkMemoryError(ErrorModule::Capture, 3); | ||
| 11 | constexpr Result ResultUnknown5(ErrorModule::Capture, 5); | ||
| 12 | constexpr Result ResultUnknown6(ErrorModule::Capture, 6); | ||
| 13 | constexpr Result ResultUnknown7(ErrorModule::Capture, 7); | ||
| 14 | constexpr Result ResultOutOfRange(ErrorModule::Capture, 8); | ||
| 15 | constexpr Result ResulInvalidTimestamp(ErrorModule::Capture, 12); | ||
| 16 | constexpr Result ResultInvalidStorage(ErrorModule::Capture, 13); | ||
| 17 | constexpr Result ResultInvalidFileContents(ErrorModule::Capture, 14); | ||
| 18 | constexpr Result ResultIsNotMounted(ErrorModule::Capture, 21); | ||
| 19 | constexpr Result ResultUnknown22(ErrorModule::Capture, 22); | ||
| 20 | constexpr Result ResultFileNotFound(ErrorModule::Capture, 23); | ||
| 21 | constexpr Result ResultInvalidFileData(ErrorModule::Capture, 24); | ||
| 22 | constexpr Result ResultUnknown25(ErrorModule::Capture, 25); | ||
| 23 | constexpr Result ResultReadBufferShortage(ErrorModule::Capture, 30); | ||
| 24 | constexpr Result ResultUnknown810(ErrorModule::Capture, 810); | ||
| 25 | constexpr Result ResultUnknown1024(ErrorModule::Capture, 1024); | ||
| 26 | constexpr Result ResultUnknown1202(ErrorModule::Capture, 1202); | ||
| 27 | constexpr Result ResultUnknown1203(ErrorModule::Capture, 1203); | ||
| 28 | constexpr Result ResultFileCountLimit(ErrorModule::Capture, 1401); | ||
| 29 | constexpr Result ResultUnknown1701(ErrorModule::Capture, 1701); | ||
| 30 | constexpr Result ResultUnknown1801(ErrorModule::Capture, 1801); | ||
| 31 | constexpr Result ResultUnknown1802(ErrorModule::Capture, 1802); | ||
| 32 | constexpr Result ResultUnknown1803(ErrorModule::Capture, 1803); | ||
| 33 | constexpr Result ResultUnknown1804(ErrorModule::Capture, 1804); | ||
| 34 | |||
| 35 | } // namespace Service::Capture | ||
diff --git a/src/core/hle/service/caps/caps_sc.cpp b/src/core/hle/service/caps/caps_sc.cpp index 395b13da7..6117cb7c6 100644 --- a/src/core/hle/service/caps/caps_sc.cpp +++ b/src/core/hle/service/caps/caps_sc.cpp | |||
| @@ -5,7 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | namespace Service::Capture { | 6 | namespace Service::Capture { |
| 7 | 7 | ||
| 8 | CAPS_SC::CAPS_SC(Core::System& system_) : ServiceFramework{system_, "caps:sc"} { | 8 | IScreenShotControlService::IScreenShotControlService(Core::System& system_) |
| 9 | : ServiceFramework{system_, "caps:sc"} { | ||
| 9 | // clang-format off | 10 | // clang-format off |
| 10 | static const FunctionInfo functions[] = { | 11 | static const FunctionInfo functions[] = { |
| 11 | {1, nullptr, "CaptureRawImage"}, | 12 | {1, nullptr, "CaptureRawImage"}, |
| @@ -34,6 +35,6 @@ CAPS_SC::CAPS_SC(Core::System& system_) : ServiceFramework{system_, "caps:sc"} { | |||
| 34 | RegisterHandlers(functions); | 35 | RegisterHandlers(functions); |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | CAPS_SC::~CAPS_SC() = default; | 38 | IScreenShotControlService::~IScreenShotControlService() = default; |
| 38 | 39 | ||
| 39 | } // namespace Service::Capture | 40 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_sc.h b/src/core/hle/service/caps/caps_sc.h index e5600f6d7..d555f4979 100644 --- a/src/core/hle/service/caps/caps_sc.h +++ b/src/core/hle/service/caps/caps_sc.h | |||
| @@ -11,10 +11,10 @@ class System; | |||
| 11 | 11 | ||
| 12 | namespace Service::Capture { | 12 | namespace Service::Capture { |
| 13 | 13 | ||
| 14 | class CAPS_SC final : public ServiceFramework<CAPS_SC> { | 14 | class IScreenShotControlService final : public ServiceFramework<IScreenShotControlService> { |
| 15 | public: | 15 | public: |
| 16 | explicit CAPS_SC(Core::System& system_); | 16 | explicit IScreenShotControlService(Core::System& system_); |
| 17 | ~CAPS_SC() override; | 17 | ~IScreenShotControlService() override; |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | } // namespace Service::Capture | 20 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_ss.cpp b/src/core/hle/service/caps/caps_ss.cpp index 62b9edd41..d0d1b5425 100644 --- a/src/core/hle/service/caps/caps_ss.cpp +++ b/src/core/hle/service/caps/caps_ss.cpp | |||
| @@ -5,7 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | namespace Service::Capture { | 6 | namespace Service::Capture { |
| 7 | 7 | ||
| 8 | CAPS_SS::CAPS_SS(Core::System& system_) : ServiceFramework{system_, "caps:ss"} { | 8 | IScreenShotService::IScreenShotService(Core::System& system_) |
| 9 | : ServiceFramework{system_, "caps:ss"} { | ||
| 9 | // clang-format off | 10 | // clang-format off |
| 10 | static const FunctionInfo functions[] = { | 11 | static const FunctionInfo functions[] = { |
| 11 | {201, nullptr, "SaveScreenShot"}, | 12 | {201, nullptr, "SaveScreenShot"}, |
| @@ -21,6 +22,6 @@ CAPS_SS::CAPS_SS(Core::System& system_) : ServiceFramework{system_, "caps:ss"} { | |||
| 21 | RegisterHandlers(functions); | 22 | RegisterHandlers(functions); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | CAPS_SS::~CAPS_SS() = default; | 25 | IScreenShotService::~IScreenShotService() = default; |
| 25 | 26 | ||
| 26 | } // namespace Service::Capture | 27 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_ss.h b/src/core/hle/service/caps/caps_ss.h index 718ade485..381e44fd4 100644 --- a/src/core/hle/service/caps/caps_ss.h +++ b/src/core/hle/service/caps/caps_ss.h | |||
| @@ -11,10 +11,10 @@ class System; | |||
| 11 | 11 | ||
| 12 | namespace Service::Capture { | 12 | namespace Service::Capture { |
| 13 | 13 | ||
| 14 | class CAPS_SS final : public ServiceFramework<CAPS_SS> { | 14 | class IScreenShotService final : public ServiceFramework<IScreenShotService> { |
| 15 | public: | 15 | public: |
| 16 | explicit CAPS_SS(Core::System& system_); | 16 | explicit IScreenShotService(Core::System& system_); |
| 17 | ~CAPS_SS() override; | 17 | ~IScreenShotService() override; |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | } // namespace Service::Capture | 20 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_su.cpp b/src/core/hle/service/caps/caps_su.cpp index 3b11cc95c..cad173dc7 100644 --- a/src/core/hle/service/caps/caps_su.cpp +++ b/src/core/hle/service/caps/caps_su.cpp | |||
| @@ -7,10 +7,11 @@ | |||
| 7 | 7 | ||
| 8 | namespace Service::Capture { | 8 | namespace Service::Capture { |
| 9 | 9 | ||
| 10 | CAPS_SU::CAPS_SU(Core::System& system_) : ServiceFramework{system_, "caps:su"} { | 10 | IScreenShotApplicationService::IScreenShotApplicationService(Core::System& system_) |
| 11 | : ServiceFramework{system_, "caps:su"} { | ||
| 11 | // clang-format off | 12 | // clang-format off |
| 12 | static const FunctionInfo functions[] = { | 13 | static const FunctionInfo functions[] = { |
| 13 | {32, &CAPS_SU::SetShimLibraryVersion, "SetShimLibraryVersion"}, | 14 | {32, &IScreenShotApplicationService::SetShimLibraryVersion, "SetShimLibraryVersion"}, |
| 14 | {201, nullptr, "SaveScreenShot"}, | 15 | {201, nullptr, "SaveScreenShot"}, |
| 15 | {203, nullptr, "SaveScreenShotEx0"}, | 16 | {203, nullptr, "SaveScreenShotEx0"}, |
| 16 | {205, nullptr, "SaveScreenShotEx1"}, | 17 | {205, nullptr, "SaveScreenShotEx1"}, |
| @@ -21,9 +22,9 @@ CAPS_SU::CAPS_SU(Core::System& system_) : ServiceFramework{system_, "caps:su"} { | |||
| 21 | RegisterHandlers(functions); | 22 | RegisterHandlers(functions); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| 24 | CAPS_SU::~CAPS_SU() = default; | 25 | IScreenShotApplicationService::~IScreenShotApplicationService() = default; |
| 25 | 26 | ||
| 26 | void CAPS_SU::SetShimLibraryVersion(HLERequestContext& ctx) { | 27 | void IScreenShotApplicationService::SetShimLibraryVersion(HLERequestContext& ctx) { |
| 27 | IPC::RequestParser rp{ctx}; | 28 | IPC::RequestParser rp{ctx}; |
| 28 | const auto library_version{rp.Pop<u64>()}; | 29 | const auto library_version{rp.Pop<u64>()}; |
| 29 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 30 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
diff --git a/src/core/hle/service/caps/caps_su.h b/src/core/hle/service/caps/caps_su.h index c6398858d..647e3059d 100644 --- a/src/core/hle/service/caps/caps_su.h +++ b/src/core/hle/service/caps/caps_su.h | |||
| @@ -11,10 +11,10 @@ class System; | |||
| 11 | 11 | ||
| 12 | namespace Service::Capture { | 12 | namespace Service::Capture { |
| 13 | 13 | ||
| 14 | class CAPS_SU final : public ServiceFramework<CAPS_SU> { | 14 | class IScreenShotApplicationService final : public ServiceFramework<IScreenShotApplicationService> { |
| 15 | public: | 15 | public: |
| 16 | explicit CAPS_SU(Core::System& system_); | 16 | explicit IScreenShotApplicationService(Core::System& system_); |
| 17 | ~CAPS_SU() override; | 17 | ~IScreenShotApplicationService() override; |
| 18 | 18 | ||
| 19 | private: | 19 | private: |
| 20 | void SetShimLibraryVersion(HLERequestContext& ctx); | 20 | void SetShimLibraryVersion(HLERequestContext& ctx); |
diff --git a/src/core/hle/service/caps/caps_types.h b/src/core/hle/service/caps/caps_types.h new file mode 100644 index 000000000..bf6061273 --- /dev/null +++ b/src/core/hle/service/caps/caps_types.h | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | namespace Service::Capture { | ||
| 10 | |||
| 11 | // This is nn::album::ImageOrientation | ||
| 12 | enum class AlbumImageOrientation { | ||
| 13 | None, | ||
| 14 | Rotate90, | ||
| 15 | Rotate180, | ||
| 16 | Rotate270, | ||
| 17 | }; | ||
| 18 | |||
| 19 | // This is nn::album::AlbumReportOption | ||
| 20 | enum class AlbumReportOption : s32 { | ||
| 21 | Disable, | ||
| 22 | Enable, | ||
| 23 | }; | ||
| 24 | |||
| 25 | enum class ContentType : u8 { | ||
| 26 | Screenshot = 0, | ||
| 27 | Movie = 1, | ||
| 28 | ExtraMovie = 3, | ||
| 29 | }; | ||
| 30 | |||
| 31 | enum class AlbumStorage : u8 { | ||
| 32 | Nand, | ||
| 33 | Sd, | ||
| 34 | }; | ||
| 35 | |||
| 36 | enum class ScreenShotDecoderFlag : u64 { | ||
| 37 | None = 0, | ||
| 38 | EnableFancyUpsampling = 1 << 0, | ||
| 39 | EnableBlockSmoothing = 1 << 1, | ||
| 40 | }; | ||
| 41 | |||
| 42 | // This is nn::capsrv::AlbumFileDateTime | ||
| 43 | struct AlbumFileDateTime { | ||
| 44 | u16 year{}; | ||
| 45 | u8 month{}; | ||
| 46 | u8 day{}; | ||
| 47 | u8 hour{}; | ||
| 48 | u8 minute{}; | ||
| 49 | u8 second{}; | ||
| 50 | u8 unique_id{}; | ||
| 51 | |||
| 52 | friend constexpr bool operator==(const AlbumFileDateTime&, const AlbumFileDateTime&) = default; | ||
| 53 | friend constexpr bool operator>(const AlbumFileDateTime& a, const AlbumFileDateTime& b) { | ||
| 54 | if (a.year > b.year) { | ||
| 55 | return true; | ||
| 56 | } | ||
| 57 | if (a.month > b.month) { | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | if (a.day > b.day) { | ||
| 61 | return true; | ||
| 62 | } | ||
| 63 | if (a.hour > b.hour) { | ||
| 64 | return true; | ||
| 65 | } | ||
| 66 | if (a.minute > b.minute) { | ||
| 67 | return true; | ||
| 68 | } | ||
| 69 | return a.second > b.second; | ||
| 70 | }; | ||
| 71 | friend constexpr bool operator<(const AlbumFileDateTime& a, const AlbumFileDateTime& b) { | ||
| 72 | if (a.year < b.year) { | ||
| 73 | return true; | ||
| 74 | } | ||
| 75 | if (a.month < b.month) { | ||
| 76 | return true; | ||
| 77 | } | ||
| 78 | if (a.day < b.day) { | ||
| 79 | return true; | ||
| 80 | } | ||
| 81 | if (a.hour < b.hour) { | ||
| 82 | return true; | ||
| 83 | } | ||
| 84 | if (a.minute < b.minute) { | ||
| 85 | return true; | ||
| 86 | } | ||
| 87 | return a.second < b.second; | ||
| 88 | }; | ||
| 89 | }; | ||
| 90 | static_assert(sizeof(AlbumFileDateTime) == 0x8, "AlbumFileDateTime has incorrect size."); | ||
| 91 | |||
| 92 | // This is nn::album::AlbumEntry | ||
| 93 | struct AlbumFileEntry { | ||
| 94 | u64 size{}; // Size of the entry | ||
| 95 | u64 hash{}; // AES256 with hardcoded key over AlbumEntry | ||
| 96 | AlbumFileDateTime datetime{}; | ||
| 97 | AlbumStorage storage{}; | ||
| 98 | ContentType content{}; | ||
| 99 | INSERT_PADDING_BYTES(5); | ||
| 100 | u8 unknown{}; // Set to 1 on official SW | ||
| 101 | }; | ||
| 102 | static_assert(sizeof(AlbumFileEntry) == 0x20, "AlbumFileEntry has incorrect size."); | ||
| 103 | |||
| 104 | struct AlbumFileId { | ||
| 105 | u64 application_id{}; | ||
| 106 | AlbumFileDateTime date{}; | ||
| 107 | AlbumStorage storage{}; | ||
| 108 | ContentType type{}; | ||
| 109 | INSERT_PADDING_BYTES(0x5); | ||
| 110 | u8 unknown{}; | ||
| 111 | |||
| 112 | friend constexpr bool operator==(const AlbumFileId&, const AlbumFileId&) = default; | ||
| 113 | }; | ||
| 114 | static_assert(sizeof(AlbumFileId) == 0x18, "AlbumFileId is an invalid size"); | ||
| 115 | |||
| 116 | // This is nn::capsrv::AlbumEntry | ||
| 117 | struct AlbumEntry { | ||
| 118 | u64 entry_size{}; | ||
| 119 | AlbumFileId file_id{}; | ||
| 120 | }; | ||
| 121 | static_assert(sizeof(AlbumEntry) == 0x20, "AlbumEntry has incorrect size."); | ||
| 122 | |||
| 123 | // This is nn::capsrv::ApplicationAlbumEntry | ||
| 124 | struct ApplicationAlbumEntry { | ||
| 125 | u64 size{}; // Size of the entry | ||
| 126 | u64 hash{}; // AES256 with hardcoded key over AlbumEntry | ||
| 127 | AlbumFileDateTime datetime{}; | ||
| 128 | AlbumStorage storage{}; | ||
| 129 | ContentType content{}; | ||
| 130 | INSERT_PADDING_BYTES(5); | ||
| 131 | u8 unknown{1}; // Set to 1 on official SW | ||
| 132 | }; | ||
| 133 | static_assert(sizeof(ApplicationAlbumEntry) == 0x20, "ApplicationAlbumEntry has incorrect size."); | ||
| 134 | |||
| 135 | // This is nn::capsrv::ApplicationAlbumFileEntry | ||
| 136 | struct ApplicationAlbumFileEntry { | ||
| 137 | ApplicationAlbumEntry entry{}; | ||
| 138 | AlbumFileDateTime datetime{}; | ||
| 139 | u64 unknown{}; | ||
| 140 | }; | ||
| 141 | static_assert(sizeof(ApplicationAlbumFileEntry) == 0x30, | ||
| 142 | "ApplicationAlbumFileEntry has incorrect size."); | ||
| 143 | |||
| 144 | struct ApplicationData { | ||
| 145 | std::array<u8, 0x400> data{}; | ||
| 146 | u32 data_size{}; | ||
| 147 | }; | ||
| 148 | static_assert(sizeof(ApplicationData) == 0x404, "ApplicationData is an invalid size"); | ||
| 149 | |||
| 150 | struct ScreenShotAttribute { | ||
| 151 | u32 unknown_0{}; | ||
| 152 | AlbumImageOrientation orientation{}; | ||
| 153 | u32 unknown_1{}; | ||
| 154 | u32 unknown_2{}; | ||
| 155 | INSERT_PADDING_BYTES(0x30); | ||
| 156 | }; | ||
| 157 | static_assert(sizeof(ScreenShotAttribute) == 0x40, "ScreenShotAttribute is an invalid size"); | ||
| 158 | |||
| 159 | struct ScreenShotDecodeOption { | ||
| 160 | ScreenShotDecoderFlag flags{}; | ||
| 161 | INSERT_PADDING_BYTES(0x18); | ||
| 162 | }; | ||
| 163 | static_assert(sizeof(ScreenShotDecodeOption) == 0x20, "ScreenShotDecodeOption is an invalid size"); | ||
| 164 | |||
| 165 | struct LoadAlbumScreenShotImageOutput { | ||
| 166 | s64 width{}; | ||
| 167 | s64 height{}; | ||
| 168 | ScreenShotAttribute attribute{}; | ||
| 169 | INSERT_PADDING_BYTES(0x400); | ||
| 170 | }; | ||
| 171 | static_assert(sizeof(LoadAlbumScreenShotImageOutput) == 0x450, | ||
| 172 | "LoadAlbumScreenShotImageOutput is an invalid size"); | ||
| 173 | |||
| 174 | struct LoadAlbumScreenShotImageOutputForApplication { | ||
| 175 | s64 width{}; | ||
| 176 | s64 height{}; | ||
| 177 | ScreenShotAttribute attribute{}; | ||
| 178 | ApplicationData data{}; | ||
| 179 | INSERT_PADDING_BYTES(0xAC); | ||
| 180 | }; | ||
| 181 | static_assert(sizeof(LoadAlbumScreenShotImageOutputForApplication) == 0x500, | ||
| 182 | "LoadAlbumScreenShotImageOutput is an invalid size"); | ||
| 183 | |||
| 184 | } // namespace Service::Capture | ||
diff --git a/src/core/hle/service/caps/caps_u.cpp b/src/core/hle/service/caps/caps_u.cpp index bffe0f8d0..260f25490 100644 --- a/src/core/hle/service/caps/caps_u.cpp +++ b/src/core/hle/service/caps/caps_u.cpp | |||
| @@ -2,45 +2,29 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include "common/logging/log.h" | 4 | #include "common/logging/log.h" |
| 5 | #include "core/hle/service/caps/caps.h" | 5 | #include "core/hle/service/caps/caps_manager.h" |
| 6 | #include "core/hle/service/caps/caps_types.h" | ||
| 6 | #include "core/hle/service/caps/caps_u.h" | 7 | #include "core/hle/service/caps/caps_u.h" |
| 7 | #include "core/hle/service/ipc_helpers.h" | 8 | #include "core/hle/service/ipc_helpers.h" |
| 8 | 9 | ||
| 9 | namespace Service::Capture { | 10 | namespace Service::Capture { |
| 10 | 11 | ||
| 11 | class IAlbumAccessorApplicationSession final | 12 | IAlbumApplicationService::IAlbumApplicationService(Core::System& system_, |
| 12 | : public ServiceFramework<IAlbumAccessorApplicationSession> { | 13 | std::shared_ptr<AlbumManager> album_manager) |
| 13 | public: | 14 | : ServiceFramework{system_, "caps:u"}, manager{album_manager} { |
| 14 | explicit IAlbumAccessorApplicationSession(Core::System& system_) | ||
| 15 | : ServiceFramework{system_, "IAlbumAccessorApplicationSession"} { | ||
| 16 | // clang-format off | ||
| 17 | static const FunctionInfo functions[] = { | ||
| 18 | {2001, nullptr, "OpenAlbumMovieReadStream"}, | ||
| 19 | {2002, nullptr, "CloseAlbumMovieReadStream"}, | ||
| 20 | {2003, nullptr, "GetAlbumMovieReadStreamMovieDataSize"}, | ||
| 21 | {2004, nullptr, "ReadMovieDataFromAlbumMovieReadStream"}, | ||
| 22 | {2005, nullptr, "GetAlbumMovieReadStreamBrokenReason"}, | ||
| 23 | }; | ||
| 24 | // clang-format on | ||
| 25 | |||
| 26 | RegisterHandlers(functions); | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | |||
| 30 | CAPS_U::CAPS_U(Core::System& system_) : ServiceFramework{system_, "caps:u"} { | ||
| 31 | // clang-format off | 15 | // clang-format off |
| 32 | static const FunctionInfo functions[] = { | 16 | static const FunctionInfo functions[] = { |
| 33 | {32, &CAPS_U::SetShimLibraryVersion, "SetShimLibraryVersion"}, | 17 | {32, &IAlbumApplicationService::SetShimLibraryVersion, "SetShimLibraryVersion"}, |
| 34 | {102, &CAPS_U::GetAlbumContentsFileListForApplication, "GetAlbumContentsFileListForApplication"}, | 18 | {102, &IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated, "GetAlbumFileList0AafeAruidDeprecated"}, |
| 35 | {103, nullptr, "DeleteAlbumContentsFileForApplication"}, | 19 | {103, nullptr, "DeleteAlbumFileByAruid"}, |
| 36 | {104, nullptr, "GetAlbumContentsFileSizeForApplication"}, | 20 | {104, nullptr, "GetAlbumFileSizeByAruid"}, |
| 37 | {105, nullptr, "DeleteAlbumFileByAruidForDebug"}, | 21 | {105, nullptr, "DeleteAlbumFileByAruidForDebug"}, |
| 38 | {110, nullptr, "LoadAlbumContentsFileScreenShotImageForApplication"}, | 22 | {110, nullptr, "LoadAlbumScreenShotImageByAruid"}, |
| 39 | {120, nullptr, "LoadAlbumContentsFileThumbnailImageForApplication"}, | 23 | {120, nullptr, "LoadAlbumScreenShotThumbnailImageByAruid"}, |
| 40 | {130, nullptr, "PrecheckToCreateContentsForApplication"}, | 24 | {130, nullptr, "PrecheckToCreateContentsByAruid"}, |
| 41 | {140, nullptr, "GetAlbumFileList1AafeAruidDeprecated"}, | 25 | {140, nullptr, "GetAlbumFileList1AafeAruidDeprecated"}, |
| 42 | {141, nullptr, "GetAlbumFileList2AafeUidAruidDeprecated"}, | 26 | {141, nullptr, "GetAlbumFileList2AafeUidAruidDeprecated"}, |
| 43 | {142, &CAPS_U::GetAlbumFileList3AaeAruid, "GetAlbumFileList3AaeAruid"}, | 27 | {142, &IAlbumApplicationService::GetAlbumFileList3AaeAruid, "GetAlbumFileList3AaeAruid"}, |
| 44 | {143, nullptr, "GetAlbumFileList4AaeUidAruid"}, | 28 | {143, nullptr, "GetAlbumFileList4AaeUidAruid"}, |
| 45 | {144, nullptr, "GetAllAlbumFileList3AaeAruid"}, | 29 | {144, nullptr, "GetAllAlbumFileList3AaeAruid"}, |
| 46 | {60002, nullptr, "OpenAccessorSessionForApplication"}, | 30 | {60002, nullptr, "OpenAccessorSessionForApplication"}, |
| @@ -50,9 +34,9 @@ CAPS_U::CAPS_U(Core::System& system_) : ServiceFramework{system_, "caps:u"} { | |||
| 50 | RegisterHandlers(functions); | 34 | RegisterHandlers(functions); |
| 51 | } | 35 | } |
| 52 | 36 | ||
| 53 | CAPS_U::~CAPS_U() = default; | 37 | IAlbumApplicationService::~IAlbumApplicationService() = default; |
| 54 | 38 | ||
| 55 | void CAPS_U::SetShimLibraryVersion(HLERequestContext& ctx) { | 39 | void IAlbumApplicationService::SetShimLibraryVersion(HLERequestContext& ctx) { |
| 56 | IPC::RequestParser rp{ctx}; | 40 | IPC::RequestParser rp{ctx}; |
| 57 | const auto library_version{rp.Pop<u64>()}; | 41 | const auto library_version{rp.Pop<u64>()}; |
| 58 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 42 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| @@ -64,10 +48,7 @@ void CAPS_U::SetShimLibraryVersion(HLERequestContext& ctx) { | |||
| 64 | rb.Push(ResultSuccess); | 48 | rb.Push(ResultSuccess); |
| 65 | } | 49 | } |
| 66 | 50 | ||
| 67 | void CAPS_U::GetAlbumContentsFileListForApplication(HLERequestContext& ctx) { | 51 | void IAlbumApplicationService::GetAlbumFileList0AafeAruidDeprecated(HLERequestContext& ctx) { |
| 68 | // Takes a type-0x6 output buffer containing an array of ApplicationAlbumFileEntry, a PID, an | ||
| 69 | // u8 ContentType, two s64s, and an u64 AppletResourceUserId. Returns an output u64 for total | ||
| 70 | // output entries (which is copied to a s32 by official SW). | ||
| 71 | IPC::RequestParser rp{ctx}; | 52 | IPC::RequestParser rp{ctx}; |
| 72 | const auto pid{rp.Pop<s32>()}; | 53 | const auto pid{rp.Pop<s32>()}; |
| 73 | const auto content_type{rp.PopEnum<ContentType>()}; | 54 | const auto content_type{rp.PopEnum<ContentType>()}; |
| @@ -75,26 +56,49 @@ void CAPS_U::GetAlbumContentsFileListForApplication(HLERequestContext& ctx) { | |||
| 75 | const auto end_posix_time{rp.Pop<s64>()}; | 56 | const auto end_posix_time{rp.Pop<s64>()}; |
| 76 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 57 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 77 | 58 | ||
| 78 | // TODO: Update this when we implement the album. | 59 | LOG_WARNING(Service_Capture, |
| 79 | // Currently we do not have a method of accessing album entries, set this to 0 for now. | 60 | "(STUBBED) called. pid={}, content_type={}, start_posix_time={}, " |
| 80 | constexpr u32 total_entries_1{}; | 61 | "end_posix_time={}, applet_resource_user_id={}", |
| 81 | constexpr u32 total_entries_2{}; | 62 | pid, content_type, start_posix_time, end_posix_time, applet_resource_user_id); |
| 63 | |||
| 64 | // TODO: Translate posix to DateTime | ||
| 65 | |||
| 66 | std::vector<ApplicationAlbumFileEntry> entries; | ||
| 67 | const Result result = | ||
| 68 | manager->GetAlbumFileList(entries, content_type, {}, {}, applet_resource_user_id); | ||
| 82 | 69 | ||
| 83 | LOG_WARNING( | 70 | if (!entries.empty()) { |
| 84 | Service_Capture, | 71 | ctx.WriteBuffer(entries); |
| 85 | "(STUBBED) called. pid={}, content_type={}, start_posix_time={}, " | 72 | } |
| 86 | "end_posix_time={}, applet_resource_user_id={}, total_entries_1={}, total_entries_2={}", | ||
| 87 | pid, content_type, start_posix_time, end_posix_time, applet_resource_user_id, | ||
| 88 | total_entries_1, total_entries_2); | ||
| 89 | 73 | ||
| 90 | IPC::ResponseBuilder rb{ctx, 4}; | 74 | IPC::ResponseBuilder rb{ctx, 4}; |
| 91 | rb.Push(ResultSuccess); | 75 | rb.Push(result); |
| 92 | rb.Push(total_entries_1); | 76 | rb.Push<u64>(entries.size()); |
| 93 | rb.Push(total_entries_2); | ||
| 94 | } | 77 | } |
| 95 | 78 | ||
| 96 | void CAPS_U::GetAlbumFileList3AaeAruid(HLERequestContext& ctx) { | 79 | void IAlbumApplicationService::GetAlbumFileList3AaeAruid(HLERequestContext& ctx) { |
| 97 | GetAlbumContentsFileListForApplication(ctx); | 80 | IPC::RequestParser rp{ctx}; |
| 81 | const auto pid{rp.Pop<s32>()}; | ||
| 82 | const auto content_type{rp.PopEnum<ContentType>()}; | ||
| 83 | const auto start_date_time{rp.PopRaw<AlbumFileDateTime>()}; | ||
| 84 | const auto end_date_time{rp.PopRaw<AlbumFileDateTime>()}; | ||
| 85 | const auto applet_resource_user_id{rp.Pop<u64>()}; | ||
| 86 | |||
| 87 | LOG_WARNING(Service_Capture, | ||
| 88 | "(STUBBED) called. pid={}, content_type={}, applet_resource_user_id={}", pid, | ||
| 89 | content_type, applet_resource_user_id); | ||
| 90 | |||
| 91 | std::vector<ApplicationAlbumFileEntry> entries; | ||
| 92 | const Result result = manager->GetAlbumFileList(entries, content_type, start_date_time, | ||
| 93 | end_date_time, applet_resource_user_id); | ||
| 94 | |||
| 95 | if (!entries.empty()) { | ||
| 96 | ctx.WriteBuffer(entries); | ||
| 97 | } | ||
| 98 | |||
| 99 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 100 | rb.Push(result); | ||
| 101 | rb.Push<u64>(entries.size()); | ||
| 98 | } | 102 | } |
| 99 | 103 | ||
| 100 | } // namespace Service::Capture | 104 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/caps/caps_u.h b/src/core/hle/service/caps/caps_u.h index e8dd037d7..9458c128e 100644 --- a/src/core/hle/service/caps/caps_u.h +++ b/src/core/hle/service/caps/caps_u.h | |||
| @@ -10,16 +10,20 @@ class System; | |||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | namespace Service::Capture { | 12 | namespace Service::Capture { |
| 13 | class AlbumManager; | ||
| 13 | 14 | ||
| 14 | class CAPS_U final : public ServiceFramework<CAPS_U> { | 15 | class IAlbumApplicationService final : public ServiceFramework<IAlbumApplicationService> { |
| 15 | public: | 16 | public: |
| 16 | explicit CAPS_U(Core::System& system_); | 17 | explicit IAlbumApplicationService(Core::System& system_, |
| 17 | ~CAPS_U() override; | 18 | std::shared_ptr<AlbumManager> album_manager); |
| 19 | ~IAlbumApplicationService() override; | ||
| 18 | 20 | ||
| 19 | private: | 21 | private: |
| 20 | void SetShimLibraryVersion(HLERequestContext& ctx); | 22 | void SetShimLibraryVersion(HLERequestContext& ctx); |
| 21 | void GetAlbumContentsFileListForApplication(HLERequestContext& ctx); | 23 | void GetAlbumFileList0AafeAruidDeprecated(HLERequestContext& ctx); |
| 22 | void GetAlbumFileList3AaeAruid(HLERequestContext& ctx); | 24 | void GetAlbumFileList3AaeAruid(HLERequestContext& ctx); |
| 25 | |||
| 26 | std::shared_ptr<AlbumManager> manager = nullptr; | ||
| 23 | }; | 27 | }; |
| 24 | 28 | ||
| 25 | } // namespace Service::Capture | 29 | } // namespace Service::Capture |
diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 21b06d10b..22dc55a6d 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp | |||
| @@ -545,6 +545,16 @@ void IGeneralService::IsAnyInternetRequestAccepted(HLERequestContext& ctx) { | |||
| 545 | } | 545 | } |
| 546 | } | 546 | } |
| 547 | 547 | ||
| 548 | void IGeneralService::IsAnyForegroundRequestAccepted(HLERequestContext& ctx) { | ||
| 549 | const bool is_accepted{}; | ||
| 550 | |||
| 551 | LOG_WARNING(Service_NIFM, "(STUBBED) called, is_accepted={}", is_accepted); | ||
| 552 | |||
| 553 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 554 | rb.Push(ResultSuccess); | ||
| 555 | rb.Push<u8>(is_accepted); | ||
| 556 | } | ||
| 557 | |||
| 548 | IGeneralService::IGeneralService(Core::System& system_) | 558 | IGeneralService::IGeneralService(Core::System& system_) |
| 549 | : ServiceFramework{system_, "IGeneralService"}, network{system_.GetRoomNetwork()} { | 559 | : ServiceFramework{system_, "IGeneralService"}, network{system_.GetRoomNetwork()} { |
| 550 | // clang-format off | 560 | // clang-format off |
| @@ -569,7 +579,7 @@ IGeneralService::IGeneralService(Core::System& system_) | |||
| 569 | {19, nullptr, "SetEthernetCommunicationEnabled"}, | 579 | {19, nullptr, "SetEthernetCommunicationEnabled"}, |
| 570 | {20, &IGeneralService::IsEthernetCommunicationEnabled, "IsEthernetCommunicationEnabled"}, | 580 | {20, &IGeneralService::IsEthernetCommunicationEnabled, "IsEthernetCommunicationEnabled"}, |
| 571 | {21, &IGeneralService::IsAnyInternetRequestAccepted, "IsAnyInternetRequestAccepted"}, | 581 | {21, &IGeneralService::IsAnyInternetRequestAccepted, "IsAnyInternetRequestAccepted"}, |
| 572 | {22, nullptr, "IsAnyForegroundRequestAccepted"}, | 582 | {22, &IGeneralService::IsAnyForegroundRequestAccepted, "IsAnyForegroundRequestAccepted"}, |
| 573 | {23, nullptr, "PutToSleep"}, | 583 | {23, nullptr, "PutToSleep"}, |
| 574 | {24, nullptr, "WakeUp"}, | 584 | {24, nullptr, "WakeUp"}, |
| 575 | {25, nullptr, "GetSsidListVersion"}, | 585 | {25, nullptr, "GetSsidListVersion"}, |
diff --git a/src/core/hle/service/nifm/nifm.h b/src/core/hle/service/nifm/nifm.h index ae99c4695..b74b66438 100644 --- a/src/core/hle/service/nifm/nifm.h +++ b/src/core/hle/service/nifm/nifm.h | |||
| @@ -35,6 +35,7 @@ private: | |||
| 35 | void GetInternetConnectionStatus(HLERequestContext& ctx); | 35 | void GetInternetConnectionStatus(HLERequestContext& ctx); |
| 36 | void IsEthernetCommunicationEnabled(HLERequestContext& ctx); | 36 | void IsEthernetCommunicationEnabled(HLERequestContext& ctx); |
| 37 | void IsAnyInternetRequestAccepted(HLERequestContext& ctx); | 37 | void IsAnyInternetRequestAccepted(HLERequestContext& ctx); |
| 38 | void IsAnyForegroundRequestAccepted(HLERequestContext& ctx); | ||
| 38 | 39 | ||
| 39 | Network::RoomNetwork& network; | 40 | Network::RoomNetwork& network; |
| 40 | }; | 41 | }; |
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 6e0baf0be..f9e0e272d 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "core/file_sys/control_metadata.h" | 7 | #include "core/file_sys/control_metadata.h" |
| 8 | #include "core/file_sys/patch_manager.h" | 8 | #include "core/file_sys/patch_manager.h" |
| 9 | #include "core/file_sys/vfs.h" | 9 | #include "core/file_sys/vfs.h" |
| 10 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 10 | #include "core/hle/service/glue/glue_manager.h" | 11 | #include "core/hle/service/glue/glue_manager.h" |
| 11 | #include "core/hle/service/ipc_helpers.h" | 12 | #include "core/hle/service/ipc_helpers.h" |
| 12 | #include "core/hle/service/ns/errors.h" | 13 | #include "core/hle/service/ns/errors.h" |
| @@ -502,8 +503,8 @@ IContentManagementInterface::IContentManagementInterface(Core::System& system_) | |||
| 502 | static const FunctionInfo functions[] = { | 503 | static const FunctionInfo functions[] = { |
| 503 | {11, nullptr, "CalculateApplicationOccupiedSize"}, | 504 | {11, nullptr, "CalculateApplicationOccupiedSize"}, |
| 504 | {43, nullptr, "CheckSdCardMountStatus"}, | 505 | {43, nullptr, "CheckSdCardMountStatus"}, |
| 505 | {47, nullptr, "GetTotalSpaceSize"}, | 506 | {47, &IContentManagementInterface::GetTotalSpaceSize, "GetTotalSpaceSize"}, |
| 506 | {48, nullptr, "GetFreeSpaceSize"}, | 507 | {48, &IContentManagementInterface::GetFreeSpaceSize, "GetFreeSpaceSize"}, |
| 507 | {600, nullptr, "CountApplicationContentMeta"}, | 508 | {600, nullptr, "CountApplicationContentMeta"}, |
| 508 | {601, nullptr, "ListApplicationContentMetaStatus"}, | 509 | {601, nullptr, "ListApplicationContentMetaStatus"}, |
| 509 | {605, nullptr, "ListApplicationContentMetaStatusWithRightsCheck"}, | 510 | {605, nullptr, "ListApplicationContentMetaStatusWithRightsCheck"}, |
| @@ -516,6 +517,28 @@ IContentManagementInterface::IContentManagementInterface(Core::System& system_) | |||
| 516 | 517 | ||
| 517 | IContentManagementInterface::~IContentManagementInterface() = default; | 518 | IContentManagementInterface::~IContentManagementInterface() = default; |
| 518 | 519 | ||
| 520 | void IContentManagementInterface::GetTotalSpaceSize(HLERequestContext& ctx) { | ||
| 521 | IPC::RequestParser rp{ctx}; | ||
| 522 | const auto storage{rp.PopEnum<FileSys::StorageId>()}; | ||
| 523 | |||
| 524 | LOG_INFO(Service_Capture, "called, storage={}", storage); | ||
| 525 | |||
| 526 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 527 | rb.Push(ResultSuccess); | ||
| 528 | rb.Push<u64>(system.GetFileSystemController().GetTotalSpaceSize(storage)); | ||
| 529 | } | ||
| 530 | |||
| 531 | void IContentManagementInterface::GetFreeSpaceSize(HLERequestContext& ctx) { | ||
| 532 | IPC::RequestParser rp{ctx}; | ||
| 533 | const auto storage{rp.PopEnum<FileSys::StorageId>()}; | ||
| 534 | |||
| 535 | LOG_INFO(Service_Capture, "called, storage={}", storage); | ||
| 536 | |||
| 537 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 538 | rb.Push(ResultSuccess); | ||
| 539 | rb.Push<u64>(system.GetFileSystemController().GetFreeSpaceSize(storage)); | ||
| 540 | } | ||
| 541 | |||
| 519 | IDocumentInterface::IDocumentInterface(Core::System& system_) | 542 | IDocumentInterface::IDocumentInterface(Core::System& system_) |
| 520 | : ServiceFramework{system_, "IDocumentInterface"} { | 543 | : ServiceFramework{system_, "IDocumentInterface"} { |
| 521 | // clang-format off | 544 | // clang-format off |
diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index 175dad780..34d2a45dc 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h | |||
| @@ -48,6 +48,10 @@ class IContentManagementInterface final : public ServiceFramework<IContentManage | |||
| 48 | public: | 48 | public: |
| 49 | explicit IContentManagementInterface(Core::System& system_); | 49 | explicit IContentManagementInterface(Core::System& system_); |
| 50 | ~IContentManagementInterface() override; | 50 | ~IContentManagementInterface() override; |
| 51 | |||
| 52 | private: | ||
| 53 | void GetTotalSpaceSize(HLERequestContext& ctx); | ||
| 54 | void GetFreeSpaceSize(HLERequestContext& ctx); | ||
| 51 | }; | 55 | }; |
| 52 | 56 | ||
| 53 | class IDocumentInterface final : public ServiceFramework<IDocumentInterface> { | 57 | class IDocumentInterface final : public ServiceFramework<IDocumentInterface> { |
diff --git a/src/core/hle/service/pctl/pctl_module.cpp b/src/core/hle/service/pctl/pctl_module.cpp index 5db1703d1..938330dd0 100644 --- a/src/core/hle/service/pctl/pctl_module.cpp +++ b/src/core/hle/service/pctl/pctl_module.cpp | |||
| @@ -33,7 +33,7 @@ public: | |||
| 33 | {1001, &IParentalControlService::CheckFreeCommunicationPermission, "CheckFreeCommunicationPermission"}, | 33 | {1001, &IParentalControlService::CheckFreeCommunicationPermission, "CheckFreeCommunicationPermission"}, |
| 34 | {1002, nullptr, "ConfirmLaunchApplicationPermission"}, | 34 | {1002, nullptr, "ConfirmLaunchApplicationPermission"}, |
| 35 | {1003, nullptr, "ConfirmResumeApplicationPermission"}, | 35 | {1003, nullptr, "ConfirmResumeApplicationPermission"}, |
| 36 | {1004, nullptr, "ConfirmSnsPostPermission"}, | 36 | {1004, &IParentalControlService::ConfirmSnsPostPermission, "ConfirmSnsPostPermission"}, |
| 37 | {1005, nullptr, "ConfirmSystemSettingsPermission"}, | 37 | {1005, nullptr, "ConfirmSystemSettingsPermission"}, |
| 38 | {1006, &IParentalControlService::IsRestrictionTemporaryUnlocked, "IsRestrictionTemporaryUnlocked"}, | 38 | {1006, &IParentalControlService::IsRestrictionTemporaryUnlocked, "IsRestrictionTemporaryUnlocked"}, |
| 39 | {1007, nullptr, "RevertRestrictionTemporaryUnlocked"}, | 39 | {1007, nullptr, "RevertRestrictionTemporaryUnlocked"}, |
| @@ -236,6 +236,13 @@ private: | |||
| 236 | states.free_communication = true; | 236 | states.free_communication = true; |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | void ConfirmSnsPostPermission(HLERequestContext& ctx) { | ||
| 240 | LOG_WARNING(Service_PCTL, "(STUBBED) called"); | ||
| 241 | |||
| 242 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 243 | rb.Push(Error::ResultNoFreeCommunication); | ||
| 244 | } | ||
| 245 | |||
| 239 | void IsRestrictionTemporaryUnlocked(HLERequestContext& ctx) { | 246 | void IsRestrictionTemporaryUnlocked(HLERequestContext& ctx) { |
| 240 | const bool is_temporary_unlocked = false; | 247 | const bool is_temporary_unlocked = false; |
| 241 | 248 | ||
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 9e90c587c..9b2698fad 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -544,7 +544,7 @@ void BufferCache<P>::CommitAsyncFlushesHigh() { | |||
| 544 | it++; | 544 | it++; |
| 545 | } | 545 | } |
| 546 | 546 | ||
| 547 | boost::container::small_vector<std::pair<BufferCopy, BufferId>, 1> downloads; | 547 | boost::container::small_vector<std::pair<BufferCopy, BufferId>, 16> downloads; |
| 548 | u64 total_size_bytes = 0; | 548 | u64 total_size_bytes = 0; |
| 549 | u64 largest_copy = 0; | 549 | u64 largest_copy = 0; |
| 550 | for (const IntervalSet& intervals : committed_ranges) { | 550 | for (const IntervalSet& intervals : committed_ranges) { |
| @@ -914,6 +914,11 @@ void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) { | |||
| 914 | 914 | ||
| 915 | const u32 offset = buffer.Offset(binding.cpu_addr); | 915 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 916 | const bool is_written = ((channel_state->written_storage_buffers[stage] >> index) & 1) != 0; | 916 | const bool is_written = ((channel_state->written_storage_buffers[stage] >> index) & 1) != 0; |
| 917 | |||
| 918 | if (is_written) { | ||
| 919 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, size); | ||
| 920 | } | ||
| 921 | |||
| 917 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { | 922 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { |
| 918 | runtime.BindStorageBuffer(stage, binding_index, buffer, offset, size, is_written); | 923 | runtime.BindStorageBuffer(stage, binding_index, buffer, offset, size, is_written); |
| 919 | ++binding_index; | 924 | ++binding_index; |
| @@ -931,6 +936,11 @@ void BufferCache<P>::BindHostGraphicsTextureBuffers(size_t stage) { | |||
| 931 | const u32 size = binding.size; | 936 | const u32 size = binding.size; |
| 932 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 937 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 933 | 938 | ||
| 939 | const bool is_written = ((channel_state->written_texture_buffers[stage] >> index) & 1) != 0; | ||
| 940 | if (is_written) { | ||
| 941 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, size); | ||
| 942 | } | ||
| 943 | |||
| 934 | const u32 offset = buffer.Offset(binding.cpu_addr); | 944 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 935 | const PixelFormat format = binding.format; | 945 | const PixelFormat format = binding.format; |
| 936 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { | 946 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { |
| @@ -962,6 +972,8 @@ void BufferCache<P>::BindHostTransformFeedbackBuffers() { | |||
| 962 | const u32 size = binding.size; | 972 | const u32 size = binding.size; |
| 963 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 973 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 964 | 974 | ||
| 975 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, size); | ||
| 976 | |||
| 965 | const u32 offset = buffer.Offset(binding.cpu_addr); | 977 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 966 | host_bindings.buffers.push_back(&buffer); | 978 | host_bindings.buffers.push_back(&buffer); |
| 967 | host_bindings.offsets.push_back(offset); | 979 | host_bindings.offsets.push_back(offset); |
| @@ -1011,6 +1023,11 @@ void BufferCache<P>::BindHostComputeStorageBuffers() { | |||
| 1011 | const u32 offset = buffer.Offset(binding.cpu_addr); | 1023 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 1012 | const bool is_written = | 1024 | const bool is_written = |
| 1013 | ((channel_state->written_compute_storage_buffers >> index) & 1) != 0; | 1025 | ((channel_state->written_compute_storage_buffers >> index) & 1) != 0; |
| 1026 | |||
| 1027 | if (is_written) { | ||
| 1028 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, size); | ||
| 1029 | } | ||
| 1030 | |||
| 1014 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { | 1031 | if constexpr (NEEDS_BIND_STORAGE_INDEX) { |
| 1015 | runtime.BindComputeStorageBuffer(binding_index, buffer, offset, size, is_written); | 1032 | runtime.BindComputeStorageBuffer(binding_index, buffer, offset, size, is_written); |
| 1016 | ++binding_index; | 1033 | ++binding_index; |
| @@ -1028,6 +1045,12 @@ void BufferCache<P>::BindHostComputeTextureBuffers() { | |||
| 1028 | const u32 size = binding.size; | 1045 | const u32 size = binding.size; |
| 1029 | SynchronizeBuffer(buffer, binding.cpu_addr, size); | 1046 | SynchronizeBuffer(buffer, binding.cpu_addr, size); |
| 1030 | 1047 | ||
| 1048 | const bool is_written = | ||
| 1049 | ((channel_state->written_compute_texture_buffers >> index) & 1) != 0; | ||
| 1050 | if (is_written) { | ||
| 1051 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, size); | ||
| 1052 | } | ||
| 1053 | |||
| 1031 | const u32 offset = buffer.Offset(binding.cpu_addr); | 1054 | const u32 offset = buffer.Offset(binding.cpu_addr); |
| 1032 | const PixelFormat format = binding.format; | 1055 | const PixelFormat format = binding.format; |
| 1033 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { | 1056 | if constexpr (SEPARATE_IMAGE_BUFFERS_BINDINGS) { |
| @@ -1201,16 +1224,11 @@ void BufferCache<P>::UpdateUniformBuffers(size_t stage) { | |||
| 1201 | 1224 | ||
| 1202 | template <class P> | 1225 | template <class P> |
| 1203 | void BufferCache<P>::UpdateStorageBuffers(size_t stage) { | 1226 | void BufferCache<P>::UpdateStorageBuffers(size_t stage) { |
| 1204 | const u32 written_mask = channel_state->written_storage_buffers[stage]; | ||
| 1205 | ForEachEnabledBit(channel_state->enabled_storage_buffers[stage], [&](u32 index) { | 1227 | ForEachEnabledBit(channel_state->enabled_storage_buffers[stage], [&](u32 index) { |
| 1206 | // Resolve buffer | 1228 | // Resolve buffer |
| 1207 | Binding& binding = channel_state->storage_buffers[stage][index]; | 1229 | Binding& binding = channel_state->storage_buffers[stage][index]; |
| 1208 | const BufferId buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1230 | const BufferId buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1209 | binding.buffer_id = buffer_id; | 1231 | binding.buffer_id = buffer_id; |
| 1210 | // Mark buffer as written if needed | ||
| 1211 | if (((written_mask >> index) & 1) != 0) { | ||
| 1212 | MarkWrittenBuffer(buffer_id, binding.cpu_addr, binding.size); | ||
| 1213 | } | ||
| 1214 | }); | 1232 | }); |
| 1215 | } | 1233 | } |
| 1216 | 1234 | ||
| @@ -1219,10 +1237,6 @@ void BufferCache<P>::UpdateTextureBuffers(size_t stage) { | |||
| 1219 | ForEachEnabledBit(channel_state->enabled_texture_buffers[stage], [&](u32 index) { | 1237 | ForEachEnabledBit(channel_state->enabled_texture_buffers[stage], [&](u32 index) { |
| 1220 | Binding& binding = channel_state->texture_buffers[stage][index]; | 1238 | Binding& binding = channel_state->texture_buffers[stage][index]; |
| 1221 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1239 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1222 | // Mark buffer as written if needed | ||
| 1223 | if (((channel_state->written_texture_buffers[stage] >> index) & 1) != 0) { | ||
| 1224 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); | ||
| 1225 | } | ||
| 1226 | }); | 1240 | }); |
| 1227 | } | 1241 | } |
| 1228 | 1242 | ||
| @@ -1252,7 +1266,6 @@ void BufferCache<P>::UpdateTransformFeedbackBuffer(u32 index) { | |||
| 1252 | .size = size, | 1266 | .size = size, |
| 1253 | .buffer_id = buffer_id, | 1267 | .buffer_id = buffer_id, |
| 1254 | }; | 1268 | }; |
| 1255 | MarkWrittenBuffer(buffer_id, *cpu_addr, size); | ||
| 1256 | } | 1269 | } |
| 1257 | 1270 | ||
| 1258 | template <class P> | 1271 | template <class P> |
| @@ -1279,10 +1292,6 @@ void BufferCache<P>::UpdateComputeStorageBuffers() { | |||
| 1279 | // Resolve buffer | 1292 | // Resolve buffer |
| 1280 | Binding& binding = channel_state->compute_storage_buffers[index]; | 1293 | Binding& binding = channel_state->compute_storage_buffers[index]; |
| 1281 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1294 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1282 | // Mark as written if needed | ||
| 1283 | if (((channel_state->written_compute_storage_buffers >> index) & 1) != 0) { | ||
| 1284 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); | ||
| 1285 | } | ||
| 1286 | }); | 1295 | }); |
| 1287 | } | 1296 | } |
| 1288 | 1297 | ||
| @@ -1291,18 +1300,11 @@ void BufferCache<P>::UpdateComputeTextureBuffers() { | |||
| 1291 | ForEachEnabledBit(channel_state->enabled_compute_texture_buffers, [&](u32 index) { | 1300 | ForEachEnabledBit(channel_state->enabled_compute_texture_buffers, [&](u32 index) { |
| 1292 | Binding& binding = channel_state->compute_texture_buffers[index]; | 1301 | Binding& binding = channel_state->compute_texture_buffers[index]; |
| 1293 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); | 1302 | binding.buffer_id = FindBuffer(binding.cpu_addr, binding.size); |
| 1294 | // Mark as written if needed | ||
| 1295 | if (((channel_state->written_compute_texture_buffers >> index) & 1) != 0) { | ||
| 1296 | MarkWrittenBuffer(binding.buffer_id, binding.cpu_addr, binding.size); | ||
| 1297 | } | ||
| 1298 | }); | 1303 | }); |
| 1299 | } | 1304 | } |
| 1300 | 1305 | ||
| 1301 | template <class P> | 1306 | template <class P> |
| 1302 | void BufferCache<P>::MarkWrittenBuffer(BufferId buffer_id, VAddr cpu_addr, u32 size) { | 1307 | void BufferCache<P>::MarkWrittenBuffer(BufferId buffer_id, VAddr cpu_addr, u32 size) { |
| 1303 | if (memory_tracker.IsRegionCpuModified(cpu_addr, size)) { | ||
| 1304 | SynchronizeBuffer(slot_buffers[buffer_id], cpu_addr, size); | ||
| 1305 | } | ||
| 1306 | memory_tracker.MarkRegionAsGpuModified(cpu_addr, size); | 1308 | memory_tracker.MarkRegionAsGpuModified(cpu_addr, size); |
| 1307 | 1309 | ||
| 1308 | const IntervalType base_interval{cpu_addr, cpu_addr + size}; | 1310 | const IntervalType base_interval{cpu_addr, cpu_addr + size}; |
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index 0a86ce139..8151cabf0 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp | |||
| @@ -68,6 +68,7 @@ struct LevelInfo { | |||
| 68 | Extent2D tile_size; | 68 | Extent2D tile_size; |
| 69 | u32 bpp_log2; | 69 | u32 bpp_log2; |
| 70 | u32 tile_width_spacing; | 70 | u32 tile_width_spacing; |
| 71 | u32 num_levels; | ||
| 71 | }; | 72 | }; |
| 72 | 73 | ||
| 73 | [[nodiscard]] constexpr u32 AdjustTileSize(u32 shift, u32 unit_factor, u32 dimension) { | 74 | [[nodiscard]] constexpr u32 AdjustTileSize(u32 shift, u32 unit_factor, u32 dimension) { |
| @@ -118,11 +119,11 @@ template <u32 GOB_EXTENT> | |||
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | [[nodiscard]] constexpr Extent3D AdjustMipBlockSize(Extent3D num_tiles, Extent3D block_size, | 121 | [[nodiscard]] constexpr Extent3D AdjustMipBlockSize(Extent3D num_tiles, Extent3D block_size, |
| 121 | u32 level) { | 122 | u32 level, u32 num_levels) { |
| 122 | return { | 123 | return { |
| 123 | .width = AdjustMipBlockSize<GOB_SIZE_X>(num_tiles.width, block_size.width, level), | 124 | .width = AdjustMipBlockSize<GOB_SIZE_X>(num_tiles.width, block_size.width, level), |
| 124 | .height = AdjustMipBlockSize<GOB_SIZE_Y>(num_tiles.height, block_size.height, level), | 125 | .height = AdjustMipBlockSize<GOB_SIZE_Y>(num_tiles.height, block_size.height, level), |
| 125 | .depth = level == 0 | 126 | .depth = level == 0 && num_levels == 1 |
| 126 | ? block_size.depth | 127 | ? block_size.depth |
| 127 | : AdjustMipBlockSize<GOB_SIZE_Z>(num_tiles.depth, block_size.depth, level), | 128 | : AdjustMipBlockSize<GOB_SIZE_Z>(num_tiles.depth, block_size.depth, level), |
| 128 | }; | 129 | }; |
| @@ -166,13 +167,6 @@ template <u32 GOB_EXTENT> | |||
| 166 | } | 167 | } |
| 167 | 168 | ||
| 168 | [[nodiscard]] constexpr Extent3D TileShift(const LevelInfo& info, u32 level) { | 169 | [[nodiscard]] constexpr Extent3D TileShift(const LevelInfo& info, u32 level) { |
| 169 | if (level == 0) { | ||
| 170 | return Extent3D{ | ||
| 171 | .width = info.block.width, | ||
| 172 | .height = info.block.height, | ||
| 173 | .depth = info.block.depth, | ||
| 174 | }; | ||
| 175 | } | ||
| 176 | const Extent3D blocks = NumLevelBlocks(info, level); | 170 | const Extent3D blocks = NumLevelBlocks(info, level); |
| 177 | return Extent3D{ | 171 | return Extent3D{ |
| 178 | .width = AdjustTileSize(info.block.width, GOB_SIZE_X, blocks.width), | 172 | .width = AdjustTileSize(info.block.width, GOB_SIZE_X, blocks.width), |
| @@ -257,7 +251,7 @@ template <u32 GOB_EXTENT> | |||
| 257 | } | 251 | } |
| 258 | 252 | ||
| 259 | [[nodiscard]] constexpr LevelInfo MakeLevelInfo(PixelFormat format, Extent3D size, Extent3D block, | 253 | [[nodiscard]] constexpr LevelInfo MakeLevelInfo(PixelFormat format, Extent3D size, Extent3D block, |
| 260 | u32 tile_width_spacing) { | 254 | u32 tile_width_spacing, u32 num_levels) { |
| 261 | const u32 bytes_per_block = BytesPerBlock(format); | 255 | const u32 bytes_per_block = BytesPerBlock(format); |
| 262 | return { | 256 | return { |
| 263 | .size = | 257 | .size = |
| @@ -270,16 +264,18 @@ template <u32 GOB_EXTENT> | |||
| 270 | .tile_size = DefaultBlockSize(format), | 264 | .tile_size = DefaultBlockSize(format), |
| 271 | .bpp_log2 = BytesPerBlockLog2(bytes_per_block), | 265 | .bpp_log2 = BytesPerBlockLog2(bytes_per_block), |
| 272 | .tile_width_spacing = tile_width_spacing, | 266 | .tile_width_spacing = tile_width_spacing, |
| 267 | .num_levels = num_levels, | ||
| 273 | }; | 268 | }; |
| 274 | } | 269 | } |
| 275 | 270 | ||
| 276 | [[nodiscard]] constexpr LevelInfo MakeLevelInfo(const ImageInfo& info) { | 271 | [[nodiscard]] constexpr LevelInfo MakeLevelInfo(const ImageInfo& info) { |
| 277 | return MakeLevelInfo(info.format, info.size, info.block, info.tile_width_spacing); | 272 | return MakeLevelInfo(info.format, info.size, info.block, info.tile_width_spacing, |
| 273 | info.resources.levels); | ||
| 278 | } | 274 | } |
| 279 | 275 | ||
| 280 | [[nodiscard]] constexpr u32 CalculateLevelOffset(PixelFormat format, Extent3D size, Extent3D block, | 276 | [[nodiscard]] constexpr u32 CalculateLevelOffset(PixelFormat format, Extent3D size, Extent3D block, |
| 281 | u32 tile_width_spacing, u32 level) { | 277 | u32 tile_width_spacing, u32 level) { |
| 282 | const LevelInfo info = MakeLevelInfo(format, size, block, tile_width_spacing); | 278 | const LevelInfo info = MakeLevelInfo(format, size, block, tile_width_spacing, level); |
| 283 | u32 offset = 0; | 279 | u32 offset = 0; |
| 284 | for (u32 current_level = 0; current_level < level; ++current_level) { | 280 | for (u32 current_level = 0; current_level < level; ++current_level) { |
| 285 | offset += CalculateLevelSize(info, current_level); | 281 | offset += CalculateLevelSize(info, current_level); |
| @@ -466,7 +462,7 @@ template <u32 GOB_EXTENT> | |||
| 466 | }; | 462 | }; |
| 467 | const u32 bpp_log2 = BytesPerBlockLog2(info.format); | 463 | const u32 bpp_log2 = BytesPerBlockLog2(info.format); |
| 468 | const u32 alignment = StrideAlignment(num_tiles, info.block, bpp_log2, info.tile_width_spacing); | 464 | const u32 alignment = StrideAlignment(num_tiles, info.block, bpp_log2, info.tile_width_spacing); |
| 469 | const Extent3D mip_block = AdjustMipBlockSize(num_tiles, info.block, 0); | 465 | const Extent3D mip_block = AdjustMipBlockSize(num_tiles, info.block, 0, info.resources.levels); |
| 470 | return Extent3D{ | 466 | return Extent3D{ |
| 471 | .width = Common::AlignUpLog2(num_tiles.width, alignment), | 467 | .width = Common::AlignUpLog2(num_tiles.width, alignment), |
| 472 | .height = Common::AlignUpLog2(num_tiles.height, GOB_SIZE_Y_SHIFT + mip_block.height), | 468 | .height = Common::AlignUpLog2(num_tiles.height, GOB_SIZE_Y_SHIFT + mip_block.height), |
| @@ -533,7 +529,8 @@ void SwizzleBlockLinearImage(Tegra::MemoryManager& gpu_memory, GPUVAddr gpu_addr | |||
| 533 | UNIMPLEMENTED_IF(copy.image_extent != level_size); | 529 | UNIMPLEMENTED_IF(copy.image_extent != level_size); |
| 534 | 530 | ||
| 535 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); | 531 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); |
| 536 | const Extent3D block = AdjustMipBlockSize(num_tiles, level_info.block, level); | 532 | const Extent3D block = |
| 533 | AdjustMipBlockSize(num_tiles, level_info.block, level, level_info.num_levels); | ||
| 537 | 534 | ||
| 538 | size_t host_offset = copy.buffer_offset; | 535 | size_t host_offset = copy.buffer_offset; |
| 539 | 536 | ||
| @@ -698,7 +695,7 @@ u32 CalculateLevelStrideAlignment(const ImageInfo& info, u32 level) { | |||
| 698 | const Extent2D tile_size = DefaultBlockSize(info.format); | 695 | const Extent2D tile_size = DefaultBlockSize(info.format); |
| 699 | const Extent3D level_size = AdjustMipSize(info.size, level); | 696 | const Extent3D level_size = AdjustMipSize(info.size, level); |
| 700 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); | 697 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); |
| 701 | const Extent3D block = AdjustMipBlockSize(num_tiles, info.block, level); | 698 | const Extent3D block = AdjustMipBlockSize(num_tiles, info.block, level, info.resources.levels); |
| 702 | const u32 bpp_log2 = BytesPerBlockLog2(info.format); | 699 | const u32 bpp_log2 = BytesPerBlockLog2(info.format); |
| 703 | return StrideAlignment(num_tiles, block, bpp_log2, info.tile_width_spacing); | 700 | return StrideAlignment(num_tiles, block, bpp_log2, info.tile_width_spacing); |
| 704 | } | 701 | } |
| @@ -887,7 +884,8 @@ boost::container::small_vector<BufferImageCopy, 16> UnswizzleImage(Tegra::Memory | |||
| 887 | .image_extent = level_size, | 884 | .image_extent = level_size, |
| 888 | }; | 885 | }; |
| 889 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); | 886 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); |
| 890 | const Extent3D block = AdjustMipBlockSize(num_tiles, level_info.block, level); | 887 | const Extent3D block = |
| 888 | AdjustMipBlockSize(num_tiles, level_info.block, level, level_info.num_levels); | ||
| 891 | const u32 stride_alignment = StrideAlignment(num_tiles, info.block, gob, bpp_log2); | 889 | const u32 stride_alignment = StrideAlignment(num_tiles, info.block, gob, bpp_log2); |
| 892 | size_t guest_layer_offset = 0; | 890 | size_t guest_layer_offset = 0; |
| 893 | 891 | ||
| @@ -1041,7 +1039,7 @@ Extent3D MipBlockSize(const ImageInfo& info, u32 level) { | |||
| 1041 | const Extent2D tile_size = DefaultBlockSize(info.format); | 1039 | const Extent2D tile_size = DefaultBlockSize(info.format); |
| 1042 | const Extent3D level_size = AdjustMipSize(info.size, level); | 1040 | const Extent3D level_size = AdjustMipSize(info.size, level); |
| 1043 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); | 1041 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); |
| 1044 | return AdjustMipBlockSize(num_tiles, level_info.block, level); | 1042 | return AdjustMipBlockSize(num_tiles, level_info.block, level, level_info.num_levels); |
| 1045 | } | 1043 | } |
| 1046 | 1044 | ||
| 1047 | boost::container::small_vector<SwizzleParameters, 16> FullUploadSwizzles(const ImageInfo& info) { | 1045 | boost::container::small_vector<SwizzleParameters, 16> FullUploadSwizzles(const ImageInfo& info) { |
| @@ -1063,7 +1061,8 @@ boost::container::small_vector<SwizzleParameters, 16> FullUploadSwizzles(const I | |||
| 1063 | for (s32 level = 0; level < num_levels; ++level) { | 1061 | for (s32 level = 0; level < num_levels; ++level) { |
| 1064 | const Extent3D level_size = AdjustMipSize(size, level); | 1062 | const Extent3D level_size = AdjustMipSize(size, level); |
| 1065 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); | 1063 | const Extent3D num_tiles = AdjustTileSize(level_size, tile_size); |
| 1066 | const Extent3D block = AdjustMipBlockSize(num_tiles, level_info.block, level); | 1064 | const Extent3D block = |
| 1065 | AdjustMipBlockSize(num_tiles, level_info.block, level, level_info.num_levels); | ||
| 1067 | params[level] = SwizzleParameters{ | 1066 | params[level] = SwizzleParameters{ |
| 1068 | .num_tiles = num_tiles, | 1067 | .num_tiles = num_tiles, |
| 1069 | .block = block, | 1068 | .block = block, |
| @@ -1292,11 +1291,11 @@ u32 MapSizeBytes(const ImageBase& image) { | |||
| 1292 | } | 1291 | } |
| 1293 | } | 1292 | } |
| 1294 | 1293 | ||
| 1295 | static_assert(CalculateLevelSize(LevelInfo{{1920, 1080, 1}, {0, 2, 0}, {1, 1}, 2, 0}, 0) == | 1294 | static_assert(CalculateLevelSize(LevelInfo{{1920, 1080, 1}, {0, 2, 0}, {1, 1}, 2, 0, 1}, 0) == |
| 1296 | 0x7f8000); | 1295 | 0x7f8000); |
| 1297 | static_assert(CalculateLevelSize(LevelInfo{{32, 32, 1}, {0, 0, 4}, {1, 1}, 4, 0}, 0) == 0x40000); | 1296 | static_assert(CalculateLevelSize(LevelInfo{{32, 32, 1}, {0, 0, 4}, {1, 1}, 4, 0, 1}, 0) == 0x4000); |
| 1298 | 1297 | ||
| 1299 | static_assert(CalculateLevelSize(LevelInfo{{128, 8, 1}, {0, 4, 0}, {1, 1}, 4, 0}, 0) == 0x40000); | 1298 | static_assert(CalculateLevelSize(LevelInfo{{128, 8, 1}, {0, 4, 0}, {1, 1}, 4, 0, 1}, 0) == 0x4000); |
| 1300 | 1299 | ||
| 1301 | static_assert(CalculateLevelOffset(PixelFormat::R8_SINT, {1920, 1080, 1}, {0, 2, 0}, 0, 7) == | 1300 | static_assert(CalculateLevelOffset(PixelFormat::R8_SINT, {1920, 1080, 1}, {0, 2, 0}, 0, 7) == |
| 1302 | 0x2afc00); | 1301 | 0x2afc00); |
diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp index d15559518..ca0e14fad 100644 --- a/src/yuzu/applets/qt_controller.cpp +++ b/src/yuzu/applets/qt_controller.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include "yuzu/configuration/configure_vibration.h" | 23 | #include "yuzu/configuration/configure_vibration.h" |
| 24 | #include "yuzu/configuration/input_profiles.h" | 24 | #include "yuzu/configuration/input_profiles.h" |
| 25 | #include "yuzu/main.h" | 25 | #include "yuzu/main.h" |
| 26 | #include "yuzu/util/controller_navigation.h" | ||
| 26 | 27 | ||
| 27 | namespace { | 28 | namespace { |
| 28 | 29 | ||
| @@ -132,6 +133,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 132 | ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected, | 133 | ui->checkboxPlayer7Connected, ui->checkboxPlayer8Connected, |
| 133 | }; | 134 | }; |
| 134 | 135 | ||
| 136 | ui->labelError->setVisible(false); | ||
| 137 | |||
| 135 | // Setup/load everything prior to setting up connections. | 138 | // Setup/load everything prior to setting up connections. |
| 136 | // This avoids unintentionally changing the states of elements while loading them in. | 139 | // This avoids unintentionally changing the states of elements while loading them in. |
| 137 | SetSupportedControllers(); | 140 | SetSupportedControllers(); |
| @@ -143,6 +146,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 143 | 146 | ||
| 144 | LoadConfiguration(); | 147 | LoadConfiguration(); |
| 145 | 148 | ||
| 149 | controller_navigation = new ControllerNavigation(system.HIDCore(), this); | ||
| 150 | |||
| 146 | for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { | 151 | for (std::size_t i = 0; i < NUM_PLAYERS; ++i) { |
| 147 | SetExplainText(i); | 152 | SetExplainText(i); |
| 148 | UpdateControllerIcon(i); | 153 | UpdateControllerIcon(i); |
| @@ -151,6 +156,8 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 151 | 156 | ||
| 152 | connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) { | 157 | connect(player_groupboxes[i], &QGroupBox::toggled, [this, i](bool checked) { |
| 153 | if (checked) { | 158 | if (checked) { |
| 159 | // Hide eventual error message about number of controllers | ||
| 160 | ui->labelError->setVisible(false); | ||
| 154 | for (std::size_t index = 0; index <= i; ++index) { | 161 | for (std::size_t index = 0; index <= i; ++index) { |
| 155 | connected_controller_checkboxes[index]->setChecked(checked); | 162 | connected_controller_checkboxes[index]->setChecked(checked); |
| 156 | } | 163 | } |
| @@ -199,6 +206,12 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 199 | connect(ui->buttonBox, &QDialogButtonBox::accepted, this, | 206 | connect(ui->buttonBox, &QDialogButtonBox::accepted, this, |
| 200 | &QtControllerSelectorDialog::ApplyConfiguration); | 207 | &QtControllerSelectorDialog::ApplyConfiguration); |
| 201 | 208 | ||
| 209 | connect(controller_navigation, &ControllerNavigation::TriggerKeyboardEvent, | ||
| 210 | [this](Qt::Key key) { | ||
| 211 | QKeyEvent* event = new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier); | ||
| 212 | QCoreApplication::postEvent(this, event); | ||
| 213 | }); | ||
| 214 | |||
| 202 | // Enhancement: Check if the parameters have already been met before disconnecting controllers. | 215 | // Enhancement: Check if the parameters have already been met before disconnecting controllers. |
| 203 | // If all the parameters are met AND only allows a single player, | 216 | // If all the parameters are met AND only allows a single player, |
| 204 | // stop the constructor here as we do not need to continue. | 217 | // stop the constructor here as we do not need to continue. |
| @@ -217,6 +230,7 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( | |||
| 217 | } | 230 | } |
| 218 | 231 | ||
| 219 | QtControllerSelectorDialog::~QtControllerSelectorDialog() { | 232 | QtControllerSelectorDialog::~QtControllerSelectorDialog() { |
| 233 | controller_navigation->UnloadController(); | ||
| 220 | system.HIDCore().DisableAllControllerConfiguration(); | 234 | system.HIDCore().DisableAllControllerConfiguration(); |
| 221 | } | 235 | } |
| 222 | 236 | ||
| @@ -291,6 +305,31 @@ void QtControllerSelectorDialog::CallConfigureInputProfileDialog() { | |||
| 291 | dialog.exec(); | 305 | dialog.exec(); |
| 292 | } | 306 | } |
| 293 | 307 | ||
| 308 | void QtControllerSelectorDialog::keyPressEvent(QKeyEvent* evt) { | ||
| 309 | const auto num_connected_players = static_cast<int>( | ||
| 310 | std::count_if(player_groupboxes.begin(), player_groupboxes.end(), | ||
| 311 | [](const QGroupBox* player) { return player->isChecked(); })); | ||
| 312 | |||
| 313 | const auto min_supported_players = parameters.enable_single_mode ? 1 : parameters.min_players; | ||
| 314 | const auto max_supported_players = parameters.enable_single_mode ? 1 : parameters.max_players; | ||
| 315 | |||
| 316 | if ((evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) && !parameters_met) { | ||
| 317 | // Display error message when trying to validate using "Enter" and "OK" button is disabled | ||
| 318 | ui->labelError->setVisible(true); | ||
| 319 | return; | ||
| 320 | } else if (evt->key() == Qt::Key_Left && num_connected_players > min_supported_players) { | ||
| 321 | // Remove a player if possible | ||
| 322 | connected_controller_checkboxes[num_connected_players - 1]->setChecked(false); | ||
| 323 | return; | ||
| 324 | } else if (evt->key() == Qt::Key_Right && num_connected_players < max_supported_players) { | ||
| 325 | // Add a player, if possible | ||
| 326 | ui->labelError->setVisible(false); | ||
| 327 | connected_controller_checkboxes[num_connected_players]->setChecked(true); | ||
| 328 | return; | ||
| 329 | } | ||
| 330 | QDialog::keyPressEvent(evt); | ||
| 331 | } | ||
| 332 | |||
| 294 | bool QtControllerSelectorDialog::CheckIfParametersMet() { | 333 | bool QtControllerSelectorDialog::CheckIfParametersMet() { |
| 295 | // Here, we check and validate the current configuration against all applicable parameters. | 334 | // Here, we check and validate the current configuration against all applicable parameters. |
| 296 | const auto num_connected_players = static_cast<int>( | 335 | const auto num_connected_players = static_cast<int>( |
diff --git a/src/yuzu/applets/qt_controller.h b/src/yuzu/applets/qt_controller.h index 2fdc35857..7f0673d06 100644 --- a/src/yuzu/applets/qt_controller.h +++ b/src/yuzu/applets/qt_controller.h | |||
| @@ -34,6 +34,8 @@ class HIDCore; | |||
| 34 | enum class NpadStyleIndex : u8; | 34 | enum class NpadStyleIndex : u8; |
| 35 | } // namespace Core::HID | 35 | } // namespace Core::HID |
| 36 | 36 | ||
| 37 | class ControllerNavigation; | ||
| 38 | |||
| 37 | class QtControllerSelectorDialog final : public QDialog { | 39 | class QtControllerSelectorDialog final : public QDialog { |
| 38 | Q_OBJECT | 40 | Q_OBJECT |
| 39 | 41 | ||
| @@ -46,6 +48,8 @@ public: | |||
| 46 | 48 | ||
| 47 | int exec() override; | 49 | int exec() override; |
| 48 | 50 | ||
| 51 | void keyPressEvent(QKeyEvent* evt) override; | ||
| 52 | |||
| 49 | private: | 53 | private: |
| 50 | // Applies the current configuration. | 54 | // Applies the current configuration. |
| 51 | void ApplyConfiguration(); | 55 | void ApplyConfiguration(); |
| @@ -110,6 +114,8 @@ private: | |||
| 110 | 114 | ||
| 111 | Core::System& system; | 115 | Core::System& system; |
| 112 | 116 | ||
| 117 | ControllerNavigation* controller_navigation = nullptr; | ||
| 118 | |||
| 113 | // This is true if and only if all parameters are met. Otherwise, this is false. | 119 | // This is true if and only if all parameters are met. Otherwise, this is false. |
| 114 | // This determines whether the "OK" button can be clicked to exit the applet. | 120 | // This determines whether the "OK" button can be clicked to exit the applet. |
| 115 | bool parameters_met{false}; | 121 | bool parameters_met{false}; |
diff --git a/src/yuzu/applets/qt_controller.ui b/src/yuzu/applets/qt_controller.ui index 729e921ee..6f7cb3c13 100644 --- a/src/yuzu/applets/qt_controller.ui +++ b/src/yuzu/applets/qt_controller.ui | |||
| @@ -2624,13 +2624,53 @@ | |||
| 2624 | </spacer> | 2624 | </spacer> |
| 2625 | </item> | 2625 | </item> |
| 2626 | <item alignment="Qt::AlignBottom"> | 2626 | <item alignment="Qt::AlignBottom"> |
| 2627 | <widget class="QDialogButtonBox" name="buttonBox"> | 2627 | <widget class="QWidget" name="closeButtons" native="true"> |
| 2628 | <property name="enabled"> | 2628 | <layout class="QVBoxLayout" name="verticalLayout_46"> |
| 2629 | <bool>true</bool> | 2629 | <property name="spacing"> |
| 2630 | </property> | 2630 | <number>7</number> |
| 2631 | <property name="standardButtons"> | 2631 | </property> |
| 2632 | <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | 2632 | <property name="leftMargin"> |
| 2633 | </property> | 2633 | <number>0</number> |
| 2634 | </property> | ||
| 2635 | <property name="topMargin"> | ||
| 2636 | <number>0</number> | ||
| 2637 | </property> | ||
| 2638 | <property name="rightMargin"> | ||
| 2639 | <number>0</number> | ||
| 2640 | </property> | ||
| 2641 | <property name="bottomMargin"> | ||
| 2642 | <number>0</number> | ||
| 2643 | </property> | ||
| 2644 | <item> | ||
| 2645 | <widget class="QLabel" name="labelError"> | ||
| 2646 | <property name="enabled"> | ||
| 2647 | <bool>true</bool> | ||
| 2648 | </property> | ||
| 2649 | <property name="styleSheet"> | ||
| 2650 | <string notr="true">QLabel { color : red; }</string> | ||
| 2651 | </property> | ||
| 2652 | <property name="text"> | ||
| 2653 | <string>Not enough controllers</string> | ||
| 2654 | </property> | ||
| 2655 | <property name="alignment"> | ||
| 2656 | <set>Qt::AlignCenter</set> | ||
| 2657 | </property> | ||
| 2658 | <property name="margin"> | ||
| 2659 | <number>0</number> | ||
| 2660 | </property> | ||
| 2661 | </widget> | ||
| 2662 | </item> | ||
| 2663 | <item> | ||
| 2664 | <widget class="QDialogButtonBox" name="buttonBox"> | ||
| 2665 | <property name="enabled"> | ||
| 2666 | <bool>true</bool> | ||
| 2667 | </property> | ||
| 2668 | <property name="standardButtons"> | ||
| 2669 | <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
| 2670 | </property> | ||
| 2671 | </widget> | ||
| 2672 | </item> | ||
| 2673 | </layout> | ||
| 2634 | </widget> | 2674 | </widget> |
| 2635 | </item> | 2675 | </item> |
| 2636 | </layout> | 2676 | </layout> |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 89361fa3f..5427758c1 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1560,6 +1560,7 @@ void GMainWindow::ConnectMenuEvents() { | |||
| 1560 | // Tools | 1560 | // Tools |
| 1561 | connect_menu(ui->action_Rederive, std::bind(&GMainWindow::OnReinitializeKeys, this, | 1561 | connect_menu(ui->action_Rederive, std::bind(&GMainWindow::OnReinitializeKeys, this, |
| 1562 | ReinitializeKeyBehavior::Warning)); | 1562 | ReinitializeKeyBehavior::Warning)); |
| 1563 | connect_menu(ui->action_Load_Album, &GMainWindow::OnAlbum); | ||
| 1563 | connect_menu(ui->action_Load_Cabinet_Nickname_Owner, | 1564 | connect_menu(ui->action_Load_Cabinet_Nickname_Owner, |
| 1564 | [this]() { OnCabinet(Service::NFP::CabinetMode::StartNicknameAndOwnerSettings); }); | 1565 | [this]() { OnCabinet(Service::NFP::CabinetMode::StartNicknameAndOwnerSettings); }); |
| 1565 | connect_menu(ui->action_Load_Cabinet_Eraser, | 1566 | connect_menu(ui->action_Load_Cabinet_Eraser, |
| @@ -1597,6 +1598,7 @@ void GMainWindow::UpdateMenuState() { | |||
| 1597 | }; | 1598 | }; |
| 1598 | 1599 | ||
| 1599 | const std::array applet_actions{ | 1600 | const std::array applet_actions{ |
| 1601 | ui->action_Load_Album, | ||
| 1600 | ui->action_Load_Cabinet_Nickname_Owner, | 1602 | ui->action_Load_Cabinet_Nickname_Owner, |
| 1601 | ui->action_Load_Cabinet_Eraser, | 1603 | ui->action_Load_Cabinet_Eraser, |
| 1602 | ui->action_Load_Cabinet_Restorer, | 1604 | ui->action_Load_Cabinet_Restorer, |
| @@ -4224,6 +4226,29 @@ void GMainWindow::OnToggleStatusBar() { | |||
| 4224 | statusBar()->setVisible(ui->action_Show_Status_Bar->isChecked()); | 4226 | statusBar()->setVisible(ui->action_Show_Status_Bar->isChecked()); |
| 4225 | } | 4227 | } |
| 4226 | 4228 | ||
| 4229 | void GMainWindow::OnAlbum() { | ||
| 4230 | constexpr u64 AlbumId = 0x010000000000100Dull; | ||
| 4231 | auto bis_system = system->GetFileSystemController().GetSystemNANDContents(); | ||
| 4232 | if (!bis_system) { | ||
| 4233 | QMessageBox::warning(this, tr("No firmware available"), | ||
| 4234 | tr("Please install the firmware to use the Album applet.")); | ||
| 4235 | return; | ||
| 4236 | } | ||
| 4237 | |||
| 4238 | auto album_nca = bis_system->GetEntry(AlbumId, FileSys::ContentRecordType::Program); | ||
| 4239 | if (!album_nca) { | ||
| 4240 | QMessageBox::warning(this, tr("Album Applet"), | ||
| 4241 | tr("Album applet is not available. Please reinstall firmware.")); | ||
| 4242 | return; | ||
| 4243 | } | ||
| 4244 | |||
| 4245 | system->GetAppletManager().SetCurrentAppletId(Service::AM::Applets::AppletId::PhotoViewer); | ||
| 4246 | |||
| 4247 | const auto filename = QString::fromStdString(album_nca->GetFullPath()); | ||
| 4248 | UISettings::values.roms_path = QFileInfo(filename).path(); | ||
| 4249 | BootGame(filename); | ||
| 4250 | } | ||
| 4251 | |||
| 4227 | void GMainWindow::OnCabinet(Service::NFP::CabinetMode mode) { | 4252 | void GMainWindow::OnCabinet(Service::NFP::CabinetMode mode) { |
| 4228 | constexpr u64 CabinetId = 0x0100000000001002ull; | 4253 | constexpr u64 CabinetId = 0x0100000000001002ull; |
| 4229 | auto bis_system = system->GetFileSystemController().GetSystemNANDContents(); | 4254 | auto bis_system = system->GetFileSystemController().GetSystemNANDContents(); |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index c1872ecd4..2346eb3bd 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -374,6 +374,7 @@ private slots: | |||
| 374 | void ResetWindowSize720(); | 374 | void ResetWindowSize720(); |
| 375 | void ResetWindowSize900(); | 375 | void ResetWindowSize900(); |
| 376 | void ResetWindowSize1080(); | 376 | void ResetWindowSize1080(); |
| 377 | void OnAlbum(); | ||
| 377 | void OnCabinet(Service::NFP::CabinetMode mode); | 378 | void OnCabinet(Service::NFP::CabinetMode mode); |
| 378 | void OnMiiEdit(); | 379 | void OnMiiEdit(); |
| 379 | void OnCaptureScreenshot(); | 380 | void OnCaptureScreenshot(); |
diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index 31c3de9ef..88684ffb5 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui | |||
| @@ -160,6 +160,7 @@ | |||
| 160 | <addaction name="action_Verify_installed_contents"/> | 160 | <addaction name="action_Verify_installed_contents"/> |
| 161 | <addaction name="separator"/> | 161 | <addaction name="separator"/> |
| 162 | <addaction name="menu_cabinet_applet"/> | 162 | <addaction name="menu_cabinet_applet"/> |
| 163 | <addaction name="action_Load_Album"/> | ||
| 163 | <addaction name="action_Load_Mii_Edit"/> | 164 | <addaction name="action_Load_Mii_Edit"/> |
| 164 | <addaction name="separator"/> | 165 | <addaction name="separator"/> |
| 165 | <addaction name="action_Capture_Screenshot"/> | 166 | <addaction name="action_Capture_Screenshot"/> |
| @@ -380,6 +381,11 @@ | |||
| 380 | <string>&Capture Screenshot</string> | 381 | <string>&Capture Screenshot</string> |
| 381 | </property> | 382 | </property> |
| 382 | </action> | 383 | </action> |
| 384 | <action name="action_Load_Album"> | ||
| 385 | <property name="text"> | ||
| 386 | <string>Open &Album</string> | ||
| 387 | </property> | ||
| 388 | </action> | ||
| 383 | <action name="action_Load_Cabinet_Nickname_Owner"> | 389 | <action name="action_Load_Cabinet_Nickname_Owner"> |
| 384 | <property name="text"> | 390 | <property name="text"> |
| 385 | <string>&Set Nickname and Owner</string> | 391 | <string>&Set Nickname and Owner</string> |