UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AndroidWindowUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "Misc/CommandLine.h"
7#include "RHI.h"
8
9#if PLATFORM_ANDROID
11
12#if USE_ANDROID_JNI
14#endif
15
16#endif
17
19
21{
23 {
25 // ensure Width and Height is multiple of 8
27 SanitizedDims.Y = (RequestedScreenDims.Y / 8) * 8;
28
29 // clamp to native resolution
30 SanitizedDims.X = FPlatformMath::Min(SanitizedDims.X, MaxScreenDims.X);
31 SanitizedDims.Y = FPlatformMath::Min(SanitizedDims.Y, MaxScreenDims.Y);
32 return SanitizedDims;
33 }
34
36 {
37 // CSF is a multiplier to 1280x720
38 static IConsoleVariable* CVarScale = IConsoleManager::Get().FindConsoleVariable(TEXT("r.MobileContentScaleFactor"));
40
41 static IConsoleVariable* CVarResX = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.DesiredResX"));
42 static IConsoleVariable* CVarResY = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.DesiredResY"));
43 int32 RequestedResX = CVarResX->GetInt();
44 int32 RequestedResY = CVarResY->GetInt();
45
46 FString CmdLineCSF;
47 if (FParse::Value(FCommandLine::Get(), TEXT("mcsf="), CmdLineCSF, false))
48 {
50 }
51
52 FString CmdLineMDRes;
53 if (FParse::Value(FCommandLine::Get(), TEXT("mobileresx="), CmdLineMDRes, false))
54 {
55 RequestedResX = FCString::Atoi(*CmdLineMDRes);
56 }
57 if (FParse::Value(FCommandLine::Get(), TEXT("mobileresy="), CmdLineMDRes, false))
58 {
59 RequestedResY = FCString::Atoi(*CmdLineMDRes);
60 }
61
62 // 0 means to use native size
63 if (RequestedContentScaleFactor == 0.0f && RequestedResX <= 0 && RequestedResY <= 0)
64 {
65 UE_LOG(LogAndroidWindowUtils, Log, TEXT("Setting Width=%d and Height=%d (requested scale = 0 = auto)"), InOutScreenWidth, InOutScreenHeight);
66 }
67 else
68 {
69 int32 Width = InOutScreenWidth;
70 int32 Height = InOutScreenHeight;
71
72 if (RequestedResX > 0)
73 {
74 // set long side for orientation to requested X (height > width == GAndroidIsPortrait)
76 {
77 Height = RequestedResX;
78 Width = FMath::TruncToInt32((float)Height * ((float)InOutScreenWidth / (float)InOutScreenHeight) + 0.5f);
79 }
80 else
81 {
82 Width = RequestedResX;
83 Height = FMath::TruncToInt32((float)Width * ((float)InOutScreenHeight / (float)InOutScreenWidth) + 0.5f);
84 }
85 }
86 else if (RequestedResY > 0)
87 {
88 // set short side for orientation to requested Y (height > width == GAndroidIsPortrait)
90 {
91 Width = RequestedResY;
92 Height = FMath::TruncToInt32((float)Width * ((float)InOutScreenHeight / (float)InOutScreenWidth) + 0.5f);
93 }
94 else
95 {
96 Height = RequestedResY;
97 Width = FMath::TruncToInt32((float)Height * ((float)InOutScreenWidth / (float)InOutScreenHeight) + 0.5f);
98 }
99 }
100 else
101 {
102 const float AspectRatio = (float)InOutScreenWidth / (float)InOutScreenHeight;
103
104 // set resolution relative to 1280x720 ((height > width == GAndroidIsPortrait)
106 {
107 Height = FMath::TruncToInt32(1280.f * RequestedContentScaleFactor);
108 }
109 else
110 {
111 Height = FMath::TruncToInt32(720.f * RequestedContentScaleFactor);
112 }
113
114 // apply the aspect ration to get the width
115 Width = FMath::TruncToInt32((float)Height * AspectRatio + 0.5f);
116 }
117
121
122 UE_LOG(LogAndroidWindowUtils, Log, TEXT("Setting Width=%d and Height=%d (requested scale = %f)"), InOutScreenWidth, InOutScreenHeight, RequestedContentScaleFactor);
123 }
124 }
125} // end AndroidWindowUtils
bool AndroidThunkCpp_IsOculusMobileApplication()
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DEFINE_LOG_CATEGORY_STATIC(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:380
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
UE::Math::TIntVector2< int32 > FIntVector2
Definition MathFwd.h:91
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition IConsoleManager.h:558
virtual float GetFloat() const =0
virtual int32 GetInt() const =0
Definition AndroidWindowUtils.h:21
void ApplyContentScaleFactor(int32 &InOutScreenWidth, int32 &InOutScreenHeight)
Definition AndroidWindowUtils.h:35
FIntVector2 SanitizeAndroidScreenSize(const FIntVector2 &&MaxScreenDims, const FIntVector2 &&RequestedScreenDims)
Definition AndroidWindowUtils.h:22
static CORE_API const TCHAR * Get()
Definition CommandLine.cpp:61
static CORE_API bool Value(const TCHAR *Stream, const TCHAR *Match, FName &Name)
Definition Parse.cpp:584
virtual IConsoleVariable * FindConsoleVariable(const TCHAR *Name, bool bTrackFrequentCalls=true) const =0
static IConsoleManager & Get()
Definition IConsoleManager.h:1270
static UE_FORCEINLINE_HINT int32 Atoi(const CharType *String)
Definition CString.h:1173
static UE_FORCEINLINE_HINT float Atof(const CharType *String)
Definition CString.h:1185
IntType X
Definition IntVector.h:679