Skip to content

Commit

Permalink
Move waitForRender resolve into core render loop. Use for toDataURL
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Mar 12, 2019
1 parent 9a91b0a commit fa40439
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions modules/core/src/core/animation-loop.js
Expand Up @@ -77,9 +77,6 @@ export default class AnimationLoop {
this._resolveNextFrame = null;
this._cpuStartTime = 0;

this._canvasDataURLPromise = null;
this._resolveCanvasDataURL = null;

this.setProps({
autoResizeViewport,
autoResizeDrawingBuffer,
Expand Down Expand Up @@ -179,10 +176,10 @@ export default class AnimationLoop {
this.gl.commit();
}

if (this._canvasDataURLPromise) {
this._resolveCanvasDataURL(this.gl.canvas.toDataURL());
this._canvasDataURLPromise = null;
this._resolveCanvasDataURL = null;
if (this._resolveNextFrame) {
this._resolveNextFrame(this);
this._nextFramePromise = null;
this._resolveNextFrame = null;
}

this._endTimers();
Expand Down Expand Up @@ -214,16 +211,7 @@ export default class AnimationLoop {
}

toDataURL() {
if (this._canvasDataURLPromise) {
return this._canvasDataURLPromise;
}

this.setNeedsRedraw('getCanvasDataUrl');
this._canvasDataURLPromise = new Promise(resolve => {
this._resolveCanvasDataURL = resolve;
});

return this._canvasDataURLPromise;
return this.waitForRender().then(self => self.gl.canvas.toDataURL());
}

onCreateContext(...args) {
Expand Down Expand Up @@ -263,11 +251,6 @@ export default class AnimationLoop {
return;
}
this.redraw();
if (this._resolveNextFrame) {
this._resolveNextFrame(this);
this._nextFramePromise = null;
this._resolveNextFrame = null;
}
this._animationFrameId = requestAnimationFrame(renderFrame);
};

Expand Down

0 comments on commit fa40439

Please sign in to comment.