azahar/src/core/frontend/framebuffer_layout.h
David Griswold aca8b45664
android: Implement secondary display support (#617)
* Enable the SecondScreenPresentation class

* Update everything to enable second screen on android under GL and Vulkan. Still some issues!

* Some attempts to enable surface changes

* OpenGL is working on surface change, vulkan still no

* release surfaces (also fixed vulkan?)

* added and enabled layout setting

* resolve merge conflict

* rearrange switch cases to satisfy linux compiler

* openGL is working!

* several vk changes to try to fix crashes

* maybe vulkan is working?

* removing unnecessary code attempts

* Simplified secondscreen for better performance

* vk_platform.cpp: Fixed build failure caused by bad rebase

* vk_present_window.h: Removed stray newline

* Applied clang-format

* bug fix for odin 2

* Applied clang-format

* Updated license headers

* Moved SecondScreen class to org.citra.citra_emu.display

* Various formatting and readability improvements

* Added brackets where previously absent for readability

* Additional readability improvement

* RendererVulkan::NotifySurfaceChanged: Simplified condition checking

* change all references to "secondary screen" to "secondary display" to limit confusion with top screen / bottom screen

* rename main_window to main_present_window and second_window to secondary_present_window

* Reverted accidentally downgraded compatibility list submodule

* Removed unnecessary log message

* Applied clang-format

* Added a description to the Secondary Display Screen Layout setting

* Added `_ptr` suffix to `secondary_present_window`

This distinguishes it as a pointer, as `main_present_window` isn't a pointer, so there could be confusion on whether to use `.` or `->`

---------

Co-authored-by: OpenSauce04 <opensauce04@gmail.com>
2025-08-08 21:41:52 +01:00

174 lines
7.5 KiB
C++

// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include "common/math_util.h"
#include "common/settings.h"
namespace Layout {
/// Orientation of the 3DS displays
enum class DisplayOrientation {
Landscape, // Default orientation of the 3DS
Portrait, // 3DS rotated 90 degrees counter-clockwise
LandscapeFlipped, // 3DS rotated 180 degrees counter-clockwise
PortraitFlipped, // 3DS rotated 270 degrees counter-clockwise
};
/// Describes the horizontal coordinates for the right eye screen when using Cardboard VR
struct CardboardSettings {
u32 top_screen_right_eye;
u32 bottom_screen_right_eye;
s32 user_x_shift;
};
/// Describes the layout of the window framebuffer (size and top/bottom screen positions)
struct FramebufferLayout {
u32 width;
u32 height;
bool top_screen_enabled;
bool bottom_screen_enabled;
Common::Rectangle<u32> top_screen;
Common::Rectangle<u32> bottom_screen;
bool is_rotated = true;
bool is_portrait = false;
bool additional_screen_enabled;
Common::Rectangle<u32> additional_screen;
CardboardSettings cardboard;
/**
* Returns the ratio of pixel size of the top screen, compared to the native size of the 3DS
* screen.
*/
u32 GetScalingRatio() const;
static float GetAspectRatioValue(Settings::AspectRatio aspect_ratio);
};
/**
* Method to create a rotated copy of a framebuffer layout, used to rotate to upright mode
*/
FramebufferLayout reverseLayout(FramebufferLayout layout);
/**
* Factory method for constructing a default FramebufferLayout with screens on top of one another
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be displayed above the top screen
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
* @return Newly created FramebufferLayout object with default screen regions initialized
*/
FramebufferLayout DefaultFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
/**
* Factory method for constructing the mobile Full Width (Default) layout
* Two screens at top, full width (so different heights)
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be displayed above the top screen
* @return Newly created FramebufferLayout object with mobile portrait screen regions initialized
*/
FramebufferLayout PortraitTopFullFrameLayout(u32 width, u32 height, bool is_swapped,
bool upright = false);
/**
* Factory method for constructing the mobile Original layout
* Two screens at top, equal heights
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be displayed above the top screen
* @return Newly created FramebufferLayout object with mobile portrait screen regions initialized
*/
FramebufferLayout PortraitOriginalLayout(u32 width, u32 height, bool is_swapped,
bool upright = false);
/**
* Factory method for constructing a FramebufferLayout with only the top or bottom screen
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed)
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
* @return Newly created FramebufferLayout object with default screen regions initialized
*/
FramebufferLayout SingleFrameLayout(u32 width, u32 height, bool is_swapped, bool upright);
/**
* Factory method for constructing a Frame with differently sized top and bottom windows
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be the large display
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
* @param scale_factor The ratio between the large screen with respect to the smaller screen
* @param vertical_alignment The vertical alignment of the smaller screen relative to the larger
* screen
* @return Newly created FramebufferLayout object with default screen regions initialized
*/
FramebufferLayout LargeFrameLayout(u32 width, u32 height, bool is_swapped, bool upright,
float scale_factor,
Settings::SmallScreenPosition small_screen_position);
/**
* Factory method for constructing a frame with 2.5 times bigger top screen on the right,
* and 1x top and bottom screen on the left
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be the large display
* @param upright if true, the screens will be rotated 90 degrees anti-clockwise
* @param scale_factor determines the proportion of large to small. Must be >= 1
* @param small_screen_position determines where the small screen appears relative to the large
* screen
* @return Newly created FramebufferLayout object with default screen regions initialized
*/
FramebufferLayout HybridScreenLayout(u32 width, u32 height, bool swapped, bool upright);
/**
* Factory method for constructing a Frame with the Top screen and bottom
* screen on separate windows
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @param is_secondary if true, the bottom screen will be enabled instead of the top screen
* @return Newly created FramebufferLayout object with default screen regions initialized
*/
FramebufferLayout SeparateWindowsLayout(u32 width, u32 height, bool is_secondary, bool upright);
/**
* Method for constructing the secondary layout for Android, based on
* the appropriate setting.
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
*/
FramebufferLayout AndroidSecondaryLayout(u32 width, u32 height);
/**
* Factory method for constructing a custom FramebufferLayout
* @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels
* @return Newly created FramebufferLayout object with default screen regions initialized
*/
FramebufferLayout CustomFrameLayout(u32 width, u32 height, bool is_swapped,
bool is_portrait_mode = false);
/**
* Convenience method to get frame layout by resolution scale
* Read from the current settings to determine which layout to use.
* @param res_scale resolution scale factor
* @param is_portrait_mode defaults to false
*/
FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale, bool is_secondary = false,
bool is_portrait_mode = false);
/**
* Convenience method for transforming a frame layout when using Cardboard VR
* @param layout frame layout to transform
* @return layout transformed with the user cardboard settings
*/
FramebufferLayout GetCardboardSettings(const FramebufferLayout& layout);
std::pair<unsigned, unsigned> GetMinimumSizeFromLayout(Settings::LayoutOption layout,
bool upright_screen);
std::pair<unsigned, unsigned> GetMinimumSizeFromPortraitLayout();
} // namespace Layout