Skip to content

Commit

Permalink
Merge pull request #227 from markuskreukniet/use-gl-fallback
Browse files Browse the repository at this point in the history
Identifying a possible stable 'use-gl' implementation across systems
  • Loading branch information
hmlendea authored Mar 14, 2024
2 parents 0e847e9 + 9c4f015 commit 27c5566
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "geforcenow-electron",
"appId": "com.github.hmlendea.${name}",
"productName": "GeForce NOW",
"version": "2.0.2",
"version": "2.1.0",
"description": "A Linux desktop web app for GeForce NOW",
"main": "scripts/main.js",
"scripts": {
Expand Down
46 changes: 43 additions & 3 deletions scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { app, globalShortcut, BrowserWindow, session } = require('electron');
const findProcess = require('find-process');
const fs = require('fs');
const path = require('path');
const { DiscordRPC } = require('./rpc.js');
const { switchFullscreenState } = require('./windowManager.js');
Expand All @@ -23,9 +24,36 @@ app.commandLine.appendSwitch('enable-native-gpu-memory-buffers');
app.commandLine.appendSwitch('enable-gpu-rasterization');
app.commandLine.appendSwitch('enable-zero-copy');
app.commandLine.appendSwitch('enable-gpu-memory-buffer-video-frames');
// TODO: This is going to depend per user, so we need to find a way to detect this
// egl should be a safe bet for now, as it allows for hardware video decode on most systems
app.commandLine.appendSwitch('use-gl', 'egl');

// To identify a possible stable 'use-gl' switch implementation for our application, we utilize a config file that stores the number of crashes.
// On Linux, the crash count is likely stored here: /home/[username]/.config/GeForce NOW/config.json.
// To reset the crash count, we can delete that file.

// If the 'use-gl' switch with the 'angle' implementation crashes, the app will then use the 'egl' implementation.
// If the 'egl' implementation also crashes, the app will disable hardware acceleration.

// When I try to use the 'use-gl' switch with 'desktop' or 'swiftshader', it results in an error indicating that these options are not among the permitted implementations.
// It's possible that future versions of Electron may introduce support for 'desktop' and 'swiftshader' implementations.

// Based on my current understanding (which may be incorrect), the 'angle' implementation is preferred due to its utilization of 'OpenGL ES', which ensures consistent behavior across different systems, such as Windows and Linux systems.
// Furthermore, 'angle' includes an additional abstraction layer that could potentially mitigate bugs or circumvent limitations inherent in direct implementations.

// When the 'use-gl' switch is functioning correctly, I still encounter the 'GetVSyncParametersIfAvailable() error' three times, but it does not occur thereafter (based on my testing).
const configPath = path.join(app.getPath('userData'), 'config.json');
const config = fs.existsSync(configPath) ?
JSON.parse(fs.readFileSync(configPath, 'utf-8')) :
{ crashCount: 0 };

switch(config.crashCount) {
case 0:
app.commandLine.appendSwitch('use-gl', 'angle');
break;
case 1:
app.commandLine.appendSwitch('use-gl', 'egl');
break;
default:
app.disableHardwareAcceleration();
}

async function createWindow() {
const mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -144,6 +172,18 @@ app.on('browser-window-created', async function (e, window) {
}
});

app.on('child-process-gone', (event, details) => {
if (details.type === 'GPU' && details.reason === 'crashed') {
config.crashCount++;
fs.writeFileSync(configPath, JSON.stringify(config));

console.log("Initiating application restart with an alternative 'use-gl' switch implementation or with hardware acceleration disabled, aiming to improve stability or performance based on prior execution outcomes.");

app.relaunch();
app.exit(0);
}
});

app.on('will-quit', async () => {
globalShortcut.unregisterAll();
});
Expand Down

0 comments on commit 27c5566

Please sign in to comment.