Skip to content

Commit bfdfdb5

Browse files
authored
Add main menu setting for browser GPU rendering (#3816)
* Adds browser_enable_gpu and browser_enable_gpu_compositing CVARS * Adds options to "web browser" tab in main menu settings * Add isBrowserGPUEnabled lua definition (clientside)
1 parent 64747aa commit bfdfdb5

File tree

10 files changed

+97
-5
lines changed

10 files changed

+97
-5
lines changed

Client/cefweb/CWebApp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ CefRefPtr<CefResourceHandler> CWebApp::HandleError(const SString& strError, unsi
2121

2222
void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
2323
{
24+
CWebCore* pWebCore = static_cast<CWebCore*>(g_pCore->GetWebCore());
25+
26+
if (!pWebCore->GetGPUEnabled()) // if GPU is disabled...
27+
{
28+
command_line->AppendSwitch("disable-gpu-compositing");
29+
command_line->AppendSwitch("disable-gpu");
30+
}
31+
else if (!pWebCore->GetGPUCompositingEnabled()) // if GPU is enabled, but compositing is disabled...
32+
command_line->AppendSwitch("disable-gpu-compositing");
33+
2434
// command_line->AppendSwitch("disable-d3d11");
2535
command_line->AppendSwitch("enable-begin-frame-scheduling");
2636

Client/cefweb/CWebCore.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ CWebCore::~CWebCore()
4949
delete m_pXmlConfig;
5050
}
5151

52-
bool CWebCore::Initialise()
52+
bool CWebCore::Initialise(bool gpuEnabled, bool gpuCompositingEnabled)
5353
{
5454
CefMainArgs mainArgs;
5555
void* sandboxInfo = nullptr;
56+
57+
m_bGPUEnabled = gpuEnabled;
58+
m_bGPUCompositingEnabled = gpuCompositingEnabled;
59+
5660
CefRefPtr<CWebApp> app(new CWebApp);
5761

5862
#ifdef CEF_ENABLE_SANDBOX
@@ -869,3 +873,13 @@ void CWebCore::StaticFetchBlacklistFinished(const SHttpDownloadResult& result)
869873
OutputDebugLine("Updated browser blacklist!");
870874
#endif
871875
}
876+
877+
bool CWebCore::GetGPUEnabled() const noexcept
878+
{
879+
return m_bGPUEnabled;
880+
}
881+
882+
bool CWebCore::GetGPUCompositingEnabled() const noexcept
883+
{
884+
return m_bGPUCompositingEnabled;
885+
}

Client/cefweb/CWebCore.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CWebCore : public CWebCoreInterface
5454
public:
5555
CWebCore();
5656
~CWebCore();
57-
bool Initialise() override;
57+
bool Initialise(bool gpuEnabled, bool gpuCompositingEnabled) override;
5858

5959
CWebViewInterface* CreateWebView(unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem, bool bTransparent);
6060
void DestroyWebView(CWebViewInterface* pWebViewInterface);
@@ -108,6 +108,9 @@ class CWebCore : public CWebCoreInterface
108108
static void StaticFetchWhitelistFinished(const SHttpDownloadResult& result);
109109
static void StaticFetchBlacklistFinished(const SHttpDownloadResult& result);
110110

111+
bool GetGPUEnabled() const noexcept;
112+
bool GetGPUCompositingEnabled() const noexcept;
113+
111114
private:
112115
typedef std::pair<bool, eWebFilterType> WebFilterPair;
113116

@@ -129,4 +132,8 @@ class CWebCore : public CWebCoreInterface
129132
CXMLFile* m_pXmlConfig;
130133
int m_iWhitelistRevision;
131134
int m_iBlacklistRevision;
135+
136+
// Shouldn't be changed after init
137+
bool m_bGPUEnabled;
138+
bool m_bGPUCompositingEnabled;
132139
};

Client/core/CClientVariables.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ void CClientVariables::LoadDefaults()
358358
DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing
359359
DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time
360360
DEFAULT("_beta_qc_rightclick_command", _S("reconnect")); // Command to run when right clicking quick connect (beta - can be removed at any time)
361+
DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function)
362+
DEFAULT("browser_enable_gpu_compositing", true); // Enable GPU compositing in CEF? (required GPU enabled)
361363

