Skip to content

Commit

Permalink
fix: setup renderer may show rotate frame (#1190)
Browse files Browse the repository at this point in the history
perf: set canvas hidden before first frame shown
  • Loading branch information
guoxianzhe authored May 14, 2024
1 parent 029b6d5 commit ad6400c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ts/Renderer/IRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export abstract class IRenderer {
});
this.parentElement.appendChild(this.container);
this.canvas = document.createElement('canvas');
this.canvas.style.display = 'none';
this.container.appendChild(this.canvas);
}

Expand All @@ -42,7 +43,13 @@ export abstract class IRenderer {
this.parentElement = undefined;
}

public abstract drawFrame(videoFrame: VideoFrame): void;
public drawFrame(_videoFrame?: VideoFrame): void {
if (!this.canvas) return;
//@ts-ignore
if (!this.canvas.checkVisibility()) {
this.canvas.style.display = '';
}
}

public set context({ renderMode, mirrorMode }: Context) {
if (this.context.renderMode !== renderMode) {
Expand Down
1 change: 1 addition & 0 deletions ts/Renderer/WebGLRenderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class WebGLRenderer extends IRenderer {
);

this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);
super.drawFrame();
}

protected override rotateCanvas({ width, height, rotation }: VideoFrame) {
Expand Down
1 change: 1 addition & 0 deletions ts/Renderer/YUVCanvasRenderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class YUVCanvasRenderer extends IRenderer {
}
)
);
super.drawFrame();
}

protected override rotateCanvas({ width, height, rotation }: VideoFrame) {
Expand Down

0 comments on commit ad6400c

Please sign in to comment.