Add basic canvas tests
[WebKit-https.git] / PerformanceTests / Animometer / tests / simple / resources / simple-canvas.js
1
2 function SimpleCanvasStage(element, options, canvasObject)
3 {
4     Stage.call(this, element, options);
5     this.context = this.element.getContext("2d");
6     this.canvasObject = canvasObject;
7     this._objects = [];
8 }
9 SimpleCanvasStage.prototype = Object.create(Stage.prototype);
10 SimpleCanvasStage.prototype.constructor = SimpleCanvasStage;
11 SimpleCanvasStage.prototype.tune = function(count)
12 {
13     if (count == 0)
14         return this._objects.length;
15
16     if (count > 0) {
17         for (var i = 0; i < count; ++i) {
18             this._objects.push(new this.canvasObject(this));
19         }
20         return this._objects.length;
21     }
22
23     count = Math.min(-count, this._objects.length);
24     this._objects.splice(-count, count);
25
26     return this._objects.length;
27 }
28 SimpleCanvasStage.prototype.animate = function()
29 {
30     var context = this.context;
31     this._objects.forEach(function(object) {
32         object.draw(context);
33     });
34 }
35
36 function SimpleCanvasAnimator(benchmark)
37 {
38     StageAnimator.call(this, benchmark);
39     this._context = benchmark._stage.context;
40 }
41
42 SimpleCanvasAnimator.prototype = Object.create(StageAnimator.prototype);
43 SimpleCanvasAnimator.prototype.constructor = SimpleCanvasAnimator;
44 SimpleCanvasAnimator.prototype.animate = function()
45 {
46     this._context.clearRect(0, 0, this._benchmark._stage.size.x, this._benchmark._stage.size.y);
47     return StageAnimator.prototype.animate.call(this);
48 }
49
50
51 function SimpleCanvasBenchmark(suite, test, options, recordTable, progressBar) {
52     options["gain"] = 6;
53     options["addLimit"] = 100;
54     options["removeLimit"] = 1000;
55     StageBenchmark.call(this, suite, test, options, recordTable, progressBar);
56 }
57 SimpleCanvasBenchmark.prototype = Object.create(StageBenchmark.prototype);
58 SimpleCanvasBenchmark.prototype.constructor = SimpleCanvasBenchmark;
59 SimpleCanvasBenchmark.prototype.createAnimator = function() {
60     return new SimpleCanvasAnimator(this);
61 }
62