代码改变世界

deviceProfile相关

2023-06-07 16:32  kk20161206  阅读(102)  评论(0编辑  收藏  举报
deviceManager的get
UDeviceProfileManager& UDeviceProfileManager::Get(bool bFromPostCDOContruct)
{
    if (DeviceProfileManagerSingleton == nullptr)
    {
        static bool bEntered = false;
        if (bEntered && bFromPostCDOContruct)
        {
            return *(UDeviceProfileManager*)0x3; // we know that the return value is never used, linux hates null here, which would be less weird. 
        }
        bEntered = true;
        DeviceProfileManagerSingleton = NewObject<UDeviceProfileManager>();

        DeviceProfileManagerSingleton->AddToRoot();
        if (!FPlatformProperties::RequiresCookedData())
        {
            DeviceProfileManagerSingleton->LoadProfiles();
        }

        // always start with an active profile, even if we create it on the spot
        UDeviceProfile* ActiveProfile = DeviceProfileManagerSingleton->FindProfile(GetPlatformDeviceProfileName());
        DeviceProfileManagerSingleton->SetActiveDeviceProfile(ActiveProfile);

        // now we allow the cvar changes to be acknowledged
        CVarDeviceProfileOverride.AsVariable()->SetOnChangedCallback(FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* Variable)
        {
            UDeviceProfileManager::Get().HandleDeviceProfileOverrideChange();
        }));

        IConsoleManager::Get().RegisterConsoleCommand(
            TEXT("dp.Override.Restore"),
            TEXT("Restores any cvars set by dp.Override to their previous value"),
            FConsoleCommandDelegate::CreateLambda([]()
            {
                UDeviceProfileManager::Get().HandleDeviceProfileOverridePop();
            }),
            ECVF_Default
        );

        InitializeSharedSamplerStates();
    }
    return *DeviceProfileManagerSingleton;
}

 

const FString UDeviceProfileManager::GetPlatformDeviceProfileName()
const FString UDeviceProfileManager::GetPlatformDeviceProfileName()
{
    FString ActiveProfileName = FPlatformProperties::PlatformName();

    // look for a commandline override (never even calls into the selector plugin)
    FString OverrideProfileName;
    if (FParse::Value(FCommandLine::Get(), TEXT("DeviceProfile="), OverrideProfileName) || FParse::Value(FCommandLine::Get(), TEXT("DP="), OverrideProfileName))
    {
        return OverrideProfileName;
    }

    // look for cvar override
    OverrideProfileName = CVarDeviceProfileOverride.GetValueOnGameThread();
    if (OverrideProfileName.Len() > 0)
    {
        return OverrideProfileName;
    }


    FString DeviceProfileSelectionModule;
    if (GConfig->GetString(TEXT("DeviceProfileManager"), TEXT("DeviceProfileSelectionModule"), DeviceProfileSelectionModule, GEngineIni))
    {
        if (IDeviceProfileSelectorModule* DPSelectorModule = FModuleManager::LoadModulePtr<IDeviceProfileSelectorModule>(*DeviceProfileSelectionModule))
        {
            ActiveProfileName = DPSelectorModule->GetRuntimeDeviceProfileName();
        }
    }

#if WITH_EDITOR
    if (FPIEPreviewDeviceModule::IsRequestingPreviewDevice())
    {
        IDeviceProfileSelectorModule* PIEPreviewDeviceProfileSelectorModule = FModuleManager::LoadModulePtr<IDeviceProfileSelectorModule>("PIEPreviewDeviceProfileSelector");
        if (PIEPreviewDeviceProfileSelectorModule)
        {
            FString PIEProfileName = PIEPreviewDeviceProfileSelectorModule->GetRuntimeDeviceProfileName();
            if (!PIEProfileName.IsEmpty())
            {
                ActiveProfileName = PIEProfileName;
            }
        }
    }
#endif
    return ActiveProfileName;
}

在UDeviceProfileManager::GetActiveDeviceProfileName()里也会调用到const FString UDeviceProfileManager::GetPlatformDeviceProfileName()函数。

