caps_su.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "common/logging/log.h"
  4. #include "core/core.h"
  5. #include "core/hle/service/caps/caps_manager.h"
  6. #include "core/hle/service/caps/caps_su.h"
  7. #include "core/hle/service/caps/caps_types.h"
  8. #include "core/hle/service/cmif_serialization.h"
  9. #include "core/hle/service/ipc_helpers.h"
  10. #include "video_core/renderer_base.h"
  11. namespace Service::Capture {
  12. IScreenShotApplicationService::IScreenShotApplicationService(
  13. Core::System& system_, std::shared_ptr<AlbumManager> album_manager)
  14. : ServiceFramework{system_, "caps:su"}, manager{album_manager} {
  15. // clang-format off
  16. static const FunctionInfo functions[] = {
  17. {32, C<&IScreenShotApplicationService::SetShimLibraryVersion>, "SetShimLibraryVersion"},
  18. {201, nullptr, "SaveScreenShot"},
  19. {203, C<&IScreenShotApplicationService::SaveScreenShotEx0>, "SaveScreenShotEx0"},
  20. {205, C<&IScreenShotApplicationService::SaveScreenShotEx1>, "SaveScreenShotEx1"},
  21. {210, nullptr, "SaveScreenShotEx2"},
  22. };
  23. // clang-format on
  24. RegisterHandlers(functions);
  25. }
  26. IScreenShotApplicationService::~IScreenShotApplicationService() = default;
  27. Result IScreenShotApplicationService::SetShimLibraryVersion(ShimLibraryVersion library_version,
  28. ClientAppletResourceUserId aruid) {
  29. LOG_WARNING(Service_Capture, "(STUBBED) called. library_version={}, applet_resource_user_id={}",
  30. library_version, aruid.pid);
  31. R_SUCCEED();
  32. }
  33. Result IScreenShotApplicationService::SaveScreenShotEx0(
  34. Out<ApplicationAlbumEntry> out_entry, const ScreenShotAttribute& attribute,
  35. AlbumReportOption report_option, ClientAppletResourceUserId aruid,
  36. InBuffer<BufferAttr_HipcMapTransferAllowsNonSecure | BufferAttr_HipcMapAlias>
  37. image_data_buffer) {
  38. LOG_INFO(Service_Capture,
  39. "called, report_option={}, image_data_buffer_size={}, applet_resource_user_id={}",
  40. report_option, image_data_buffer.size(), aruid.pid);
  41. manager->FlipVerticallyOnWrite(false);
  42. R_RETURN(manager->SaveScreenShot(*out_entry, attribute, report_option, image_data_buffer,
  43. aruid.pid));
  44. }
  45. Result IScreenShotApplicationService::SaveScreenShotEx1(
  46. Out<ApplicationAlbumEntry> out_entry, const ScreenShotAttribute& attribute,
  47. AlbumReportOption report_option, ClientAppletResourceUserId aruid,
  48. const InLargeData<ApplicationData, BufferAttr_HipcMapAlias> app_data_buffer,
  49. const InBuffer<BufferAttr_HipcMapTransferAllowsNonSecure | BufferAttr_HipcMapAlias>
  50. image_data_buffer) {
  51. LOG_INFO(Service_Capture,
  52. "called, report_option={}, image_data_buffer_size={}, applet_resource_user_id={}",
  53. report_option, image_data_buffer.size(), aruid.pid);
  54. manager->FlipVerticallyOnWrite(false);
  55. R_RETURN(manager->SaveScreenShot(*out_entry, attribute, report_option, *app_data_buffer,
  56. image_data_buffer, aruid.pid));
  57. }
  58. void IScreenShotApplicationService::CaptureAndSaveScreenshot(AlbumReportOption report_option) {
  59. auto& renderer = system.Renderer();
  60. Layout::FramebufferLayout layout =
  61. Layout::DefaultFrameLayout(screenshot_width, screenshot_height);
  62. const Capture::ScreenShotAttribute attribute{
  63. .unknown_0{},
  64. .orientation = Capture::AlbumImageOrientation::None,
  65. .unknown_1{},
  66. .unknown_2{},
  67. .pad163{},
  68. };
  69. renderer.RequestScreenshot(
  70. image_data.data(),
  71. [attribute, report_option, this](bool invert_y) {
  72. // Convert from BGRA to RGBA
  73. for (std::size_t i = 0; i < image_data.size(); i += bytes_per_pixel) {
  74. const u8 temp = image_data[i];
  75. image_data[i] = image_data[i + 2];
  76. image_data[i + 2] = temp;
  77. }
  78. Capture::ApplicationAlbumEntry entry{};
  79. manager->FlipVerticallyOnWrite(invert_y);
  80. manager->SaveScreenShot(entry, attribute, report_option, image_data, {});
  81. },
  82. layout);
  83. }
  84. } // namespace Service::Capture