mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 23:57:19 +02:00
Optimize touch control's canvas, use low-power profile and disable antialiasing
This commit is contained in:
parent
d1b99705e6
commit
b9355d5c01
@ -23,7 +23,7 @@ import { RemotePlay } from "@modules/remote-play";
|
|||||||
import { onHistoryChanged, patchHistoryMethod } from "@utils/history";
|
import { onHistoryChanged, patchHistoryMethod } from "@utils/history";
|
||||||
import { VibrationManager } from "@modules/vibration-manager";
|
import { VibrationManager } from "@modules/vibration-manager";
|
||||||
import { PreloadedState } from "@utils/titles-info";
|
import { PreloadedState } from "@utils/titles-info";
|
||||||
import { patchAudioContext, patchMeControl, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
import { patchAudioContext, patchCanvasContext, patchMeControl, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "@utils/monkey-patches";
|
||||||
import { STATES } from "@utils/global";
|
import { STATES } from "@utils/global";
|
||||||
import { injectStreamMenuButtons } from "@modules/stream/stream-ui";
|
import { injectStreamMenuButtons } from "@modules/stream/stream-ui";
|
||||||
import { BxLogger } from "@utils/bx-logger";
|
import { BxLogger } from "@utils/bx-logger";
|
||||||
@ -215,6 +215,7 @@ function main() {
|
|||||||
patchRtcCodecs();
|
patchRtcCodecs();
|
||||||
interceptHttpRequests();
|
interceptHttpRequests();
|
||||||
patchVideoApi();
|
patchVideoApi();
|
||||||
|
patchCanvasContext();
|
||||||
|
|
||||||
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
|
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
|
||||||
getPref(PrefKey.BLOCK_TRACKING) && patchMeControl();
|
getPref(PrefKey.BLOCK_TRACKING) && patchMeControl();
|
||||||
|
@ -9,7 +9,10 @@ export function takeScreenshot(callback: any) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $canvasContext = $canvas.getContext('2d')!;
|
const $canvasContext = $canvas.getContext('2d', {
|
||||||
|
alpha: false,
|
||||||
|
willReadFrequently: false,
|
||||||
|
})!;
|
||||||
|
|
||||||
$canvasContext.drawImage($video, 0, 0, $canvas.width, $canvas.height);
|
$canvasContext.drawImage($video, 0, 0, $canvas.width, $canvas.height);
|
||||||
|
|
||||||
|
@ -180,3 +180,25 @@ export function patchMeControl() {
|
|||||||
(window as any).MSA = new Proxy(MSA, MsaHandler);
|
(window as any).MSA = new Proxy(MSA, MsaHandler);
|
||||||
(window as any).MeControl = new Proxy(MeControl, MeControlHandler);
|
(window as any).MeControl = new Proxy(MeControl, MeControlHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use power-saving flags for touch control
|
||||||
|
*/
|
||||||
|
export function patchCanvasContext() {
|
||||||
|
const nativeGetContext = HTMLCanvasElement.prototype.getContext;
|
||||||
|
// @ts-ignore
|
||||||
|
HTMLCanvasElement.prototype.getContext = function(contextType: string, contextAttributes?: any) {
|
||||||
|
if (contextType.includes('webgl')) {
|
||||||
|
contextAttributes = contextAttributes || {};
|
||||||
|
|
||||||
|
contextAttributes.antialias = false;
|
||||||
|
|
||||||
|
// Use low-power profile for touch controller
|
||||||
|
if (contextAttributes.powerPreference === 'high-performance') {
|
||||||
|
contextAttributes.powerPreference = 'low-power';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nativeGetContext.apply(this, [contextType, contextAttributes]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user