diff --git a/src/index.ts b/src/index.ts index 6b2dd4d..41fe0be 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ import { RemotePlay } from "@modules/remote-play"; import { onHistoryChanged, patchHistoryMethod } from "@utils/history"; import { VibrationManager } from "@modules/vibration-manager"; 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 { injectStreamMenuButtons } from "@modules/stream/stream-ui"; import { BxLogger } from "@utils/bx-logger"; @@ -215,6 +215,7 @@ function main() { patchRtcCodecs(); interceptHttpRequests(); patchVideoApi(); + patchCanvasContext(); getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext(); getPref(PrefKey.BLOCK_TRACKING) && patchMeControl(); diff --git a/src/modules/screenshot.ts b/src/modules/screenshot.ts index 26d1d9d..a02cb37 100644 --- a/src/modules/screenshot.ts +++ b/src/modules/screenshot.ts @@ -9,7 +9,10 @@ export function takeScreenshot(callback: any) { return; } - const $canvasContext = $canvas.getContext('2d')!; + const $canvasContext = $canvas.getContext('2d', { + alpha: false, + willReadFrequently: false, + })!; $canvasContext.drawImage($video, 0, 0, $canvas.width, $canvas.height); diff --git a/src/utils/monkey-patches.ts b/src/utils/monkey-patches.ts index 262e602..32d4290 100644 --- a/src/utils/monkey-patches.ts +++ b/src/utils/monkey-patches.ts @@ -180,3 +180,25 @@ export function patchMeControl() { (window as any).MSA = new Proxy(MSA, MsaHandler); (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]); + } +}