framebuffer_layout.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "common/math_util.h"
  7. namespace Layout {
  8. namespace MinimumSize {
  9. constexpr u32 Width = 640;
  10. constexpr u32 Height = 360;
  11. } // namespace MinimumSize
  12. namespace ScreenUndocked {
  13. constexpr u32 Width = 1280;
  14. constexpr u32 Height = 720;
  15. } // namespace ScreenUndocked
  16. namespace ScreenDocked {
  17. constexpr u32 Width = 1920;
  18. constexpr u32 Height = 1080;
  19. } // namespace ScreenDocked
  20. enum class AspectRatio {
  21. Default,
  22. R4_3,
  23. R21_9,
  24. StretchToWindow,
  25. };
  26. /// Describes the layout of the window framebuffer
  27. struct FramebufferLayout {
  28. u32 width{ScreenUndocked::Width};
  29. u32 height{ScreenUndocked::Height};
  30. bool is_srgb{};
  31. Common::Rectangle<u32> screen;
  32. /**
  33. * Returns the ration of pixel size of the screen, compared to the native size of the undocked
  34. * Switch screen.
  35. */
  36. float GetScalingRatio() const {
  37. return static_cast<float>(screen.GetWidth()) / ScreenUndocked::Width;
  38. }
  39. };
  40. /**
  41. * Factory method for constructing a default FramebufferLayout
  42. * @param width Window framebuffer width in pixels
  43. * @param height Window framebuffer height in pixels
  44. * @return Newly created FramebufferLayout object with default screen regions initialized
  45. */
  46. FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
  47. /**
  48. * Convenience method to get frame layout by resolution scale
  49. * @param res_scale resolution scale factor
  50. */
  51. FramebufferLayout FrameLayoutFromResolutionScale(f32 res_scale);
  52. /**
  53. * Convenience method to determine emulation aspect ratio
  54. * @param aspect Represents the index of aspect ratio stored in Settings::values.aspect_ratio
  55. * @param window_aspect_ratio Current window aspect ratio
  56. * @return Emulation render window aspect ratio
  57. */
  58. float EmulationAspectRatio(AspectRatio aspect, float window_aspect_ratio);
  59. } // namespace Layout