362364
if (!Exists("locale"))
363365
{

Client/core/CCore.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,14 @@ CWebCoreInterface* CCore::GetWebCore()
11551155
{
11561156
if (m_pWebCore == nullptr)
11571157
{
1158+
bool gpuEnabled;
1159+
bool gpuCompositingEnabled;
1160+
auto cvars = g_pCore->GetCVars();
1161+
cvars->Get("browser_enable_gpu", gpuEnabled);
1162+
cvars->Get("browser_enable_gpu_compositing", gpuCompositingEnabled);
1163+
11581164
m_pWebCore = CreateModule<CWebCoreInterface>(m_WebCoreModule, "CefWeb", "cefweb", "InitWebCoreInterface", this);
1159-
m_pWebCore->Initialise();
1165+
m_pWebCore->Initialise(gpuEnabled, gpuCompositingEnabled);
11601166
}
11611167
return m_pWebCore;
11621168
}

Client/core/CSettings.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,16 @@ void CSettings::CreateGUI()
917917
m_pCheckBoxRemoteJavascript->GetPosition(vecTemp);
918918
m_pCheckBoxRemoteJavascript->AutoSize(NULL, 20.0f);
919919

920+
m_pCheckBoxBrowserGPUEnabled = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(m_pTabBrowser, _("Enable GPU rendering"), true));
921+
m_pCheckBoxBrowserGPUEnabled->SetPosition(CVector2D(vecTemp.fX + 300.0f, vecTemp.fY - 20.0f));
922+
m_pCheckBoxBrowserGPUEnabled->AutoSize(NULL, 20.0f);
923+
m_pCheckBoxBrowserGPUEnabled->SetClickHandler(GUI_CALLBACK(&CSettings::OnGPUSettingChanged, this));
924+
925+
m_pCheckBoxBrowserGPUCompositingEnabled =
926+
reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(m_pTabBrowser, _("Enable GPU compositing"), true));
927+
m_pCheckBoxBrowserGPUCompositingEnabled->SetPosition(CVector2D(vecTemp.fX + 300.0f, vecTemp.fY));
928+
m_pCheckBoxBrowserGPUCompositingEnabled->AutoSize(NULL, 20.0f);
929+
920930
m_pLabelBrowserCustomBlacklist = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTabBrowser, _("Custom blacklist")));
921931
m_pLabelBrowserCustomBlacklist->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 30.0f));
922932
m_pLabelBrowserCustomBlacklist->GetPosition(vecTemp);
@@ -3287,6 +3297,14 @@ void CSettings::LoadData()
32873297
m_pCheckBoxRemoteBrowser->SetSelected(bVar);
32883298
CVARS_GET("browser_remote_javascript", bVar);
32893299
m_pCheckBoxRemoteJavascript->SetSelected(bVar);
3300+
CVARS_GET("browser_enable_gpu", bVar);
3301+
m_pCheckBoxBrowserGPUEnabled->SetSelected(bVar);
3302+
3303+
if (!bVar)
3304+
m_pCheckBoxBrowserGPUCompositingEnabled->SetEnabled(false);
3305+
3306+
CVARS_GET("browser_enable_gpu_compositing", bVar);
3307+
m_pCheckBoxBrowserGPUCompositingEnabled->SetSelected(bVar);
32903308

32913309
ReloadBrowserLists();
32923310
}
@@ -3711,6 +3729,20 @@ void CSettings::SaveData()
37113729
bBrowserSettingChanged = true;
37123730
}
37133731

3732+
bool bBrowserGPUEnabled = false;
3733+
CVARS_GET("browser_enable_gpu", bBrowserGPUEnabled);
3734+
3735+
bool bBrowserGPUSetting = m_pCheckBoxBrowserGPUEnabled->GetSelected();
3736+
bool bBrowserGPUSettingChanged = (bBrowserGPUSetting != bBrowserGPUEnabled);
3737+
CVARS_SET("browser_enable_gpu", bBrowserGPUSetting);
3738+
3739+
bool bBrowserGPUCompositingEnabled = false;
3740+
CVARS_GET("browser_enable_gpu_compositing", bBrowserGPUCompositingEnabled);
3741+
3742+
bool bBrowserGPUCompositingSetting = m_pCheckBoxBrowserGPUCompositingEnabled->GetSelected();
3743+
bool bBrowserGPUCompositingSettingChanged = (bBrowserGPUCompositingSetting != bBrowserGPUCompositingEnabled);
3744+
CVARS_SET("browser_enable_gpu_compositing", bBrowserGPUCompositingSetting);
3745+
37143746
// Ensure CVARS ranges ok
37153747
CClientVariables::GetSingleton().ValidateValues();
37163748

@@ -3720,7 +3752,8 @@ void CSettings::SaveData()
37203752
gameSettings->Save();
37213753

