/ src / core / frontend / framebuffer_layout.h
framebuffer_layout.h
  1  // Copyright 2016 Citra Emulator Project
  2  // Licensed under GPLv2 or any later version
  3  // Refer to the license.txt file included.
  4  
  5  #pragma once
  6  
  7  #include "common/math_util.h"
  8  
  9  namespace Settings {
 10  enum class LayoutOption : u32;
 11  }
 12  
 13  namespace Layout {
 14  
 15  /// Orientation of the 3DS displays
 16  enum class DisplayOrientation {
 17      Landscape,        // Default orientation of the 3DS
 18      Portrait,         // 3DS rotated 90 degrees counter-clockwise
 19      LandscapeFlipped, // 3DS rotated 180 degrees counter-clockwise
 20      PortraitFlipped,  // 3DS rotated 270 degrees counter-clockwise
 21  };
 22  
 23  /// Describes the vertical alignment of the top and bottom screens in LargeFrameLayout
 24  /// Top
 25  /// +-------------+-----+
 26  /// |             |     |
 27  /// |             +-----+
 28  /// |             |
 29  /// +-------------+
 30  /// Middle
 31  /// +-------------+
 32  /// |             +-----+
 33  /// |             |     |
 34  /// |             +-----+
 35  /// +-------------+
 36  /// Bottom
 37  /// +-------------+
 38  /// |             |
 39  /// |             +-----+
 40  /// |             |     |
 41  /// +-------------+-----+
 42  enum class VerticalAlignment {
 43      Top,
 44      Middle,
 45      Bottom,
 46  };
 47  
 48  /// Describes the horizontal coordinates for the right eye screen when using Cardboard VR
 49  struct CardboardSettings {
 50      u32 top_screen_right_eye;
 51      u32 bottom_screen_right_eye;
 52      s32 user_x_shift;
 53  };
 54  
 55  /// Describes the layout of the window framebuffer (size and top/bottom screen positions)
 56  struct FramebufferLayout {
 57      u32 width;
 58      u32 height;
 59      bool top_screen_enabled;
 60      bool bottom_screen_enabled;
 61      Common::Rectangle<u32> top_screen;
 62      Common::Rectangle<u32> bottom_screen;
 63      bool is_rotated = true;
 64  
 65      bool additional_screen_enabled;
 66      Common::Rectangle<u32> additional_screen;
 67  
 68      CardboardSettings cardboard;
 69  
 70      /**
 71       * Returns the ratio of pixel size of the top screen, compared to the native size of the 3DS
 72       * screen.
 73       */
 74      u32 GetScalingRatio() const;
 75  };
 76  
 77  /**
 78   * Factory method for constructing a default FramebufferLayout
 79   * @param width Window framebuffer width in pixels
 80   * @param height Window framebuffer height in pixels
 81   * @param is_swapped if true, the bottom screen will be displayed above the top screen
 82   * @param upright if true, the screens will be rotated 90 degrees anti-clockwise
 83   * @return Newly created FramebufferLayout object with default screen regions initialized
 84   */
 85  FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
 86  
 87  /**
 88   * Factory method for constructing a mobile portrait FramebufferLayout
 89   * @param width Window framebuffer width in pixels
 90   * @param height Window framebuffer height in pixels
 91   * @param is_swapped if true, the bottom screen will be displayed above the top screen
 92   * @return Newly created FramebufferLayout object with mobile portrait screen regions initialized
 93   */
 94  FramebufferLayout MobilePortraitFrameLayout(u32 width, u32 height, bool is_swapped);
 95  
 96  /**
 97   * Factory method for constructing a FramebufferLayout with only the top or bottom screen
 98   * @param width Window framebuffer width in pixels
 99   * @param height Window framebuffer height in pixels
100   * @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed)
101   * @param upright if true, the screens will be rotated 90 degrees anti-clockwise
102   * @return Newly created FramebufferLayout object with default screen regions initialized
103   */
104  FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
105  
106  /**
107   * Factory method for constructing a Frame with the a 4x size Top screen with a 1x size bottom
108   * screen on the right
109   * This is useful in particular because it matches well with a 1920x1080 resolution monitor
110   * @param width Window framebuffer width in pixels
111   * @param height Window framebuffer height in pixels
112   * @param is_swapped if true, the bottom screen will be the large display
113   * @param upright if true, the screens will be rotated 90 degrees anti-clockwise
114   * @param scale_factor The ratio between the large screen with respect to the smaller screen
115   * @param vertical_alignment The vertical alignment of the smaller screen relative to the larger
116   * screen
117   * @return Newly created FramebufferLayout object with default screen regions initialized
118   */
119  FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool is_swapped, bool upright,
120                                     float scale_factor, VerticalAlignment vertical_alignment);
121  /**
122   * Factory method for constructing a frame with 2.5 times bigger top screen on the right,
123   * and 1x top and bottom screen on the left
124   * @param width Window framebuffer width in pixels
125   * @param height Window framebuffer height in pixels
126   * @param is_swapped if true, the bottom screen will be the large display
127   * @param upright if true, the screens will be rotated 90 degrees anti-clockwise
128   * @return Newly created FramebufferLayout object with default screen regions initialized
129   */
130  FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool upright);
131  
132  /**
133   * Factory method for constructing a Frame with the Top screen and bottom
134   * screen on separate windows
135   * @param width Window framebuffer width in pixels
136   * @param height Window framebuffer height in pixels
137   * @param is_secondary if true, the bottom screen will be enabled instead of the top screen
138   * @return Newly created FramebufferLayout object with default screen regions initialized
139   */
140  FramebufferLayout SeparateWindowsLayout(u32 width, u32 height, bool is_secondary, bool upright);
141  
142  /**
143   * Factory method for constructing a custom FramebufferLayout
144   * @param width Window framebuffer width in pixels
145   * @param height Window framebuffer height in pixels
146   * @return Newly created FramebufferLayout object with default screen regions initialized
147   */
148  FramebufferLayout CustomFrameLayout(u32 width, u32 height, bool is_swapped);
149  
150  /**
151   * Convenience method to get frame layout by resolution scale
152   * Read from the current settings to determine which layout to use.
153   * @param res_scale resolution scale factor
154   */
155  FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondary = false);
156  
157  /**
158   * Convenience method for transforming a frame layout when using Cardboard VR
159   * @param layout frame layout to transform
160   * @return layout transformed with the user cardboard settings
161   */
162  FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout);
163  
164  std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
165                                                         bool upright_screen);
166  
167  } // namespace Layout