Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit b75669fb authored by Simon Chan's avatar Simon Chan
Browse files

feat(decoder): add an option to enable capture WebGL canvas

parent 1eed9aaf
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -81,13 +81,23 @@ export class WebCodecsVideoDecoder implements ScrcpyVideoDecoder {
    #currentFrameRendered = false;
    #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.#canvas = document.createElement("canvas");

        try {
            this.#renderer = new WebGLFrameRenderer(this.#canvas);
            this.#renderer = new WebGLFrameRenderer(
                this.#canvas,
                enableCapture,
            );
        } catch {
            this.#renderer = new BitmapFrameRenderer(this.#canvas);
        }
+10 −1
Original line number Diff line number Diff line
@@ -26,15 +26,24 @@ void main(void) {

    #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 =
            canvas.getContext("webgl2", {
                alpha: false,
                failIfMajorPerformanceCaveat: true,
                preserveDrawingBuffer: enableCapture,
            }) ||
            canvas.getContext("webgl", {
                alpha: false,
                failIfMajorPerformanceCaveat: true,
                preserveDrawingBuffer: enableCapture,
            });
        if (!gl) {
            throw new Error("WebGL not supported");