mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 09:49:24 +02:00
feat(decoder): add an option to enable capture WebGL canvas
This commit is contained in:
parent
1eed9aaf8b
commit
b75669fb67
2 changed files with 22 additions and 3 deletions
|
@ -81,13 +81,23 @@ export class WebCodecsVideoDecoder implements ScrcpyVideoDecoder {
|
||||||
#currentFrameRendered = false;
|
#currentFrameRendered = false;
|
||||||
#animationFrameId = 0;
|
#animationFrameId = 0;
|
||||||
|
|
||||||
constructor(codec: ScrcpyVideoCodecId) {
|
/**
|
||||||
|
* Create a new WebCodecs video decoder.
|
||||||
|
* @param codec The video codec to decode
|
||||||
|
* @param enableCapture
|
||||||
|
* Whether to allow capturing the canvas content using APIs like `readPixels` and `toDataURL`.
|
||||||
|
* Enable this option may reduce performance.
|
||||||
|
*/
|
||||||
|
constructor(codec: ScrcpyVideoCodecId, enableCapture: boolean) {
|
||||||
this.#codec = codec;
|
this.#codec = codec;
|
||||||
|
|
||||||
this.#canvas = document.createElement("canvas");
|
this.#canvas = document.createElement("canvas");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.#renderer = new WebGLFrameRenderer(this.#canvas);
|
this.#renderer = new WebGLFrameRenderer(
|
||||||
|
this.#canvas,
|
||||||
|
enableCapture,
|
||||||
|
);
|
||||||
} catch {
|
} catch {
|
||||||
this.#renderer = new BitmapFrameRenderer(this.#canvas);
|
this.#renderer = new BitmapFrameRenderer(this.#canvas);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,15 +26,24 @@ void main(void) {
|
||||||
|
|
||||||
#context: WebGLRenderingContext;
|
#context: WebGLRenderingContext;
|
||||||
|
|
||||||
constructor(canvas: HTMLCanvasElement) {
|
/**
|
||||||
|
* Create a new WebGL frame renderer.
|
||||||
|
* @param canvas The canvas to render frames to.
|
||||||
|
* @param enableCapture
|
||||||
|
* Whether to allow capturing the canvas content using APIs like `readPixels` and `toDataURL`.
|
||||||
|
* Enable this option may reduce performance.
|
||||||
|
*/
|
||||||
|
constructor(canvas: HTMLCanvasElement, enableCapture: boolean) {
|
||||||
const gl =
|
const gl =
|
||||||
canvas.getContext("webgl2", {
|
canvas.getContext("webgl2", {
|
||||||
alpha: false,
|
alpha: false,
|
||||||
failIfMajorPerformanceCaveat: true,
|
failIfMajorPerformanceCaveat: true,
|
||||||
|
preserveDrawingBuffer: enableCapture,
|
||||||
}) ||
|
}) ||
|
||||||
canvas.getContext("webgl", {
|
canvas.getContext("webgl", {
|
||||||
alpha: false,
|
alpha: false,
|
||||||
failIfMajorPerformanceCaveat: true,
|
failIfMajorPerformanceCaveat: true,
|
||||||
|
preserveDrawingBuffer: enableCapture,
|
||||||
});
|
});
|
||||||
if (!gl) {
|
if (!gl) {
|
||||||
throw new Error("WebGL not supported");
|
throw new Error("WebGL not supported");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue