From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../resources/bouncing-tagged-images.js | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js (limited to 'third_party/webkit/PerformanceTests/MotionMark/tests/bouncing-particles/resources/bouncing-tagged-images.js') 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; + +})(); -- cgit v1.2.3