Skip to content

Commit 35efa86

Browse files
committed
Merge remote-tracking branch 'taranasus/feature/configurable-windowless-framerate'
2 parents beb2df2 + 5a7d276 commit 35efa86

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

src/Packages/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ public Resolution Resolution
130130
/// </summary>
131131
[Tooltip("Proxy settings")] public ProxySettings proxySettings;
132132

133+
/// <summary>
134+
/// Target framerate for the browser rendering (1-60 FPS).
135+
/// Higher values provide smoother video playback but use more CPU.
136+
/// </summary>
137+
[Header("Performance")]
138+
[Tooltip("Target framerate for browser rendering (1-60). Higher = smoother but more CPU.")]
139+
[Range(1, 60)]
140+
public int windowlessFrameRate = 30;
141+
133142
/// <summary>
134143
/// Enable or disable WebRTC
135144
/// </summary>
@@ -377,6 +386,9 @@ public void Init()
377386
argsBuilder.AppendArgument("width", resolution.Width);
378387
argsBuilder.AppendArgument("height", resolution.Height);
379388

389+
//Windowless frame rate
390+
argsBuilder.AppendArgument("windowless-frame-rate", windowlessFrameRate);
391+
380392
//Javascript
381393
argsBuilder.AppendArgument("javascript", javascript);
382394

src/UnityWebBrowser.Engine.Cef/Main/Core/CefEngineControlsManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,16 @@ public void Init(ClientControlsActions clientControlsActions, EnginePopupManager
198198
//Create our CEF browser settings
199199
Color suppliedColor = launchArguments.BackgroundColor;
200200
CefColor backgroundColor = new(suppliedColor.A, suppliedColor.R, suppliedColor.G, suppliedColor.B);
201+
202+
//Clamp framerate to valid CEF range (1-60)
203+
int frameRate = Math.Clamp(launchArguments.WindowlessFrameRate, 1, 60);
204+
201205
CefBrowserSettings cefBrowserSettings = new()
202206
{
203207
BackgroundColor = backgroundColor,
204208
JavaScript = launchArguments.JavaScript ? CefState.Enabled : CefState.Disabled,
205-
LocalStorage = launchArguments.LocalStorage ? CefState.Enabled : CefState.Disabled
209+
LocalStorage = launchArguments.LocalStorage ? CefState.Enabled : CefState.Disabled,
210+
WindowlessFrameRate = frameRate
206211
};
207212

208213
mainLogger.LogDebug($"Starting CEF with these options:" +
@@ -212,6 +217,7 @@ public void Init(ClientControlsActions clientControlsActions, EnginePopupManager
212217
$"\nBackgroundColor: {suppliedColor}" +
213218
$"\nCache Path: {cachePath}" +
214219
$"\nPopup Action: {launchArguments.PopupAction}" +
220+
$"\nWindowless Frame Rate: {frameRate}" +
215221
$"\nLog Path: {launchArguments.LogPath.FullName}" +
216222
$"\nLog Severity: {launchArguments.LogSeverity}");
217223
mainLogger.LogInformation($"Starting CEF client...");

src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/LaunchArguments.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,10 @@ public class LaunchArguments
134134
/// Start delay. Used for testing reasons.
135135
/// </summary>
136136
internal uint StartDelay { get; set; }
137+
138+
/// <summary>
139+
/// The target framerate for windowless rendering (1-60 FPS).
140+
/// Default is 30 FPS.
141+
/// </summary>
142+
public int WindowlessFrameRate { get; init; }
137143
}

src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/LaunchArgumentsBinder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal class LaunchArgumentsBinder : BinderBase<LaunchArguments>
2424
private readonly Option<int> height;
2525

2626
//General browser settings
27+
private readonly Option<int> windowlessFrameRate;
2728
private readonly Option<bool> javaScript;
2829
private readonly Option<bool> webRtc;
2930
private readonly Option<bool> localStorage;
@@ -62,8 +63,9 @@ public LaunchArgumentsBinder(
6263
Option<string> initialUrl,
6364
Option<int> width,
6465
Option<int> height,
66+
Option<int> windowlessFrameRate,
6567
Option<bool> javaScript,
66-
Option<bool> webRtc,
68+
Option<bool> webRtc,
6769
Option<bool> localStorage,
6870
Option<int> remoteDebugging,
6971
Option<string[]> remoteDebuggingAllowedOrigins,
@@ -87,7 +89,8 @@ public LaunchArgumentsBinder(
8789
this.initialUrl = initialUrl;
8890
this.width = width;
8991
this.height = height;
90-
92+
93+
this.windowlessFrameRate = windowlessFrameRate;
9194
this.javaScript = javaScript;
9295
this.webRtc = webRtc;
9396
this.localStorage = localStorage;
@@ -126,6 +129,7 @@ protected override LaunchArguments GetBoundValue(BindingContext bindingContext)
126129
Width = bindingContext.ParseResult.GetValueForOption(width),
127130
Height = bindingContext.ParseResult.GetValueForOption(height),
128131

132+
WindowlessFrameRate = bindingContext.ParseResult.GetValueForOption(windowlessFrameRate),
129133
JavaScript = bindingContext.ParseResult.GetValueForOption(javaScript),
130134
WebRtc = bindingContext.ParseResult.GetValueForOption(webRtc),
131135
LocalStorage = bindingContext.ParseResult.GetValueForOption(localStorage),

src/VoltstroStudios.UnityWebBrowser.Engine.Shared/Core/LaunchArgumentsParser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public LaunchArgumentsParser()
3535
"The height of the window");
3636

3737
//General browser settings
38+
Option<int> windowlessFrameRate = new("-windowless-frame-rate",
39+
() => 30,
40+
"Target framerate for windowless rendering (1-60). Default is 30.");
3841
Option<bool> javaScript = new("-javascript",
3942
() => true,
4043
"Enable or disable javascript");
@@ -117,6 +120,7 @@ public LaunchArgumentsParser()
117120
initialUrl,
118121
width,
119122
height,
123+
windowlessFrameRate,
120124
javaScript,
121125
webRtc,
122126
localStorage,
@@ -147,6 +151,7 @@ public LaunchArgumentsParser()
147151
initialUrl,
148152
width,
149153
height,
154+
windowlessFrameRate,
150155
javaScript,
151156
webRtc,
152157
localStorage,

0 commit comments

Comments
 (0)