mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37:19 +02:00
Cache screenshot's canvas context
This commit is contained in:
parent
453a45a995
commit
be897848fe
@ -172,6 +172,7 @@ window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
||||
}
|
||||
|
||||
STATES.isPlaying = false;
|
||||
STATES.currentStream = {};
|
||||
|
||||
// Stop MKB listeners
|
||||
getPref(PrefKey.MKB_ENABLED) && MkbHandler.INSTANCE.destroy();
|
||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@ -39,6 +39,7 @@ type BxStates = {
|
||||
|
||||
$video: HTMLVideoElement | null;
|
||||
$screenshotCanvas: HTMLCanvasElement | null;
|
||||
screenshotCanvasContext: CanvasRenderingContext2D | null;
|
||||
|
||||
peerConnection: RTCPeerConnection;
|
||||
audioContext: AudioContext | null;
|
||||
|
@ -3,12 +3,15 @@ import { CE } from "./html";
|
||||
|
||||
|
||||
export class Screenshot {
|
||||
static #filters: string = '';
|
||||
|
||||
static setup() {
|
||||
const currentStream = STATES.currentStream;
|
||||
if (!currentStream.$screenshotCanvas) {
|
||||
currentStream.$screenshotCanvas = CE<HTMLCanvasElement>('canvas', {'class': 'bx-gone'});
|
||||
|
||||
currentStream.screenshotCanvasContext = currentStream.$screenshotCanvas.getContext('2d', {
|
||||
alpha: false,
|
||||
willReadFrequently: false,
|
||||
});
|
||||
}
|
||||
// document.documentElement.appendChild(currentStream.$screenshotCanvas!);
|
||||
}
|
||||
@ -22,7 +25,7 @@ export class Screenshot {
|
||||
}
|
||||
|
||||
static updateCanvasFilters(filters: string) {
|
||||
Screenshot.#filters = filters;
|
||||
STATES.currentStream.screenshotCanvasContext && (STATES.currentStream.screenshotCanvasContext.filter = filters);
|
||||
}
|
||||
|
||||
private static onAnimationEnd(e: Event) {
|
||||
@ -40,12 +43,7 @@ export class Screenshot {
|
||||
$video.parentElement?.addEventListener('animationend', this.onAnimationEnd);
|
||||
$video.parentElement?.classList.add('bx-taking-screenshot');
|
||||
|
||||
const canvasContext = $canvas.getContext('2d', {
|
||||
alpha: false,
|
||||
willReadFrequently: false,
|
||||
})!;
|
||||
|
||||
canvasContext.filter = Screenshot.#filters;
|
||||
const canvasContext = currentStream.screenshotCanvasContext!;
|
||||
canvasContext.drawImage($video, 0, 0, $canvas.width, $canvas.height);
|
||||
|
||||
// Get data URL and pass to parent app
|
||||
|
Loading…
x
Reference in New Issue
Block a user