haikuwebkit/ManualTests/blur-filter-timing.html

94 lines
2.4 KiB
HTML
Raw Permalink Normal View History

[Apple] Use Accelerate framework to speed-up FEGaussianBlur https://bugs.webkit.org/show_bug.cgi?id=139310 <rdar://problem/18434594> PerformanceTests: Reviewed by Simon Fraser. Add an interactive performance test that measures the speed of a set of blur operations on a generated images. * Interactive/blur-filter-timing.html: Added. Source/WebCore: <rdar://problem/18434594> Reviewed by Simon Fraser. Using Apple's Accelerate framework provides faster blurs than the parallel jobs approach, especially since r168577 which started performing retina-accurate filters. Using Accelerate.framework to replace the existing box blur (what we use to approximate Gaussian blurs) gets about a 20% speedup on desktop class machines, but between a 2x-6x speedup on iOS hardware. Obviously this depends on the size of the content being blurred, but it is still good. The change is to intercept the platformApply function on FEGaussianBlur and send it off to Accelerate. There is an interactive performance test: PerformanceTests/Interactive/blur-filter-timing.html * platform/graphics/filters/FEGaussianBlur.cpp: (WebCore::kernelPosition): Move this to a file static function from the .h. (WebCore::accelerateBoxBlur): The Accelerate implementation. (WebCore::standardBoxBlur): The default generic/standard implementation. (WebCore::FEGaussianBlur::platformApplyGeneric): Use accelerate or the default form. (WebCore::FEGaussianBlur::platformApply): Don't try the parallelJobs approach if Accelerate is available. * platform/graphics/filters/FEGaussianBlur.h: (WebCore::FEGaussianBlur::kernelPosition): Deleted. Move into the .cpp. Source/WTF: <rdar://problem/18434594> Reviewed by Simon Fraser. Add a HAVE_ACCELERATE flag, true on Apple platforms. * wtf/Platform.h: Canonical link: https://commits.webkit.org/157279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177000 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-09 01:31:37 +00:00
<!DOCTYPE html>
<html>
<head>
<title>Timing test for blur filter</title>
<style>
img {
width: 600px;
height: 600px;
}
</style>
<script>
var WIDTH = 600;
var HEIGHT = 600;
var NUM_ITERATIONS = 10;
var MAX_RADIUS = 20;
var currentIteration = 0;
var currentRadius = 0;
var testIsRunning = false;
var image = null;
var startTime = null;
function init() {
document.querySelector("button").addEventListener("click", run, false);
image = document.querySelector("img");
// Fill the image with generated content. We can't use a canvas directly,
// since that gets composited.
var canvas = document.createElement("canvas");
canvas.width = WIDTH * window.devicePixelRatio;
canvas.height = HEIGHT * window.devicePixelRatio;
// Fill the canvas with some generated content.
var ctx = canvas.getContext("2d");
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
for (var i = 0; i < WIDTH; i += 20) {
for (var j = 0; j < HEIGHT; j += 20) {
ctx.fillStyle = "rgb(" + Math.round(i / WIDTH * 255) + ", " + Math.round(j / HEIGHT * 255) + ", " + (i % 40 ? 64 : 192) + ")";
ctx.fillRect(i, j, 20, 20);
}
}
image.src = canvas.toDataURL();
}
function run() {
if (testIsRunning)
return;
testIsRunning = true;
currentIteration = 0;
currentRadius = 0;
startTime = Date.now();
step();
}
function step() {
var usedRadius = (currentIteration % 2) ? (MAX_RADIUS - currentRadius) : currentRadius;
image.style.webkitFilter = "blur(" + usedRadius + "px)";
currentRadius++;
if (currentRadius > MAX_RADIUS) {
currentIteration++;
currentRadius = 0;
}
if (currentIteration < NUM_ITERATIONS)
setTimeout(step, 0);
else
end();
}
function end() {
testIsRunning = false;
var elapsedTime = (Date.now() - startTime) / 1000;
var result = document.createElement("p");
result.textContent = (NUM_ITERATIONS * MAX_RADIUS) + " blurs done in " + elapsedTime + " seconds";
document.body.appendChild(result);
if (window.testRunner)
testRunner.notifyDone();
}
window.addEventListener("load", init, false);
</script>
</head>
<body>
<img>
<p>
<button>Start</button>
</p>
</body>
</html>