| 737 | } |
| 738 | |
| 739 | static void aptScreenTransfer(NS_APPID appId, bool sysApplet) |
| 740 | { |
| 741 | // Retrieve display capture info from GSP |
| 742 | GSPGPU_CaptureInfo gspcapinfo = {0}; |
| 743 | GSPGPU_ImportDisplayCaptureInfo(&gspcapinfo); |
| 744 | |
| 745 | // Wait for the target applet to be registered |
| 746 | for (;;) |
| 747 | { |
| 748 | bool tmp; |
| 749 | Result res = APT_IsRegistered(appId, &tmp); |
| 750 | if (R_SUCCEEDED(res) && tmp) break; |
| 751 | svcSleepThread(10000000); |
| 752 | } |
| 753 | |
| 754 | // Calculate the layout/size of the capture memory block |
| 755 | aptCaptureBufInfo capinfo; |
| 756 | aptInitCaptureInfo(&capinfo, &gspcapinfo); |
| 757 | |
| 758 | // Request the capture memory block to be allocated |
| 759 | for (;;) |
| 760 | { |
| 761 | Result res = APT_SendParameter(envGetAptAppId(), appId, sysApplet ? APTCMD_SYSAPPLET_REQUEST : APTCMD_REQUEST, &capinfo, sizeof(capinfo), 0); |
| 762 | if (R_SUCCEEDED(res)) break; |
| 763 | svcSleepThread(10000000); |
| 764 | } |
| 765 | |
| 766 | // Receive the response from APT |
| 767 | Handle hCapMemBlk = 0; |
| 768 | for (;;) |
| 769 | { |
| 770 | APT_Command cmd; |
| 771 | Result res = aptReceiveParameter(&cmd, NULL, &hCapMemBlk); |
| 772 | if (R_SUCCEEDED(res) && cmd==APTCMD_RESPONSE) |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | // For library applets, we need to manually do the capture ourselves |
| 777 | // (this involves mapping the memory block and doing the conversion) |
| 778 | if (!sysApplet) |
| 779 | { |
| 780 | void* map = mappableAlloc(capinfo.size); |
| 781 | if (map) |
| 782 | { |
| 783 | Result res = svcMapMemoryBlock(hCapMemBlk, (u32)map, MEMPERM_READWRITE, MEMPERM_READWRITE); |
| 784 | if (R_SUCCEEDED(res)) |
| 785 | { |
| 786 | aptConvertScreenForCapture( // Bottom screen |
| 787 | (u8*)map + capinfo.bottom.leftOffset, |
| 788 | gspcapinfo.screencapture[1].framebuf0_vaddr, |
| 789 | 320, (GSPGPU_FramebufferFormat)capinfo.bottom.format); |
| 790 | aptConvertScreenForCapture( // Top screen (Left eye) |
| 791 | (u8*)map + capinfo.top.leftOffset, |
| 792 | gspcapinfo.screencapture[0].framebuf0_vaddr, |
| 793 | 400, (GSPGPU_FramebufferFormat)capinfo.top.format); |
| 794 | if (capinfo.is3D) |
| 795 | aptConvertScreenForCapture( // Top screen (Right eye) |
| 796 | (u8*)map + capinfo.top.rightOffset, |
no test coverage detected