提交 b73f9ec8 编写于 作者: B Benjamin Pasero

Add a setting to disable gpu acceleration (fixes #15211)

上级 841d8974
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
"launch.json", "launch.json",
"tasks.json", "tasks.json",
"keybindings.json", "keybindings.json",
"extensions.json" "extensions.json",
"argv.json"
] ]
} }
], ],
......
...@@ -12,6 +12,8 @@ const lp = require('./vs/base/node/languagePacks'); ...@@ -12,6 +12,8 @@ const lp = require('./vs/base/node/languagePacks');
perf.mark('main:started'); perf.mark('main:started');
const path = require('path'); const path = require('path');
const fs = require('fs');
const os = require('os');
const bootstrap = require('./bootstrap'); const bootstrap = require('./bootstrap');
const paths = require('./paths'); const paths = require('./paths');
// @ts-ignore // @ts-ignore
...@@ -113,16 +115,97 @@ async function onReady() { ...@@ -113,16 +115,97 @@ async function onReady() {
*/ */
function configureCommandlineSwitches(cliArgs) { function configureCommandlineSwitches(cliArgs) {
// Force pre-Chrome-60 color profile handling (for https://github.com/Microsoft/vscode/issues/51791) // Read argv config
app.commandLine.appendSwitch('disable-color-correct-rendering'); const argvConfig = readArgvConfig();
// Append each flag to Electron
Object.keys(argvConfig).forEach(flag => {
const value = argvConfig[flag];
if (value === true || value === 'true') {
if (flag === 'disable-gpu') {
app.disableHardwareAcceleration(); // needs to be called explicitly
}
app.commandLine.appendArgument(flag);
} else {
app.commandLine.appendSwitch(flag, value);
}
});
// Support JS Flags // Support JS Flags
const jsFlags = getJSFlags(cliArgs); const jsFlags = getJSFlags(cliArgs);
if (jsFlags) { if (jsFlags) {
app.commandLine.appendSwitch('--js-flags', jsFlags); app.commandLine.appendSwitch('js-flags', jsFlags);
} }
} }
function readArgvConfig() {
// Read or create the argv.json config file sync before app('ready')
const argvConfigPath = getArgvConfigPath();
let argvConfig;
try {
argvConfig = JSON.parse(stripComments(fs.readFileSync(argvConfigPath).toString()));
} catch (error) {
if (error && error.code === 'ENOENT') {
try {
const argvConfigPathDirname = path.dirname(argvConfigPath);
if (!fs.existsSync(argvConfigPathDirname)) {
fs.mkdirSync(argvConfigPathDirname);
}
// Create initial argv.json if not existing
fs.writeFileSync(argvConfigPath, `// This configuration file allows to pass permanent command line arguments to VSCode.
//
// PLEASE DO NOT CHANGE WITHOUT UNDERSTANDING THE IMPACT
//
// If the command line argument does not have any values, simply assign
// it in the JSON below with a value of 'true'. Otherwise, put the value
// directly.
//
// If you see rendering issues in VSCode and have a better experience
// with software rendering, you can configure this by adding:
//
// 'disable-gpu': true
//
// NOTE: Changing this file requires a restart of VSCode.
{
// Enabled by default by VSCode to resolve color issues in the renderer
// See https://github.com/Microsoft/vscode/issues/51791 for details
"disable-color-correct-rendering": true
}`);
} catch (error) {
console.error(`Unable to create argv.json configuration file in ${argvConfigPath}, falling back to defaults (${error})`);
}
} else {
console.warn(`Unable to read argv.json configuration file in ${argvConfigPath}, falling back to defaults (${error})`);
}
}
// Fallback to default
if (!argvConfig) {
argvConfig = {
'disable-color-correct-rendering': true // Force pre-Chrome-60 color profile handling (for https://github.com/Microsoft/vscode/issues/51791)
};
}
return argvConfig;
}
function getArgvConfigPath() {
const vscodePortable = process.env['VSCODE_PORTABLE'];
if (vscodePortable) {
return path.join(vscodePortable, 'argv.json');
}
let dataFolderName = product.dataFolderName;
if (process.env['VSCODE_DEV']) {
dataFolderName = `${dataFolderName}-dev`;
}
return path.join(os.homedir(), dataFolderName, 'argv.json');
}
/** /**
* @param {ParsedArgs} cliArgs * @param {ParsedArgs} cliArgs
* @returns {string} * @returns {string}
......
...@@ -116,6 +116,7 @@ export interface IEnvironmentService { ...@@ -116,6 +116,7 @@ export interface IEnvironmentService {
keybindingsResource: URI; keybindingsResource: URI;
keyboardLayoutResource: URI; keyboardLayoutResource: URI;
localeResource: URI; localeResource: URI;
argvResource: URI;
// sync resources // sync resources
userDataSyncLogResource: URI; userDataSyncLogResource: URI;
......
...@@ -95,7 +95,6 @@ export class EnvironmentService implements IEnvironmentService { ...@@ -95,7 +95,6 @@ export class EnvironmentService implements IEnvironmentService {
@memoize @memoize
get userDataPath(): string { get userDataPath(): string {
const vscodePortable = process.env['VSCODE_PORTABLE']; const vscodePortable = process.env['VSCODE_PORTABLE'];
if (vscodePortable) { if (vscodePortable) {
return path.join(vscodePortable, 'user-data'); return path.join(vscodePortable, 'user-data');
} }
...@@ -143,6 +142,16 @@ export class EnvironmentService implements IEnvironmentService { ...@@ -143,6 +142,16 @@ export class EnvironmentService implements IEnvironmentService {
@memoize @memoize
get localeResource(): URI { return resources.joinPath(this.userRoamingDataHome, 'locale.json'); } get localeResource(): URI { return resources.joinPath(this.userRoamingDataHome, 'locale.json'); }
@memoize
get argvResource(): URI {
const vscodePortable = process.env['VSCODE_PORTABLE'];
if (vscodePortable) {
return URI.file(path.join(vscodePortable, 'argv.json'));
}
return URI.file(path.join(this.userHome, product.dataFolderName, 'argv.json'));
}
@memoize @memoize
get isExtensionDevelopment(): boolean { return !!this._args.extensionDevelopmentPath; } get isExtensionDevelopment(): boolean { return !!this._args.extensionDevelopmentPath; }
...@@ -182,7 +191,6 @@ export class EnvironmentService implements IEnvironmentService { ...@@ -182,7 +191,6 @@ export class EnvironmentService implements IEnvironmentService {
} }
const vscodePortable = process.env['VSCODE_PORTABLE']; const vscodePortable = process.env['VSCODE_PORTABLE'];
if (vscodePortable) { if (vscodePortable) {
return path.join(vscodePortable, 'extensions'); return path.join(vscodePortable, 'extensions');
} }
......
...@@ -7,13 +7,19 @@ import { Action } from 'vs/base/common/actions'; ...@@ -7,13 +7,19 @@ import { Action } from 'vs/base/common/actions';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { IElectronService } from 'vs/platform/electron/node/electron'; import { IElectronService } from 'vs/platform/electron/node/electron';
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService'; import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
export class ToggleDevToolsAction extends Action { export class ToggleDevToolsAction extends Action {
static readonly ID = 'workbench.action.toggleDevTools'; static readonly ID = 'workbench.action.toggleDevTools';
static readonly LABEL = nls.localize('toggleDevTools', "Toggle Developer Tools"); static readonly LABEL = nls.localize('toggleDevTools', "Toggle Developer Tools");
constructor(id: string, label: string, @IElectronService private readonly electronService: IElectronService) { constructor(
id: string,
label: string,
@IElectronService private readonly electronService: IElectronService
) {
super(id, label); super(id, label);
} }
...@@ -27,7 +33,11 @@ export class ToggleSharedProcessAction extends Action { ...@@ -27,7 +33,11 @@ export class ToggleSharedProcessAction extends Action {
static readonly ID = 'workbench.action.toggleSharedProcess'; static readonly ID = 'workbench.action.toggleSharedProcess';
static readonly LABEL = nls.localize('toggleSharedProcess', "Toggle Shared Process"); static readonly LABEL = nls.localize('toggleSharedProcess', "Toggle Shared Process");
constructor(id: string, label: string, @ISharedProcessService private readonly sharedProcessService: ISharedProcessService) { constructor(
id: string,
label: string,
@ISharedProcessService private readonly sharedProcessService: ISharedProcessService
) {
super(id, label); super(id, label);
} }
...@@ -35,3 +45,22 @@ export class ToggleSharedProcessAction extends Action { ...@@ -35,3 +45,22 @@ export class ToggleSharedProcessAction extends Action {
return this.sharedProcessService.toggleSharedProcessWindow(); return this.sharedProcessService.toggleSharedProcessWindow();
} }
} }
export class ConfigureRuntimeArgumentsAction extends Action {
static readonly ID = 'workbench.action.configureRuntimeArguments';
static readonly LABEL = nls.localize('configureRuntimeArguments', "Configure Runtime Arguments");
constructor(
id: string,
label: string,
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@IEditorService private readonly editorService: IEditorService
) {
super(id, label);
}
async run(): Promise<void> {
await this.editorService.openEditor({ resource: this.environmentService.argvResource });
}
}
...@@ -11,7 +11,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions, Configur ...@@ -11,7 +11,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions, Configur
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions'; import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform'; import { isWindows, isLinux, isMacintosh } from 'vs/base/common/platform';
import { ToggleSharedProcessAction, ToggleDevToolsAction } from 'vs/workbench/electron-browser/actions/developerActions'; import { ToggleSharedProcessAction, ToggleDevToolsAction, ConfigureRuntimeArgumentsAction } from 'vs/workbench/electron-browser/actions/developerActions';
import { ZoomResetAction, ZoomOutAction, ZoomInAction, CloseCurrentWindowAction, SwitchWindow, QuickSwitchWindow, ReloadWindowWithExtensionsDisabledAction, NewWindowTabHandler, ShowPreviousWindowTabHandler, ShowNextWindowTabHandler, MoveWindowTabToNewWindowHandler, MergeWindowTabsHandlerHandler, ToggleWindowTabsBarHandler } from 'vs/workbench/electron-browser/actions/windowActions'; import { ZoomResetAction, ZoomOutAction, ZoomInAction, CloseCurrentWindowAction, SwitchWindow, QuickSwitchWindow, ReloadWindowWithExtensionsDisabledAction, NewWindowTabHandler, ShowPreviousWindowTabHandler, ShowNextWindowTabHandler, MoveWindowTabToNewWindowHandler, MergeWindowTabsHandlerHandler, ToggleWindowTabsBarHandler } from 'vs/workbench/electron-browser/actions/windowActions';
import { SaveWorkspaceAsAction, DuplicateWorkspaceInNewWindowAction } from 'vs/workbench/electron-browser/actions/workspaceActions'; import { SaveWorkspaceAsAction, DuplicateWorkspaceInNewWindowAction } from 'vs/workbench/electron-browser/actions/workspaceActions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
...@@ -98,6 +98,7 @@ import { IElectronService } from 'vs/platform/electron/node/electron'; ...@@ -98,6 +98,7 @@ import { IElectronService } from 'vs/platform/electron/node/electron';
(function registerDeveloperActions(): void { (function registerDeveloperActions(): void {
const developerCategory = nls.localize('developer', "Developer"); const developerCategory = nls.localize('developer', "Developer");
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSharedProcessAction, ToggleSharedProcessAction.ID, ToggleSharedProcessAction.LABEL), 'Developer: Toggle Shared Process', developerCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleSharedProcessAction, ToggleSharedProcessAction.ID, ToggleSharedProcessAction.LABEL), 'Developer: Toggle Shared Process', developerCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureRuntimeArgumentsAction, ConfigureRuntimeArgumentsAction.ID, ConfigureRuntimeArgumentsAction.LABEL), 'Developer: Configure Runtime Arguments', developerCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowWithExtensionsDisabledAction, ReloadWindowWithExtensionsDisabledAction.ID, ReloadWindowWithExtensionsDisabledAction.LABEL), 'Developer: Reload With Extensions Disabled', developerCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(ReloadWindowWithExtensionsDisabledAction, ReloadWindowWithExtensionsDisabledAction.ID, ReloadWindowWithExtensionsDisabledAction.LABEL), 'Developer: Reload With Extensions Disabled', developerCategory);
registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL), 'Developer: Toggle Developer Tools', developerCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL), 'Developer: Toggle Developer Tools', developerCategory);
......
...@@ -89,6 +89,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment ...@@ -89,6 +89,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
this.keybindingsResource = joinPath(this.userRoamingDataHome, 'keybindings.json'); this.keybindingsResource = joinPath(this.userRoamingDataHome, 'keybindings.json');
this.keyboardLayoutResource = joinPath(this.userRoamingDataHome, 'keyboardLayout.json'); this.keyboardLayoutResource = joinPath(this.userRoamingDataHome, 'keyboardLayout.json');
this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json'); this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
this.argvResource = joinPath(this.userRoamingDataHome, 'argv.json');
this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS); this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
this.configuration.backupWorkspaceResource = joinPath(this.backupHome, options.workspaceId); this.configuration.backupWorkspaceResource = joinPath(this.backupHome, options.workspaceId);
this.configuration.connectionToken = options.connectionToken || getCookieValue('vscode-tkn'); this.configuration.connectionToken = options.connectionToken || getCookieValue('vscode-tkn');
...@@ -146,6 +147,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment ...@@ -146,6 +147,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
keybindingsResource: URI; keybindingsResource: URI;
keyboardLayoutResource: URI; keyboardLayoutResource: URI;
localeResource: URI; localeResource: URI;
argvResource: URI;
settingsSyncPreviewResource: URI; settingsSyncPreviewResource: URI;
userDataSyncLogResource: URI; userDataSyncLogResource: URI;
machineSettingsHome: URI; machineSettingsHome: URI;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册