summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources')
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-images.js47
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-particles.js88
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js87
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-images.js61
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-shapes.js86
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-particles.js123
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-images.js43
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-particles.js67
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-shapes.js101
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js106
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image1.jpgbin0 -> 64004 bytes
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image2.jpgbin0 -> 71981 bytes
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image3.jpgbin0 -> 71319 bytes
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image4.jpgbin0 -> 96373 bytes
-rw-r--r--third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image5.jpgbin0 -> 135674 bytes
15 files changed, 809 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-images.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-images.js
new file mode 100644
index 0000000000..5fba5ad761
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-images.js
@@ -0,0 +1,47 @@
+(function() {
+
+BouncingCanvasImage = Utilities.createSubclass(BouncingCanvasParticle,
+ function(stage)
+ {
+ BouncingCanvasParticle.call(this, stage, "image");
+ this._imageElement = stage.imageElement;
+ }, {
+
+ _draw: function()
+ {
+ this.context.save();
+ this.applyRotation();
+ this.context.drawImage(this._imageElement, 0, 0, this.size.x, this.size.y);
+ this.context.restore();
+ }
+});
+
+BouncingCanvasImagesStage = Utilities.createSubclass(BouncingCanvasParticlesStage,
+ function()
+ {
+ BouncingCanvasParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingCanvasParticlesStage.prototype.initialize.call(this, benchmark, options);
+ var imageSrc = options["imageSrc"] || "resources/yin-yang.svg";
+ this.imageElement = document.querySelector(".hidden[src=\"" + imageSrc + "\"]");
+ },
+
+ createParticle: function()
+ {
+ return new BouncingCanvasImage(this);
+ }
+});
+
+BouncingCanvasImagesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingCanvasImagesStage(), options);
+ }
+);
+
+window.benchmarkClass = BouncingCanvasImagesBenchmark;
+
+})();
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-particles.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-particles.js
new file mode 100644
index 0000000000..0a76ba05c3
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-particles.js
@@ -0,0 +1,88 @@
+BouncingCanvasParticle = Utilities.createSubclass(BouncingParticle,
+ function(stage, shape)
+ {
+ BouncingParticle.call(this, stage);
+ this.context = stage.context;
+ this._shape = shape;
+ this._clip = stage.clip;
+ }, {
+
+ applyRotation: function()
+ {
+ if (this._shape == "circle")
+ return;
+
+ this.context.translate(this.size.x / 2, this.size.y / 2);
+ this.context.rotate(this.rotater.degree() * Math.PI / 180);
+ this.context.translate(-this.size.x / 2, -this.size.y / 2);
+ },
+
+ applyClipping: function()
+ {
+ var clipPoints = BouncingCanvasParticle.clips[this._clip];
+ if (!clipPoints)
+ return;
+
+ this.context.beginPath();
+ clipPoints.forEach(function(point, index) {
+ var point = this.size.multiply(point);
+ if (!index)
+ this.context.moveTo(point.x, point.y);
+ else
+ this.context.lineTo(point.x, point.y);
+ }, this);
+
+ this.context.closePath();
+ this.context.clip();
+ },
+
+ _draw: function()
+ {
+ throw "Not implemented";
+ },
+
+ animate: function(timeDelta)
+ {
+ BouncingParticle.prototype.animate.call(this, timeDelta);
+ this.context.save();
+ this.context.translate(this.position.x, this.position.y);
+ this._draw();
+ this.context.restore();
+ }
+});
+
+BouncingCanvasParticle.clips = {
+ star: [
+ new Point(0.50, 0.00),
+ new Point(0.38, 0.38),
+ new Point(0.00, 0.38),
+ new Point(0.30, 0.60),
+ new Point(0.18, 1.00),
+ new Point(0.50, 0.75),
+ new Point(0.82, 1.00),
+ new Point(0.70, 0.60),
+ new Point(1.00, 0.38),
+ new Point(0.62, 0.38)
+ ]
+};
+
+BouncingCanvasParticlesStage = Utilities.createSubclass(BouncingParticlesStage,
+ function()
+ {
+ BouncingParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingParticlesStage.prototype.initialize.call(this, benchmark, options);
+ this.context = this.element.getContext("2d");
+ },
+
+ animate: function(timeDelta)
+ {
+ this.context.clearRect(0, 0, this.size.x, this.size.y);
+ this.particles.forEach(function(particle) {
+ particle.animate(timeDelta);
+ });
+ }
+});
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js
new file mode 100644
index 0000000000..49a31cf40d
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-canvas-shapes.js
@@ -0,0 +1,87 @@
+(function() {
+
+BouncingCanvasShape = Utilities.createSubclass(BouncingCanvasParticle,
+ function(stage)
+ {
+ BouncingCanvasParticle.call(this, stage, stage.shape);
+ this._fill = stage.fill;
+ this._color0 = Stage.randomColor();
+ this._color1 = Stage.randomColor();
+ }, {
+
+ _applyFill: function()
+ {
+ switch (this._fill) {
+ case "gradient":
+ var gradient = this.context.createLinearGradient(0, 0, this.size.width, 0);
+ gradient.addColorStop(0, this._color0);
+ gradient.addColorStop(1, this._color1);
+ this.context.fillStyle = gradient;
+ break;
+
+ case "solid":
+ default:
+ this.context.fillStyle = this._color0;
+ break;
+ }
+ },
+
+ _drawShape: function()
+ {
+ this.context.beginPath();
+
+ switch (this._shape) {
+ case "rect":
+ this.context.rect(0, 0, this.size.width, this.size.height);
+ break;
+
+ case "circle":
+ default:
+ var center = this.size.center;
+ var radius = Math.min(this.size.x, this.size.y) / 2;
+ this.context.arc(center.x, center.y, radius, 0, Math.PI * 2, true);
+ break;
+ }
+
+ this.context.fill();
+ },
+
+ _draw: function()
+ {
+ this.context.save();
+ this._applyFill();
+ this.applyRotation();
+ this.applyClipping();
+ this._drawShape();
+ this.context.restore();
+ }
+});
+
+BouncingCanvasShapesStage = Utilities.createSubclass(BouncingCanvasParticlesStage,
+ function ()
+ {
+ BouncingCanvasParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingCanvasParticlesStage.prototype.initialize.call(this, benchmark, options);
+ this.parseShapeParameters(options);
+ },
+
+ createParticle: function()
+ {
+ return new BouncingCanvasShape(this);
+ }
+});
+
+BouncingCanvasShapesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingCanvasShapesStage(), options);
+ }
+);
+
+window.benchmarkClass = BouncingCanvasShapesBenchmark;
+
+})(); \ No newline at end of file
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-images.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-images.js
new file mode 100644
index 0000000000..ce9a48c276
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-images.js
@@ -0,0 +1,61 @@
+(function() {
+
+BouncingCssImage = Utilities.createSubclass(BouncingParticle,
+ function(stage)
+ {
+ BouncingParticle.call(this, stage);
+
+ this.element = document.createElement("img");
+ this.element.style.width = this.size.x + "px";
+ this.element.style.height = this.size.y + "px";
+ this.element.setAttribute("src", stage.imageSrc);
+
+ stage.element.appendChild(this.element);
+ this._move();
+ }, {
+
+ _move: function()
+ {
+ this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotater.rotateZ();
+ },
+
+ animate: function(timeDelta)
+ {
+ BouncingParticle.prototype.animate.call(this, timeDelta);
+ this._move();
+ }
+});
+
+BouncingCssImagesStage = Utilities.createSubclass(BouncingParticlesStage,
+ function()
+ {
+ BouncingParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingParticlesStage.prototype.initialize.call(this, benchmark, options);
+ this.imageSrc = options["imageSrc"] || "../resources/yin-yang.svg";
+ },
+
+ createParticle: function()
+ {
+ return new BouncingCssImage(this);
+ },
+
+ particleWillBeRemoved: function(particle)
+ {
+ particle.element.remove();
+ }
+});
+
+BouncingCssImagesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingCssImagesStage(), options);
+ }
+);
+
+window.benchmarkClass = BouncingCssImagesBenchmark;
+
+})();
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-shapes.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-shapes.js
new file mode 100644
index 0000000000..a1f81863f9
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-css-shapes.js
@@ -0,0 +1,86 @@
+(function() {
+
+BouncingCssShape = Utilities.createSubclass(BouncingParticle,
+ function(stage)
+ {
+ BouncingParticle.call(this, stage);
+
+ this.element = this._createSpan(stage);
+
+ switch (stage.fill) {
+ case "solid":
+ default:
+ this.element.style.backgroundColor = Stage.randomColor();
+ break;
+
+ case "gradient":
+ this.element.style.background = "linear-gradient(" + Stage.randomColor() + ", " + Stage.randomColor() + ")";
+ break;
+ }
+
+ if (stage.blend)
+ this.element.style.mixBlendMode = Stage.randomStyleMixBlendMode();
+
+ // Some browsers have not un-prefixed the css filter yet.
+ if (stage.filter)
+ Utilities.setElementPrefixedProperty(this.element, "filter", Stage.randomStyleFilter());
+
+ this._move();
+ }, {
+
+ _createSpan: function(stage)
+ {
+ var span = document.createElement("span");
+ span.className = stage.shape + " " + stage.clip;
+ span.style.width = this.size.x + "px";
+ span.style.height = this.size.y + "px";
+ stage.element.appendChild(span);
+ return span;
+ },
+
+ _move: function()
+ {
+ this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px)" + this.rotater.rotateZ();
+ },
+
+ animate: function(timeDelta)
+ {
+ BouncingParticle.prototype.animate.call(this, timeDelta);
+ this.rotater.next(timeDelta);
+ this._move();
+ }
+});
+
+BouncingCssShapesStage = Utilities.createSubclass(BouncingParticlesStage,
+ function()
+ {
+ BouncingParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingParticlesStage.prototype.initialize.call(this, benchmark, options);
+ this.parseShapeParameters(options);
+ },
+
+ createParticle: function()
+ {
+ return new BouncingCssShape(this);
+ },
+
+ particleWillBeRemoved: function(particle)
+ {
+ particle.element.remove();
+ }
+});
+
+BouncingCssShapesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingCssShapesStage(), options);
+ }
+);
+
+window.benchmarkClass = BouncingCssShapesBenchmark;
+
+})();
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-particles.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-particles.js
new file mode 100644
index 0000000000..27e02a7085
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-particles.js
@@ -0,0 +1,123 @@
+function BouncingParticle(stage)
+{
+ this._stageSize = stage.size;
+ this.size = stage.particleSize;
+
+ this.position = Stage.randomPosition(stage.size.subtract(stage.particleSize));
+ this._angle = Stage.randomAngle();
+ this._velocity = Stage.randomVelocity(stage.maxVelocity);
+ this.rotater = Stage.randomRotater();
+}
+
+BouncingParticle.prototype =
+{
+ get center()
+ {
+ return this.position.add(this.size.center);
+ },
+
+ animate: function(timeDelta)
+ {
+ this.position = this.position.move(this._angle, this._velocity, timeDelta);
+ this.rotater.next(timeDelta);
+
+ // If particle is going to move off right side
+ if (this.position.x + this.size.x > this._stageSize.x) {
+ // If direction is East-South, go West-South.
+ if (this._angle >= 0 && this._angle < Math.PI / 2)
+ this._angle = Math.PI - this._angle;
+ // If angle is East-North, go West-North.
+ else if (this._angle > Math.PI / 2 * 3)
+ this._angle = this._angle - (this._angle - Math.PI / 2 * 3) * 2;
+ // Make sure the particle does not go outside the stage boundaries.
+ this.position.x = this._stageSize.x - this.size.x;
+ }
+
+ // If particle is going to move off left side
+ if (this.position.x < 0) {
+ // If angle is West-South, go East-South.
+ if (this._angle > Math.PI / 2 && this._angle < Math.PI)
+ this._angle = Math.PI - this._angle;
+ // If angle is West-North, go East-North.
+ else if (this._angle > Math.PI && this._angle < Math.PI / 2 * 3)
+ this._angle = this._angle + (Math.PI / 2 * 3 - this._angle) * 2;
+ // Make sure the particle does not go outside the stage boundaries.
+ this.position.x = 0;
+ }
+
+ // If particle is going to move off bottom side
+ if (this.position.y + this.size.y > this._stageSize.y) {
+ // If direction is South, go North.
+ if (this._angle > 0 && this._angle < Math.PI)
+ this._angle = Math.PI * 2 - this._angle;
+ // Make sure the particle does not go outside the stage boundaries.
+ this.position.y = this._stageSize.y - this.size.y;
+ }
+
+ // If particle is going to move off top side
+ if (this.position.y < 0) {
+ // If direction is North, go South.
+ if (this._angle > Math.PI && this._angle < Math.PI * 2)
+ this._angle = this._angle - (this._angle - Math.PI) * 2;
+ // Make sure the particle does not go outside the stage boundaries.
+ this.position.y = 0;
+ }
+ }
+}
+
+BouncingParticlesStage = Utilities.createSubclass(Stage,
+ function()
+ {
+ Stage.call(this);
+ this.particles = [];
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ Stage.prototype.initialize.call(this, benchmark, options);
+ this.particleSize = new Point(parseInt(options["particleWidth"]) || 10, parseInt(options["particleHeight"]) || 10);
+ this.maxVelocity = Math.max(parseInt(options["maxVelocity"]) || 500, 100);
+ },
+
+ parseShapeParameters: function(options)
+ {
+ this.shape = options["shape"] || "circle";
+ this.fill = options["fill"] || "solid";
+ this.clip = options["clip"] || "";
+ this.blend = options["blend"] || false;
+ this.filter = options["filter"] || false;
+ },
+
+ animate: function(timeDelta)
+ {
+ this.particles.forEach(function(particle) {
+ particle.animate(timeDelta);
+ });
+ },
+
+ tune: function(count)
+ {
+ if (count == 0)
+ return;
+
+ if (count > 0) {
+ for (var i = 0; i < count; ++i)
+ this.particles.push(this.createParticle());
+ return;
+ }
+
+ count = Math.min(-count, this.particles.length);
+
+ if (typeof(this.particleWillBeRemoved) == "function") {
+ for (var i = 0; i < count; ++i)
+ this.particleWillBeRemoved(this.particles[this.particles.length - 1 - i]);
+ }
+
+ this.particles.splice(-count, count);
+ },
+
+ complexity: function()
+ {
+ return this.particles.length;
+ }
+});
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-images.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-images.js
new file mode 100644
index 0000000000..2239557312
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-images.js
@@ -0,0 +1,43 @@
+(function() {
+
+BouncingSvgImage = Utilities.createSubclass(BouncingSvgParticle,
+ function(stage)
+ {
+ BouncingSvgParticle.call(this, stage, "image");
+
+ var attrs = { x: 0, y: 0, width: this.size.x, height: this.size.y };
+ var xlinkAttrs = { href: stage.imageSrc };
+ this.element = Utilities.createSVGElement("image", attrs, xlinkAttrs, stage.element);
+ this._move();
+ }
+);
+
+BouncingSvgImagesStage = Utilities.createSubclass(BouncingSvgParticlesStage,
+ function()
+ {
+ BouncingSvgParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingSvgParticlesStage.prototype.initialize.call(this, benchmark, options);
+ this.imageSrc = options["imageSrc"] || "resources/yin-yang.svg";
+ },
+
+ createParticle: function()
+ {
+ return new BouncingSvgImage(this);
+ }
+});
+
+BouncingSvgImagesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingSvgImagesStage(), options);
+ }
+);
+
+window.benchmarkClass = BouncingSvgImagesBenchmark;
+
+})();
+
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-particles.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-particles.js
new file mode 100644
index 0000000000..0988c42d8e
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-particles.js
@@ -0,0 +1,67 @@
+BouncingSvgParticle = Utilities.createSubclass(BouncingParticle,
+ function(stage, shape)
+ {
+ BouncingParticle.call(this, stage);
+ this._shape = shape;
+ }, {
+
+ _applyClipping: function(stage)
+ {
+ if (stage.clip != "star")
+ return;
+
+ stage.ensureClipStarIsCreated();
+ this.element.setAttribute("clip-path", "url(#star-clip)");
+ },
+
+ _move: function()
+ {
+ var transform = "translate(" + this.position.x + ", " + this.position.y + ")";
+ if (this._shape != "circle")
+ transform += this.rotater.rotate(this.size.center);
+ this.element.setAttribute("transform", transform);
+ },
+
+ animate: function(timeDelta)
+ {
+ BouncingParticle.prototype.animate.call(this, timeDelta);
+ this._move();
+ }
+});
+
+BouncingSvgParticlesStage = Utilities.createSubclass(BouncingParticlesStage,
+ function()
+ {
+ BouncingParticlesStage.call(this);
+ }, {
+
+ _createDefs: function()
+ {
+ return Utilities.createSVGElement("defs", {}, {}, this.element);
+ },
+
+ _ensureDefsIsCreated: function()
+ {
+ return this.element.querySelector("defs") || this._createDefs();
+ },
+
+ _createClipStar: function()
+ {
+ var attrs = { id: "star-clip", clipPathUnits: "objectBoundingBox" };
+ var clipPath = Utilities.createSVGElement("clipPath", attrs, {}, this._ensureDefsIsCreated());
+
+ attrs = { d: "M.50,0L.38,.38L0,.38L.30,.60L.18,1L.50,.75L.82,1L.70,.60L1,.38L.62,.38z" };
+ Utilities.createSVGElement("path", attrs, {}, clipPath);
+ return clipPath;
+ },
+
+ ensureClipStarIsCreated: function()
+ {
+ return this.element.querySelector("#star-clip") || this._createClipStar();
+ },
+
+ particleWillBeRemoved: function(particle)
+ {
+ particle.element.remove();
+ }
+});
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-shapes.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-shapes.js
new file mode 100644
index 0000000000..14c917cc31
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-svg-shapes.js
@@ -0,0 +1,101 @@
+(function() {
+
+BouncingSvgShape = Utilities.createSubclass(BouncingSvgParticle,
+ function(stage)
+ {
+ BouncingSvgParticle.call(this, stage, stage.shape);
+ this._fill = stage.fill;
+
+ this._createShape(stage);
+ this._applyClipping(stage);
+ this._applyFill(stage);
+
+ this._move();
+ }, {
+
+ _createShape: function(stage)
+ {
+ switch (this._shape) {
+ case "rect":
+ var attrs = { x: 0, y: 0, width: this.size.x, height: this.size.y };
+ this.element = Utilities.createSVGElement("rect", attrs, {}, stage.element);
+ break;
+
+ case "circle":
+ default:
+ var attrs = { cx: this.size.x / 2, cy: this.size.y / 2, r: Math.min(this.size.x, this.size.y) / 2 };
+ this.element = Utilities.createSVGElement("circle", attrs, {}, stage.element);
+ break;
+ }
+ },
+
+ _applyFill: function(stage)
+ {
+ switch (this._fill) {
+ case "gradient":
+ var gradient = stage.createGradient(2);
+ this.element.setAttribute("fill", "url(#" + gradient.getAttribute("id") + ")");
+ break;
+
+ case "solid":
+ default:
+ this.element.setAttribute("fill", Stage.randomColor());
+ break;
+ }
+ }
+});
+
+BouncingSvgShapesStage = Utilities.createSubclass(BouncingSvgParticlesStage,
+ function()
+ {
+ BouncingSvgParticlesStage.call(this);
+ }, {
+
+ initialize: function(benchmark, options)
+ {
+ BouncingSvgParticlesStage.prototype.initialize.call(this, benchmark, options);
+ this.parseShapeParameters(options);
+ this._gradientsCount = 0;
+ },
+
+ createGradient: function(stops)
+ {
+ var attrs = { id: "gradient-" + ++this._gradientsCount };
+ var gradient = Utilities.createSVGElement("linearGradient", attrs, {}, this._ensureDefsIsCreated());
+
+ for (var i = 0; i < stops; ++i) {
+ attrs = { offset: i * 100 / (stops - 1) + "%", 'stop-color': Stage.randomColor() };
+ Utilities.createSVGElement("stop", attrs, {}, gradient);
+ }
+
+ return gradient;
+ },
+
+ createParticle: function()
+ {
+ return new BouncingSvgShape(this);
+ },
+
+ particleWillBeRemoved: function(particle)
+ {
+ BouncingSvgParticlesStage.prototype.particleWillBeRemoved.call(this, particle);
+
+ var fill = particle.element.getAttribute("fill");
+ if (fill.indexOf("url(#") != 0)
+ return;
+
+ var gradient = this.element.querySelector(fill.substring(4, fill.length - 1));
+ this._ensureDefsIsCreated().removeChild(gradient);
+ }
+});
+
+BouncingSvgShapesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingSvgShapesStage(), options);
+ }
+);
+
+window.benchmarkClass = BouncingSvgShapesBenchmark;
+
+})();
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js
new file mode 100644
index 0000000000..1ef6a091d2
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js
@@ -0,0 +1,106 @@
+(function() {
+
+BouncingTaggedImage = Utilities.createSubclass(BouncingParticle,
+ function(stage)
+ {
+ BouncingParticle.call(this, stage);
+
+ this.element = document.createElement("img");
+ this.element.style.width = this.size.x + "px";
+ this.element.style.height = this.size.y + "px";
+ this.element.setAttribute("src", Stage.randomElementInArray(stage.images).src);
+
+ stage.element.appendChild(this.element);
+ this._move();
+ }, {
+
+ _move: function()
+ {
+ this.element.style.transform = "translate(" + this.position.x + "px," + this.position.y + "px) " + this.rotater.rotateZ();
+ },
+
+ animate: function(timeDelta)
+ {
+ BouncingParticle.prototype.animate.call(this, timeDelta);
+ this._move();
+ }
+});
+
+BouncingTaggedImagesStage = Utilities.createSubclass(BouncingParticlesStage,
+
+ function()
+ {
+ BouncingParticlesStage.call(this);
+ }, {
+
+ imageSrcs: [
+ "image1",
+ "image2",
+ "image3",
+ "image4",
+ "image5",
+ ],
+ images: [],
+
+ initialize: function(benchmark, options)
+ {
+ BouncingParticlesStage.prototype.initialize.call(this, benchmark, options);
+
+ var lastPromise;
+ var images = this.images;
+ this.imageSrcs.forEach(function(imageSrc) {
+ var promise = this._loadImage("resources/" + imageSrc + ".jpg");
+ if (!lastPromise)
+ lastPromise = promise;
+ else {
+ lastPromise = lastPromise.then(function(img) {
+ images.push(img);
+ return promise;
+ });
+ }
+ }, this);
+
+ lastPromise.then(function(img) {
+ images.push(img);
+ benchmark.readyPromise.resolve();
+ });
+ },
+
+ _loadImage: function(src) {
+ var img = new Image;
+ var promise = new SimplePromise;
+
+ img.onload = function(e) {
+ promise.resolve(e.target);
+ };
+
+ img.src = src;
+ return promise;
+ },
+
+ createParticle: function()
+ {
+ return new BouncingTaggedImage(this);
+ },
+
+ particleWillBeRemoved: function(particle)
+ {
+ particle.element.remove();
+ }
+});
+
+BouncingTaggedImagesBenchmark = Utilities.createSubclass(Benchmark,
+ function(options)
+ {
+ Benchmark.call(this, new BouncingTaggedImagesStage(), options);
+ }, {
+
+ waitUntilReady: function() {
+ this.readyPromise = new SimplePromise;
+ return this.readyPromise;
+ }
+});
+
+window.benchmarkClass = BouncingTaggedImagesBenchmark;
+
+})();
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image1.jpg b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image1.jpg
new file mode 100644
index 0000000000..ea7a4c1303
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image1.jpg
Binary files differ
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image2.jpg b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image2.jpg
new file mode 100644
index 0000000000..697272dcb0
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image2.jpg
Binary files differ
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image3.jpg b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image3.jpg
new file mode 100644
index 0000000000..6e5964e7a9
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image3.jpg
Binary files differ
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image4.jpg b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image4.jpg
new file mode 100644
index 0000000000..806f548c44
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image4.jpg
Binary files differ
diff --git a/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image5.jpg b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image5.jpg
new file mode 100644
index 0000000000..d7971f6bcb
--- /dev/null
+++ b/third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/image5.jpg
Binary files differ