MCPcopy Create free account
hub / github.com/AutoCodeStack/ios-device-farm / RenderLoop

Class RenderLoop

public/static/js/renderer/render.loop.js:2–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1// RenderLoop to handle drawing frames onto the canvas
2class RenderLoop {
3 constructor(pipeline, canvas) {
4 this.timer = null;
5 this.pipeline = pipeline;
6 this.canvas = canvas;
7 this.context = canvas.getContext("2d");
8 }
9
10 start() {
11 this.stop();
12 this.next();
13 }
14
15 stop() {
16 cancelAnimationFrame(this.timer);
17 }
18
19 next() {
20 this.timer = requestAnimationFrame(() => this.run());
21 }
22
23 run() {
24 const frame = this.pipeline.consume();
25 if (frame) {
26 this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
27 this.context.drawImage(frame.image, 0, 0, this.canvas.width, this.canvas.height);
28 }
29 this.next();
30 }
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected