framebuffer_layout.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/math_util.h"
  6. namespace Layout {
  7. enum ScreenUndocked : u32 {
  8. Width = 1280,
  9. Height = 720,
  10. };
  11. enum ScreenDocked : u32 {
  12. WidthDocked = 1920,
  13. HeightDocked = 1080,
  14. };
  15. enum class AspectRatio {
  16. Default,
  17. R4_3,
  18. R21_9,
  19. StretchToWindow,
  20. };
  21. /// Describes the layout of the window framebuffer
  22. struct FramebufferLayout {
  23. u32 width{ScreenUndocked::Width};
  24. u32 height{ScreenUndocked::Height};
  25. bool is_srgb{};
  26. Common::Rectangle<u32> screen;
  27. /**
  28. * Returns the ration of pixel size of the screen, compared to the native size of the undocked
  29. * Switch screen.
  30. */
  31. float GetScalingRatio() const {
  32. return static_cast<float>(screen.GetWidth()) / ScreenUndocked::Width;
  33. }
  34. };
  35. /**
  36. * Factory method for constructing a default FramebufferLayout
  37. * @param width Window framebuffer width in pixels
  38. * @param height Window framebuffer height in pixels
  39. * @return Newly created FramebufferLayout object with default screen regions initialized
  40. */
  41. FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
  42. /**
  43. * Convenience method to get frame layout by resolution scale
  44. * @param res_scale resolution scale factor
  45. */
  46. FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
  47. /**
  48. * Convenience method to determine emulation aspect ratio
  49. * @param aspect Represents the index of aspect ratio stored in Settings::values.aspect_ratio
  50. * @param window_aspect_ratio Current window aspect ratio
  51. * @return Emulation render window aspect ratio
  52. */
  53. float EmulationAspectRatio(AspectRatio aspect, float window_aspect_ratio);
  54. } // namespace Layout