调用到子类:
FString const FAndroidDeviceProfileSelectorRuntimeModule::GetRuntimeDeviceProfileName()
{
    static FString ProfileName;

#if PLATFORM_LUMIN
    if (ProfileName.IsEmpty())
    {
        // Fallback profiles in case we do not match any rules
        ProfileName = FPlatformMisc::GetDefaultDeviceProfileName();
        if (ProfileName.IsEmpty())
        {
            ProfileName = FPlatformProperties::PlatformName();
        }
    }

    // @todo Lumin: when removing this, also remove Lumin from the .uplugin
    UE_LOG(LogAndroid, Log, TEXT("Selected Device Profile: [%s]"), *ProfileName);
    return ProfileName;
#endif
    
    if (ProfileName.IsEmpty())
    {
        // Fallback profiles in case we do not match any rules
        ProfileName = FPlatformMisc::GetDefaultDeviceProfileName();
        if (ProfileName.IsEmpty())
        {
            ProfileName = FPlatformProperties::PlatformName();
        }

        FString GPUFamily = FAndroidMisc::GetGPUFamily();
        FString GLVersion = FAndroidMisc::GetGLVersion();

        FString VulkanVersion = FAndroidMisc::GetVulkanVersion();
        FString VulkanAvailable = FAndroidMisc::IsVulkanAvailable() ? TEXT("true") : TEXT("false");
        FString AndroidVersion = FAndroidMisc::GetAndroidVersion();
        FString DeviceMake = FAndroidMisc::GetDeviceMake();
        FString DeviceModel = FAndroidMisc::GetDeviceModel();
        FString DeviceBuildNumber = FAndroidMisc::GetDeviceBuildNumber();
        
        FString Hardware = FString(TEXT("unknown"));
        FString Chipset = FString(TEXT("unknown"));
        FString *HardwareLookup = FAndroidMisc::GetConfigRulesVariable(TEXT("hardware"));
        if (HardwareLookup != nullptr)
        {
            Hardware = *HardwareLookup;
        }
        FString *ChipsetLookup = FAndroidMisc::GetConfigRulesVariable(TEXT("chipset"));
        if (ChipsetLookup != nullptr)
        {
            Chipset = *ChipsetLookup;
        }

#if !(PLATFORM_ANDROID_X86 || PLATFORM_ANDROID_X64)
        // Not running an Intel libUE4.so with Houdini library present means we're emulated
        bool bUsingHoudini = (access("/system/lib/libhoudini.so", F_OK) != -1);
#else
        bool bUsingHoudini = false;
#endif
        FString UsingHoudini = bUsingHoudini ? TEXT("true") : TEXT("false");

        UE_LOG(LogAndroid, Log, TEXT("Checking %d rules from DeviceProfile ini file."), FAndroidDeviceProfileSelector::GetNumProfiles() );
        UE_LOG(LogAndroid, Log, TEXT("  Default profile: %s"), * ProfileName);
        UE_LOG(LogAndroid, Log, TEXT("  GpuFamily: %s"), *GPUFamily);
        UE_LOG(LogAndroid, Log, TEXT("  GlVersion: %s"), *GLVersion);
        UE_LOG(LogAndroid, Log, TEXT("  VulkanAvailable: %s"), *VulkanAvailable);
        UE_LOG(LogAndroid, Log, TEXT("  VulkanVersion: %s"), *VulkanVersion);
        UE_LOG(LogAndroid, Log, TEXT("  AndroidVersion: %s"), *AndroidVersion);
        UE_LOG(LogAndroid, Log, TEXT("  DeviceMake: %s"), *DeviceMake);
        UE_LOG(LogAndroid, Log, TEXT("  DeviceModel: %s"), *DeviceModel);
        UE_LOG(LogAndroid, Log, TEXT("  DeviceBuildNumber: %s"), *DeviceBuildNumber);
        UE_LOG(LogAndroid, Log, TEXT("  UsingHoudini: %s"), *UsingHoudini);
        UE_LOG(LogAndroid, Log, TEXT("  Hardware: %s"), *Hardware);
        UE_LOG(LogAndroid, Log, TEXT("  Chipset: %s"), *Chipset);

        CheckForJavaSurfaceViewWorkaround(DeviceMake, DeviceModel);

        // Use override from ConfigRules if set
        FString* ConfigProfile = FAndroidMisc::GetConfigRulesVariable(TEXT("Profile"));
        if (ConfigProfile != nullptr)
        {
            ProfileName = *ConfigProfile;
            UE_LOG(LogAndroid, Log, TEXT("Using ConfigRules Profile: [%s]"), *ProfileName);
        }
        else
        {
            // Find a match with the DeviceProfiles matching rules
            ProfileName = FAndroidDeviceProfileSelector::FindMatchingProfile(GPUFamily, GLVersion, AndroidVersion, DeviceMake, DeviceModel, DeviceBuildNumber, VulkanAvailable, VulkanVersion, UsingHoudini, Hardware, Chipset, ProfileName);
            UE_LOG(LogAndroid, Log, TEXT("Selected Device Profile: [%s]"), *ProfileName);
        }
    }

    return ProfileName;
}

 

 

getDeviceProfileName()函数:CheckAndroidDeviceProfileCommandlet.cpp里,测试这个。

在baseDeviceProfiles.ini文件里,有所有的profile名和其对应的类型:

[DeviceProfiles]
+DeviceProfileNameAndTypes=Windows,Windows
+DeviceProfileNameAndTypes=WindowsNoEditor,Windows
+DeviceProfileNameAndTypes=WindowsServer,Windows
+DeviceProfileNameAndTypes=WindowsClient,Windows
+DeviceProfileNameAndTypes=IOS,IOS
+DeviceProfileNameAndTypes=iPadAir,IOS