37223754
// Ask to restart?
3723-
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged)
3755+
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged || bBrowserGPUSettingChanged ||
3756+
bBrowserGPUCompositingSettingChanged)
37243757
ShowRestartQuestion();
37253758
else if (CModManager::GetSingleton().IsLoaded() && bBrowserSettingChanged)
37263759
ShowDisconnectQuestion();
@@ -4873,3 +4906,9 @@ bool CSettings::IsActive()
48734906
{
48744907
return m_pWindow->IsActive();
48754908
}
4909+
4910+
bool CSettings::OnGPUSettingChanged(CGUIElement* pElement)
4911+
{
4912+
m_pCheckBoxBrowserGPUCompositingEnabled->SetEnabled(m_pCheckBoxBrowserGPUEnabled->GetSelected());
4913+
return true;
4914+
}

Client/core/CSettings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ class CSettings
338338
CGUIButton* m_pButtonBrowserWhitelistAdd;
339339
CGUIGridList* m_pGridBrowserWhitelist;
340340
CGUIButton* m_pButtonBrowserWhitelistRemove;
341+
CGUICheckBox* m_pCheckBoxBrowserGPUEnabled;
342+
CGUICheckBox* m_pCheckBoxBrowserGPUCompositingEnabled;
341343
bool m_bBrowserListsChanged;
342344
bool m_bBrowserListsLoadEnabled;
343345

@@ -382,6 +384,7 @@ class CSettings
382384
bool OnBrowserWhitelistRemove(CGUIElement* pElement);
383385
bool OnBrowserWhitelistDomainAddFocused(CGUIElement* pElement);
384386
bool OnBrowserWhitelistDomainAddDefocused(CGUIElement* pElement);
387+
bool OnGPUSettingChanged(CGUIElement* pElement);
385388

386389
bool OnMouseDoubleClick(CGUIMouseEventArgs Args);
387390

Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void CLuaBrowserDefs::LoadFunctions()
4949
{"resizeBrowser", ResizeBrowser},
5050
{"guiCreateBrowser", GUICreateBrowser},
5151
{"guiGetBrowser", GUIGetBrowser},
52+
{"isBrowserGPUEnabled", ArgumentParser<IsBrowserGPUEnabled>},
5253
};
5354

5455
// Add browser functions
@@ -97,6 +98,7 @@ void CLuaBrowserDefs::AddClass(lua_State* luaVM)
9798
lua_classvariable(luaVM, "renderingPaused", "setBrowserRenderingPaused", "isBrowserRenderingPaused");
9899
lua_classvariable(luaVM, "volume", "setBrowserVolume", "getBrowserVolume");
99100
lua_classvariable(luaVM, "devTools", "toggleBrowserDevTools", nullptr);
101+
lua_classvariable(luaVM, "gpuEnabled", nullptr, "isBrowserGPUEnabled");
100102

101103
lua_registerclass(luaVM, "Browser", "DxTexture");
102104

@@ -1054,3 +1056,8 @@ int CLuaBrowserDefs::SetBrowserAjaxHandler(lua_State* luaVM)
10541056
lua_pushboolean(luaVM, false);
10551057
return 1;
10561058
}
1059+
1060+
bool CLuaBrowserDefs::IsBrowserGPUEnabled() noexcept
1061+
{
1062+
return g_pCore->GetWebCore()->GetGPUEnabled();
1063+
}

Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ class CLuaBrowserDefs : public CLuaDefs
5151
LUA_DECLARE(ResizeBrowser);
5252
LUA_DECLARE(GUICreateBrowser);
5353
LUA_DECLARE(GUIGetBrowser);
54+
static bool IsBrowserGPUEnabled() noexcept;
5455
};

Client/sdk/core/CWebCoreInterface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CWebCoreInterface
4949
{
5050
public:
5151
virtual ~CWebCoreInterface() {}
52-
virtual bool Initialise() = 0;
52+
virtual bool Initialise(bool gpuEnabled, bool gpuCompositingEnabled) = 0;
5353

5454
virtual CWebViewInterface* CreateWebView(unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem,
5555
bool bTransparent) = 0;
@@ -90,4 +90,7 @@ class CWebCoreInterface
9090
virtual void WriteCustomList(const SString& strListName, const std::vector<SString>& customList, bool bReset = true) = 0;
9191
virtual void GetFilterEntriesByType(std::vector<std::pair<SString, bool>>& outEntries, eWebFilterType filterType,
9292
eWebFilterState state = eWebFilterState::WEBFILTER_ALL) = 0;
93+
94+
virtual bool GetGPUEnabled() const noexcept = 0;
95+
virtual bool GetGPUCompositingEnabled() const noexcept = 0;
9396
};

0 commit comments

Comments
 (0)