Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
Render in requestAnimationFrame during scoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Mar 27, 2015
1 parent af1bbab commit 134f4de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion examples/swfmplayer/swfmPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function startMovie(file) {
easelHost.alwaysRenderFrame = true;
easelHost.ignoreTimestamps = fastRun;
easelHost.onComplete = function () {
alert('Score: ' + Math.round(easelHost.cpuTime));
alert('Score: ' + Math.round(easelHost.cpuTime) + '\n' +
' (updates: ' + Math.round(easelHost.cpuTimeUpdates) +
', render: ' + Math.round(easelHost.cpuTimeRendering) + ')');
};
} else {
easel.startRendering();
Expand Down
26 changes: 21 additions & 5 deletions src/gfx/test/playbackEaselHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ module Shumway.GFX.Test {

public ignoreTimestamps: boolean = false;
public alwaysRenderFrame: boolean = false;
public cpuTime: number = 0;
public cpuTimeUpdates: number = 0;
public cpuTimeRendering: number = 0;

public onComplete: () => void = null;

public constructor(easel: Easel) {
super(easel);
}

public get cpuTime(): number {
return this.cpuTimeUpdates + this.cpuTimeRendering;
}

private playUrl(url: string) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
Expand Down Expand Up @@ -110,9 +115,6 @@ module Shumway.GFX.Test {
}
break;
case MovieRecordType.Frame:
if (this.alwaysRenderFrame) {
this.easel.render();
}
this.processFrame();
break;
case MovieRecordType.FontOrImage:
Expand All @@ -127,7 +129,21 @@ module Shumway.GFX.Test {
default:
throw new Error('Invalid movie record type');
}
this.cpuTime += performance.now() - start;
this.cpuTimeUpdates += performance.now() - start;

if (this._parser.currentType === MovieRecordType.Frame &&
this.alwaysRenderFrame) {
requestAnimationFrame(this._renderFrameJustAfterRAF.bind(this));
} else {
this._parseNext();
}
}

private _renderFrameJustAfterRAF() {
var start = performance.now();
this.easel.render();
this.cpuTimeRendering += performance.now() - start;

this._parseNext();
}
}
Expand Down

0 comments on commit 134f4de

Please sign in to comment.