////////////////////////////////////////////////////////////////////////////// // Initialize() // ////////////////////////////////////////////////////////////////////////////// void Initialize() { CalculateSurfaceSize(); m_bTextureSize = m_sizeSurface.Y() == (int)NextPowerOf2((DWORD)m_sizeSurface.Y()) && m_sizeSurface.X() == (int)NextPowerOf2((DWORD)m_sizeSurface.X()); m_bColorKey = false; m_colorKey = Color(0, 0, 0); m_data.m_id = 0; m_mode = SurfaceModeDD; m_pbits = NULL; }
FPlatformRect FAndroidWindow::GetScreenRect() { // currently hardcoding resolution ANativeWindow* Window = (ANativeWindow*)FPlatformMisc::GetHardwareWindow(); check(Window != NULL); // get the aspect ratio of the physical screen int32 ScreenWidth, ScreenHeight; CalculateSurfaceSize(Window, ScreenWidth, ScreenHeight); float AspectRatio = (float)ScreenWidth / (float)ScreenHeight; int32 MaxWidth = ScreenWidth; int32 MaxHeight = ScreenHeight; static auto* MobileHDRCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR")); static auto* MobileHDR32bppCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR32bpp")); const bool bMobileHDR32bpp = (MobileHDRCvar && MobileHDRCvar->GetValueOnAnyThread() == 1) && (FAndroidMisc::SupportsFloatingPointRenderTargets() == false || (MobileHDR32bppCvar && MobileHDR32bppCvar->GetValueOnAnyThread() == 1)); if (bMobileHDR32bpp) { if (GAndroidIsPortrait) { MaxHeight = FPlatformMath::Min(MaxHeight,1024); MaxWidth = MaxHeight * AspectRatio; } else { MaxWidth = FPlatformMath::Min(MaxWidth,1024); MaxHeight = MaxWidth / AspectRatio; } } // CSF is a multiplier to 1280x720 static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.MobileContentScaleFactor")); float RequestedContentScaleFactor = CVar->GetFloat(); // 0 means to use native size int32 Width, Height; if (RequestedContentScaleFactor == 0.0f) { Width = MaxWidth; Height = MaxHeight; } else { if (GAndroidIsPortrait) { Height = 1280 * RequestedContentScaleFactor; } else { Height = 720 * RequestedContentScaleFactor; } // apply the aspect ration to get the width Width = Height * AspectRatio; // clamp to native resolution Width = FPlatformMath::Min(Width, MaxWidth); Height = FPlatformMath::Min(Height, MaxHeight); } FPlatformRect ScreenRect; ScreenRect.Left = 0; ScreenRect.Top = 0; ScreenRect.Right = Width; ScreenRect.Bottom = Height; return ScreenRect; }
FPlatformRect FAndroidWindow::GetScreenRect() { // CSF is a multiplier to 1280x720 static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.MobileContentScaleFactor")); float RequestedContentScaleFactor = CVar->GetFloat(); ANativeWindow* Window = (ANativeWindow*)FPlatformMisc::GetHardwareWindow(); check(Window != NULL); if (RequestedContentScaleFactor != ContentScaleFactor) { FPlatformMisc::LowLevelOutputDebugStringf(TEXT("***** RequestedContentScaleFactor different %d != %d, not using res cache"), RequestedContentScaleFactor, ContentScaleFactor); } if (Window != LastWindow) { FPlatformMisc::LowLevelOutputDebugString(TEXT("***** Window different, not using res cache")); } if (WindowWidth <= 8) { FPlatformMisc::LowLevelOutputDebugStringf(TEXT("***** WindowWidth is %d, not using res cache"), WindowWidth); } // since orientation won't change on Android, use cached results if still valid if (WindowInit && RequestedContentScaleFactor == ContentScaleFactor && Window == LastWindow && WindowWidth > 8) { FPlatformRect ScreenRect; ScreenRect.Left = 0; ScreenRect.Top = 0; ScreenRect.Right = WindowWidth; ScreenRect.Bottom = WindowHeight; return ScreenRect; } // currently hardcoding resolution // get the aspect ratio of the physical screen int32 ScreenWidth, ScreenHeight; CalculateSurfaceSize(Window, ScreenWidth, ScreenHeight); float AspectRatio = (float)ScreenWidth / (float)ScreenHeight; int32 MaxWidth = ScreenWidth; int32 MaxHeight = ScreenHeight; static auto* MobileHDRCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR")); static auto* MobileHDR32bppCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.MobileHDR32bpp")); const bool bMobileHDR32bpp = (MobileHDRCvar && MobileHDRCvar->GetValueOnAnyThread() == 1) && (FAndroidMisc::SupportsFloatingPointRenderTargets() == false || (MobileHDR32bppCvar && MobileHDR32bppCvar->GetValueOnAnyThread() == 1)); UE_LOG(LogAndroid, Log, TEXT("Requires Mosaic: %s"), bMobileHDR32bpp ? TEXT("YES") : TEXT("no")); if (bMobileHDR32bpp) { const int32 OldMaxWidth = MaxWidth; const int32 OldMaxHeight = MaxHeight; if (GAndroidIsPortrait) { MaxHeight = FPlatformMath::Min(MaxHeight,1024); MaxWidth = MaxHeight * AspectRatio; } else { MaxWidth = FPlatformMath::Min(MaxWidth,1024); MaxHeight = MaxWidth / AspectRatio; } UE_LOG(LogAndroid, Log, TEXT("Limiting MaxWidth=%d and MaxHeight=%d due to bMobileHDR32bpp (was %dx%d)"), MaxWidth, MaxHeight, OldMaxWidth, OldMaxHeight); } // 0 means to use native size int32 Width, Height; if (RequestedContentScaleFactor == 0.0f) { Width = MaxWidth; Height = MaxHeight; UE_LOG(LogAndroid, Log, TEXT("Setting Width=%d and Height=%d (requested scale = 0 = auto)"), Width, Height); } else { if (GAndroidIsPortrait) { Height = 1280 * RequestedContentScaleFactor; } else { Height = 720 * RequestedContentScaleFactor; } // apply the aspect ration to get the width Width = Height * AspectRatio; // clamp to native resolution Width = FPlatformMath::Min(Width, MaxWidth); Height = FPlatformMath::Min(Height, MaxHeight); UE_LOG(LogAndroid, Log, TEXT("Setting Width=%d and Height=%d (requested scale = %f)"), Width, Height, RequestedContentScaleFactor); } FPlatformRect ScreenRect; ScreenRect.Left = 0; ScreenRect.Top = 0; ScreenRect.Right = Width; ScreenRect.Bottom = Height; // save for future calls WindowWidth = Width; WindowHeight = Height; WindowInit = true; ContentScaleFactor = RequestedContentScaleFactor; LastWindow = Window; return ScreenRect; }