ae647dbd2054194ed7f3879614bdd3c22f260ec9
[WebKit-https.git] / PerformanceTests / Animometer / tests / master / resources / canvas-stage.js
1 SimpleCanvasStage = Utilities.createSubclass(Stage,
2     function(canvasObject)
3     {
4         Stage.call(this);
5         this._canvasObject = canvasObject;
6         this.objects = [];
7     }, {
8
9     initialize: function(benchmark, options)
10     {
11         Stage.prototype.initialize.call(this, benchmark, options);
12         this.context = this.element.getContext("2d");
13     },
14
15     tune: function(count)
16     {
17         if (count == 0)
18             return;
19
20         if (count > 0) {
21             for (var i = 0; i < count; ++i)
22                 this.objects.push(new this._canvasObject(this));
23             return;
24         }
25
26         count = Math.min(-count, this.objects.length);
27         this.objects.splice(0, count);
28     },
29
30     animate: function()
31     {
32         var context = this.context;
33         context.clearRect(0, 0, this.size.x, this.size.y);
34         this.objects.forEach(function(object) {
35             object.draw(context);
36         });
37     },
38
39     complexity: function()
40     {
41         return this.objects.length;
42     }
43 });