Tests: reuse objects already made.
[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         this.offsetIndex = 0;
8     }, {
9
10     initialize: function(benchmark, options)
11     {
12         Stage.prototype.initialize.call(this, benchmark, options);
13         this.context = this.element.getContext("2d");
14     },
15
16     tune: function(count)
17     {
18         if (count == 0)
19             return;
20
21         if (count < 0) {
22             this.offsetIndex = Math.min(this.offsetIndex - count, this.objects.length);
23             return;
24         }
25
26         var newIndex = this.offsetIndex - count;
27         if (newIndex < 0) {
28             this.offsetIndex = 0;
29             newIndex = -newIndex;
30             for (var i = 0; i < newIndex; ++i)
31                 this.objects.push(new this._canvasObject(this));
32         } else
33             this.offsetIndex = newIndex;
34     },
35
36     animate: function()
37     {
38         var context = this.context;
39         context.clearRect(0, 0, this.size.x, this.size.y);
40         for (var i = this.offsetIndex, length = this.objects.length; i < length; ++i)
41             this.objects[i].draw(context);
42     },
43
44     complexity: function()
45     {
46         return this.objects.length - this.offsetIndex;
47     }
48 });