mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 15:47:18 +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.isPlaying = false;
|
||||||
|
STATES.currentStream = {};
|
||||||
|
|
||||||
// Stop MKB listeners
|
// Stop MKB listeners
|
||||||
getPref(PrefKey.MKB_ENABLED) && MkbHandler.INSTANCE.destroy();
|
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;
|
$video: HTMLVideoElement | null;
|
||||||
$screenshotCanvas: HTMLCanvasElement | null;
|
$screenshotCanvas: HTMLCanvasElement | null;
|
||||||
|
screenshotCanvasContext: CanvasRenderingContext2D | null;
|
||||||
|
|
||||||
peerConnection: RTCPeerConnection;
|
peerConnection: RTCPeerConnection;
|
||||||
audioContext: AudioContext | null;
|
audioContext: AudioContext | null;
|
||||||
|
@ -3,12 +3,15 @@ import { CE } from "./html";
|
|||||||
|
|
||||||
|
|
||||||
export class Screenshot {
|
export class Screenshot {
|
||||||
static #filters: string = '';
|
|
||||||
|
|
||||||
static setup() {
|
static setup() {
|
||||||
const currentStream = STATES.currentStream;
|
const currentStream = STATES.currentStream;
|
||||||
if (!currentStream.$screenshotCanvas) {
|
if (!currentStream.$screenshotCanvas) {
|
||||||
currentStream.$screenshotCanvas = CE<HTMLCanvasElement>('canvas', {'class': 'bx-gone'});
|
currentStream.$screenshotCanvas = CE<HTMLCanvasElement>('canvas', {'class': 'bx-gone'});
|
||||||
|
|
||||||
|
currentStream.screenshotCanvasContext = currentStream.$screenshotCanvas.getContext('2d', {
|
||||||
|
alpha: false,
|
||||||
|
willReadFrequently: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// document.documentElement.appendChild(currentStream.$screenshotCanvas!);
|
// document.documentElement.appendChild(currentStream.$screenshotCanvas!);
|
||||||
}
|
}
|
||||||
@ -22,7 +25,7 @@ export class Screenshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static updateCanvasFilters(filters: string) {
|
static updateCanvasFilters(filters: string) {
|
||||||
Screenshot.#filters = filters;
|
STATES.currentStream.screenshotCanvasContext && (STATES.currentStream.screenshotCanvasContext.filter = filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static onAnimationEnd(e: Event) {
|
private static onAnimationEnd(e: Event) {
|
||||||
@ -40,12 +43,7 @@ export class Screenshot {
|
|||||||
$video.parentElement?.addEventListener('animationend', this.onAnimationEnd);
|
$video.parentElement?.addEventListener('animationend', this.onAnimationEnd);
|
||||||
$video.parentElement?.classList.add('bx-taking-screenshot');
|
$video.parentElement?.classList.add('bx-taking-screenshot');
|
||||||
|
|
||||||
const canvasContext = $canvas.getContext('2d', {
|
const canvasContext = currentStream.screenshotCanvasContext!;
|
||||||
alpha: false,
|
|
||||||
willReadFrequently: false,
|
|
||||||
})!;
|
|
||||||
|
|
||||||
canvasContext.filter = Screenshot.#filters;
|
|
||||||
canvasContext.drawImage($video, 0, 0, $canvas.width, $canvas.height);
|
canvasContext.drawImage($video, 0, 0, $canvas.width, $canvas.height);
|
||||||
|
|
||||||
// Get data URL and pass to parent app
|
// Get data URL and pass to parent app
|
||||||
|
Loading…
x
Reference in New Issue
Block a user