Skip to content

Commit b73f9ec

Browse files
author
Benjamin Pasero
committed
Add a setting to disable gpu acceleration (fixes microsoft#15211)
1 parent 841d897 commit b73f9ec

7 files changed

Lines changed: 134 additions & 9 deletions

File tree

extensions/configuration-editing/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"launch.json",
3838
"tasks.json",
3939
"keybindings.json",
40-
"extensions.json"
40+
"extensions.json",
41+
"argv.json"
4142
]
4243
}
4344
],

src/main.js

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const lp = require('./vs/base/node/languagePacks');
1212
perf.mark('main:started');
1313

1414
const path = require('path');
15+
const fs = require('fs');
16+
const os = require('os');
1517
const bootstrap = require('./bootstrap');
1618
const paths = require('./paths');
1719
// @ts-ignore
@@ -113,16 +115,97 @@ async function onReady() {
113115
*/
114116
function configureCommandlineSwitches(cliArgs) {
115117

116-
// Force pre-Chrome-60 color profile handling (for https://github.com/Microsoft/vscode/issues/51791)
117-
app.commandLine.appendSwitch('disable-color-correct-rendering');
118+
// Read argv config
119+
const argvConfig = readArgvConfig();
120+
121+
// Append each flag to Electron
122+
Object.keys(argvConfig).forEach(flag => {
123+
const value = argvConfig[flag];
124+
if (value === true || value === 'true') {
125+
if (flag === 'disable-gpu') {
126+
app.disableHardwareAcceleration(); // needs to be called explicitly
127+
}
128+
129+
app.commandLine.appendArgument(flag);
130+
} else {
131+
app.commandLine.appendSwitch(flag, value);
132+
}
133+
});
118134

119135
// Support JS Flags
120136
const jsFlags = getJSFlags(cliArgs);
121137
if (jsFlags) {
122-
app.commandLine.appendSwitch('--js-flags', jsFlags);
138+
app.commandLine.appendSwitch('js-flags', jsFlags);
123139
}
124140
}
125141

142+
function readArgvConfig() {
143+
144+
// Read or create the argv.json config file sync before app('ready')
145+
const argvConfigPath = getArgvConfigPath();
146+
let argvConfig;
147+
try {
148+
argvConfig = JSON.parse(stripComments(fs.readFileSync(argvConfigPath).toString()));
149+
} catch (error) {
150+
if (error && error.code === 'ENOENT') {
151+
try {
152+
const argvConfigPathDirname = path.dirname(argvConfigPath);
153+
if (!fs.existsSync(argvConfigPathDirname)) {
154+
fs.mkdirSync(argvConfigPathDirname);
155+
}
156+
157+
// Create initial argv.json if not existing
158+
fs.writeFileSync(argvConfigPath, `// This configuration file allows to pass permanent command line arguments to VSCode.
159+
//
160+
// PLEASE DO NOT CHANGE WITHOUT UNDERSTANDING THE IMPACT
161+
//
162+
// If the command line argument does not have any values, simply assign
163+
// it in the JSON below with a value of 'true'. Otherwise, put the value
164+
// directly.
165+
//
166+
// If you see rendering issues in VSCode and have a better experience
167+
// with software rendering, you can configure this by adding:
168+
//
169+
// 'disable-gpu': true
170+
//
171+
// NOTE: Changing this file requires a restart of VSCode.
172+
{
173+
// Enabled by default by VSCode to resolve color issues in the renderer
174+
// See https://github.com/Microsoft/vscode/issues/51791 for details
175+
"disable-color-correct-rendering": true
176+
}`);
177+
} catch (error) {
178+
console.error(`Unable to create argv.json configuration file in ${argvConfigPath}, falling back to defaults (${error})`);
179+
}
180+
} else {
181+
console.warn(`Unable to read argv.json configuration file in ${argvConfigPath}, falling back to defaults (${error})`);
182+
}
183+
}
184+
185+
// Fallback to default
186+
if (!argvConfig) {
187+
argvConfig = {
188+
'disable-color-correct-rendering': true // Force pre-Chrome-60 color profile handling (for https://github.com/Microsoft/vscode/issues/51791)
189+
};
190+
}
191+
192+
return argvConfig;
193+
}
194+
195+
function getArgvConfigPath() {
196+
const vscodePortable = process.env['VSCODE_PORTABLE'];
197+
if (vscodePortable) {
198+
return path.join(vscodePortable, 'argv.json');
199+
}
200+
201+
let dataFolderName = product.dataFolderName;
202+
if (process.env['VSCODE_DEV']) {
203+
dataFolderName = `${dataFolderName}-dev`;
204+
}
205+
206+
return path.join(os.homedir(), dataFolderName, 'argv.json');
207+
}
208+
126209
/**
127210
* @param {ParsedArgs} cliArgs
128211
* @returns {string}

src/vs/platform/environment/common/environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export interface IEnvironmentService {
116116
keybindingsResource: URI;
117117
keyboardLayoutResource: URI;
118118
localeResource: URI;
119+
argvResource: URI;
119120

120121
// sync resources
121122
userDataSyncLogResource: URI;

src/vs/platform/environment/node/environmentService.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export class EnvironmentService implements IEnvironmentService {
9595
@memoize
9696
get userDataPath(): string {
9797
const vscodePortable = process.env['VSCODE_PORTABLE'];
98-
9998
if (vscodePortable) {
10099
return path.join(vscodePortable, 'user-data');
101100
}
@@ -143,6 +142,16 @@ export class EnvironmentService implements IEnvironmentService {
143142
@memoize
144143
get localeResource(): URI { return resources.joinPath(this.userRoamingDataHome, 'locale.json'); }
145144

145+
@memoize
146+
get argvResource(): URI {
147+
const vscodePortable = process.env['VSCODE_PORTABLE'];
148+
if (vscodePortable) {
149+
return URI.file(path.join(vscodePortable, 'argv.json'));
150+
}
151+
152+
return URI.file(path.join(this.userHome, product.dataFolderName, 'argv.json'));
153+
}
154+
146155
@memoize
147156
get isExtensionDevelopment(): boolean { return !!this._args.extensionDevelopmentPath; }
148157

@@ -182,7 +191,6 @@ export class EnvironmentService implements IEnvironmentService {
182191
}
183192

184193
const vscodePortable = process.env['VSCODE_PORTABLE'];
185-
186194
if (vscodePortable) {
187195
return path.join(vscodePortable, 'extensions');
188196
}

src/vs/workbench/electron-browser/actions/developerActions.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import { Action } from 'vs/base/common/actions';
77
import * as nls from 'vs/nls';
88
import { IElectronService } from 'vs/platform/electron/node/electron';
99
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
10+
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
11+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1012

1113
export class ToggleDevToolsAction extends Action {
1214

1315
static readonly ID = 'workbench.action.toggleDevTools';
1416
static readonly LABEL = nls.localize('toggleDevTools', "Toggle Developer Tools");
1517

16-
constructor(id: string, label: string, @IElectronService private readonly electronService: IElectronService) {
18+
constructor(
19+
id: string,
20+
label: string,
21+
@IElectronService private readonly electronService: IElectronService
22+
) {
1723
super(id, label);
1824
}
1925

@@ -27,11 +33,34 @@ export class ToggleSharedProcessAction extends Action {
2733
static readonly ID = 'workbench.action.toggleSharedProcess';
2834
static readonly LABEL = nls.localize('toggleSharedProcess', "Toggle Shared Process");
2935

30-
constructor(id: string, label: string, @ISharedProcessService private readonly sharedProcessService: ISharedProcessService) {
36+
constructor(
37+
id: string,
38+
label: string,
39+
@ISharedProcessService private readonly sharedProcessService: ISharedProcessService
40+
) {
3141
super(id, label);
3242
}
3343

3444
run(): Promise<void> {
3545
return this.sharedProcessService.toggleSharedProcessWindow();
3646
}
3747
}
48+
49+
export class ConfigureRuntimeArgumentsAction extends Action {
50+
51+
static readonly ID = 'workbench.action.configureRuntimeArguments';
52+
static readonly LABEL = nls.localize('configureRuntimeArguments', "Configure Runtime Arguments");
53+
54+
constructor(
55+
id: string,
56+
label: string,
57+
@IEnvironmentService private readonly environmentService: IEnvironmentService,
58+
@IEditorService private readonly editorService: IEditorService
59+
) {
60+
super(id, label);
61+
}
62+
63+
async run(): Promise<void> {
64+
await this.editorService.openEditor({ resource: this.environmentService.argvResource });
65+
}
66+
}

src/vs/workbench/electron-browser/desktop.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions, Configur
1111
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
1212
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
1313
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
14-
import { ToggleSharedProcessAction, ToggleDevToolsAction } from 'vs/workbench/electron-browser/actions/developerActions';
14+
import { ToggleSharedProcessAction, ToggleDevToolsAction, ConfigureRuntimeArgumentsAction } from 'vs/workbench/electron-browser/actions/developerActions';
1515
import { ZoomResetAction, ZoomOutAction, ZoomInAction, CloseCurrentWindowAction, SwitchWindow, QuickSwitchWindow, ReloadWindowWithExtensionsDisabledAction, NewWindowTabHandler, ShowPreviousWindowTabHandler, ShowNextWindowTabHandler, MoveWindowTabToNewWindowHandler, MergeWindowTabsHandlerHandler, ToggleWindowTabsBarHandler } from 'vs/workbench/electron-browser/actions/windowActions';
1616
import { SaveWorkspaceAsAction, DuplicateWorkspaceInNewWindowAction } from 'vs/workbench/electron-browser/actions/workspaceActions';
1717
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
@@ -98,6 +98,7 @@ import { IElectronService } from 'vs/platform/electron/node/electron';
9898
(function registerDeveloperActions(): void {
9999
const developerCategory = nls.localize('developer', "Developer");
100100
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSharedProcessAction, ToggleSharedProcessAction.ID, ToggleSharedProcessAction.LABEL), 'Developer: Toggle Shared Process', developerCategory);
101+
registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureRuntimeArgumentsAction, ConfigureRuntimeArgumentsAction.ID, ConfigureRuntimeArgumentsAction.LABEL), 'Developer: Configure Runtime Arguments', developerCategory);
101102
registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowWithExtensionsDisabledAction, ReloadWindowWithExtensionsDisabledAction.ID, ReloadWindowWithExtensionsDisabledAction.LABEL), 'Developer: Reload With Extensions Disabled', developerCategory);
102103
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL), 'Developer: Toggle Developer Tools', developerCategory);
103104

src/vs/workbench/services/environment/browser/environmentService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
8989
this.keybindingsResource = joinPath(this.userRoamingDataHome, 'keybindings.json');
9090
this.keyboardLayoutResource = joinPath(this.userRoamingDataHome, 'keyboardLayout.json');
9191
this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
92+
this.argvResource = joinPath(this.userRoamingDataHome, 'argv.json');
9293
this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
9394
this.configuration.backupWorkspaceResource = joinPath(this.backupHome, options.workspaceId);
9495
this.configuration.connectionToken = options.connectionToken || getCookieValue('vscode-tkn');
@@ -146,6 +147,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
146147
keybindingsResource: URI;
147148
keyboardLayoutResource: URI;
148149
localeResource: URI;
150+
argvResource: URI;
149151
settingsSyncPreviewResource: URI;
150152
userDataSyncLogResource: URI;
151153
machineSettingsHome: URI;

0 commit comments

Comments
 (0)