rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Device pixel ratio for tests

Open gsnedders opened this issue 11 months ago • 3 comments

https://web-platform-tests.org/writing-tests/assumptions.html doesn't document anything about what the device pixel ratio of the viewport is (for HiDPI/Hi-DPI/retina/etc. displays).

RFC #41: Print Testing says for print that we rasterise it at 96 dpi, but doesn't say what device pixel ratio we render at:

The WebDriver-based implementation first renders the document to a PDF, and then computes the reftest result by rasterising the test and ref PDFs at 96 dpi.

There is prior discussion in https://github.com/web-platform-tests/wpt/issues/7140, https://github.com/web-platform-tests/wpt/issues/20284, and https://github.com/web-platform-tests/wpt/issues/31457.

As far as I can tell, for Gecko it is set to 1.0 in:

https://github.com/mozilla/gecko-dev/blob/fd2b3e70974daa97cd27b24fd3484abb662c671f/testing/profiles/web-platform/user.js#L48-L49

And:

https://github.com/web-platform-tests/wpt/blob/85b598e6524f25d7821a824d6c5e9a3f848740b8/tools/wptrunner/wptrunner/browsers/firefox_android.py#L181-L182

WebKit, for WKTR, sets it in:

https://github.com/WebKit/WebKit/blob/312e1f95f86f42d48b464e54109375a036572cde/Tools/WebKitTestRunner/TestOptions.cpp#L222

This is, however, ignored on iOS. (For DRT, it's set in many places, per-platform, and I'm not gonna link to all of them here!)

Chromium I think does this in many places, depending on how it is being run, but I'm not totally sure. That said, some of the failures on wpt.fyi seem like they might be caused by running at a device pixel ratio which is not 1.0, though we don't have screenshots to see what's going on there.

Currently, on wpt.fyi, Edge and Safari are both run on HiDPI screens, I believe; see https://github.com/web-platform-tests/wpt/issues/5498 and https://github.com/web-platform-tests/wpt/issues/20058.

WebDriver doesn't expose any way to change the device pixel ratio, https://github.com/w3c/webdriver/issues/1547, though WebDriver BiDi does, thus currently our only way to do this is via settings.

gsnedders avatar Mar 18 '25 23:03 gsnedders

As far as I'm aware, Chromium runs parts of WPT at different device pixel ratios: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/VirtualTestSuites;l=494-516;drc=b1fbe98c86c48fb62688a58160f024f80fff16c3

Whereas Gecko does not?

gsnedders avatar May 28 '25 22:05 gsnedders

Gecko doesn't have a specific CI configuration with different DPRs at the moment as far as I know; we just fix it to 1 everywhere.

jgraham avatar Jun 03 '25 15:06 jgraham

I think we should:

  • Try running both Firefox and Chromium at different DPRs, see how much breaks.
  • Try this, plus inject image-rendering: crisp-edges into reftests, and see if that improves matters.

We (WPT) can relatively easily:

  • Add support for <meta name=dpi> (or maybe device-pixel-ratio or something else) beyond Servo, which we can do with WebDriver BiDi.
  • Either make no <meta name=dpi> be undefined about what device-pixel-ratio is used, or define it to be 1.0 pending the above investigation.

We (WebKit) would like to be able to run tests in a configuration we actually ship, and for iOS (and most other UIKit platforms) that means almost always at least 2x.

gsnedders avatar Jul 01 '25 15:07 gsnedders