LWN.net Logo

High resolution displays and GNOME

By Nathan Willis
August 7, 2013
GUADEC 2013

For years, developers have lived comfortably with the assumption that screen resolutions were in the predictable confines of a certain pixel density—around 75 to 100 pixels-per-inch (ppi). As everyone who sees the latest Chromebook models from Google knows, however, such is no longer the case: the newest displays are well over 200 ppi. There have been partially-completed attempts to modify GNOME for high-resolution display support, but with little success. But now there appears to be a workable solution, as Alex Larsson demonstrated at GUADEC 2013.

The latest Chromebook (the "Pixel") boasts a 239 ppi screen, Larsson said, at which resolution GNOME's user interface elements are unreadably tiny. Allegedly, the display resolution is configurable, via the Xft.DPI setting, which has long been hard-coded to 96 in GNOME. But simply changing it to 239 does not work; as he showed the audience, the result only scales the size of displayed text. Although that improves legibility, UI elements like buttons and scrollbars are still ridiculously tiny. In addition, text labels and icons no longer line up, the default heights of menu bars and buttons is no longer correct, and many other UI assumptions are broken.

[Alex Larsson]

Perhaps the system could be modified to scale everything according to this DPI setting, he said. But despite the fact that the idea seems intuitive, he continued, simply scaling all of the UI elements is not the solution—scaling lines to a non-integer-multiple gives the user fuzzy lines that should be sharp and blurry icons that arguably look worse than the unscaled originals. Vector elements need to be drawn so that they align to the pixel grid of the display, and a separate fix needs to be available for those elements still using PNG or other raster graphics formats.

There are a lot of places in GNOME's user interface that are implicitly sized according to raster images and pixel-specific measurements: icons, cursors, window borders, padding, the minimum sizes of GTK+ widgets—even the cursor speed is defined in terms of pixels. The list of places where the code would need to change is lengthy, and changing it holds the possibility for a lot of unexpected breakage.

But then again, he continued, scaling everything to the exact same physical size is not strictly required; users already cope well with the variations in size caused by the different resolutions of laptop displays and external monitors; no one complains that a button is 6mm high on one and 8mm high on the other. All that really matters is that the system scales elements to approximately similar size on the Pixel display.

Abstraction to the rescue

The notion that the correct solution only needs to approximate the difference in resolution turned out to be one of the key insights. Larsson's eventual answer was to treat the existing "pixel" sizes already in use as an abstract, rather than a physical measurement, so that high-resolution displays appear low-resolution to the top levels of the software stack, and to set a scaling factor that multiplies the actual pixel count rendered on high-resolution displays. For almost everything above the drawing layer, the current definition of pixel would suffice; the pixel size itself could be scaled only when rendered by the lower-level libraries like Cairo and GDK, with very few side effects. Moreover, by always scaling abstract pixels to monitor pixels by integer factors, the pixel grid would automatically be preserved, meaning vector images would remain sharp—and the math would be considerably simpler, too.

He then implemented the abstract pixel scaling plan in Cairo, GDK, and GTK+. Normal monitors are unaffected, as their scaling factor is 1. "HiDPI" monitors like the Pixel use a scaling factor of 2, which results in a usable desktop interface, despite the on-screen elements not quite being the same physical dimensions.

In Cairo, the high-resolution scale factor is applied when the Cairo surface is rendered; applications can access the scaling factor for the display with cairo_surface_get_device_scale(), but normally GTK+ hides it completely. Similarly, in GDK, the sizes and positions of windows, screens, and monitors is still reported in abstract pixels; gdk_window_get_scale_factor() will report the scaling factor, but it is usually unnecessary for applications to know it. Wayland compositors will scale client buffers as necessary, and will allow clients to provide double-scale buffers to cope with the occasional window that spans both a high- and low-resolution display. X support is less flexible; all displays must be the same scale, which is reported via the GDK_SCALE environment variable, but, Larsson said, Wayland is the protocol of the future, so the development there is more important.

There are new functions like gdk_window_create_similar_surface() to transparently create an offscreen surface for the purpose of double-buffering, and GtkIconTheme has been patched to support specifying both normal-resolution and high-resolution versions of icons, but by and large the scaling function is invisible to application code. There are also hooks in place for use when displaying images and other situations where scaling up window content is inappropriate. The scaling functionality is due to land in Cairo 1.13, and Wayland support has been added in version 1.2 of the Wayland protocol definition. The GTK+ and GDK changes are currently available in Larsson's wip/window-scales branch.

Larsson added that GTK+ on Mac OS X also supports the scaling factor, using the operating system's Quartz library. Windows support, however, remains on the to-do list. For the time being, there are very few displays on the market that require a scaling factor other than 1. Larsson described the Chromebook Pixel as the primary driving factor, but Apple Retina displays are also supported, and there are a handful of high-density netbook displays that qualify as high-resolution as well. For the present, 1 and 2 remain the only scaling factors in deployment. There is no telling if or when a 3 or 4 scaling factor will be required for some future display, but when it does, the GNOME stack will be prepared well in advance.

[The author wishes to thank the GNOME Foundation for assistance with travel to GUADEC 2013.]


(Log in to post comments)

High resolution displays and GNOME

Posted Aug 8, 2013 9:11 UTC (Thu) by njwhite (subscriber, #51848) [Link]

This whole "abstract" vs "physical" pixel thing (which CSS has also embraced) feels like a massive kludge to me. It's really weird to define the standard measurement in terms of "this is roughly 1/96 inch, potentially depending on how far from the user the screen is planned to be".

If that really is the most sensible measurement to use, then terminology clearer than "abstract pixel" should be used. Because people have an idea of what a pixel is, and it ain't that.

I like the idea of using something like CSS's 'em' as a base unit. That also ensures interfaces are likely to scale sanely if a user could benefit from an unusually large font size.

High resolution displays and GNOME

Posted Aug 8, 2013 10:01 UTC (Thu) by alexl (subscriber, #19068) [Link]

CSS defines the term "px" for this (with a very interesting definion [1]). OSX uses "points".

Unfortunately we're in a situation where a of code already uses the term "pixel", and we're keeping that API, just making it do something slightly different. That meant it hard to apply a new name to all these existing places.

em:s are useful in some places, like maybe padding and line spacing. Not so much for e.g. border widths, raster images, etc.

[1] http://www.w3.org/TR/2013/CR-css3-values-20130730/#refere...

High resolution displays and GNOME

Posted Aug 8, 2013 10:34 UTC (Thu) by njwhite (subscriber, #51848) [Link]

> em:s are useful in some places, like maybe padding and line spacing. Not so much for e.g. border widths, raster images, etc.

True. Though reference pixels aren't a great way of describing raster images either (you'd want real pixels really, or ideally of course vector everywhere), and border widths might be better served with something like "thin" / "medium" / "thick". You'd lose a certain amount of pixel perfect expressability, but in reality you do anyway when you deal with varying pixel densities.

> Unfortunately we're in a situation where a of code already uses the term "pixel", and we're keeping that API, just making it do something slightly different.

I see that, and your abstract pixel way is a pretty clever hack to make things work well with new screens. But I wonder whether we can imagine a better way to lay things out going for the future. I haven't actually coded GTK+ much at all, or Qt (Tk and CSS are the only graphics layout engines I know well), but perhaps there are already better systems available that I'm just ignorant of.

High resolution displays and GNOME

Posted Aug 9, 2013 17:33 UTC (Fri) by zenaan (subscriber, #3778) [Link]

> but perhaps there are already better systems available that I'm just ignorant of.

Enlightenment's e* elibs?
My understanding is that they are all-singing all-dancing when it comes to ultimate scalability and declaratively-expressed UIs...
Just my hearsay though.

High resolution displays and GNOME

Posted Aug 8, 2013 20:39 UTC (Thu) by cladisch (✭ supporter ✭, #50193) [Link]

> I like the idea of using something like CSS's 'em' as a base unit. That also ensures interfaces are likely to scale sanely if a user could benefit from an unusually large font size.

Windows has always done this in dialog box templates. (In the times of 16-bit Windows, this was useful not for high-resolution displays but for non-square pixels on EGA/HGC cards. And nobody dared to waste memory on bitmaps.)

This would be easy to implement, but I have not found support for something like this in any cross-platform GUI toolkit except wxWindows.

High resolution displays and GNOME

Posted Aug 8, 2013 9:19 UTC (Thu) by SLi (subscriber, #53131) [Link]

PDFs can be made to look good at any DPI and zoom level. Why are user interfaces different? Is it only because there still are (legacy) rasterized icons?

High resolution displays and GNOME

Posted Aug 8, 2013 19:45 UTC (Thu) by ncm (subscriber, #165) [Link]

Pretty much. Once upon a time, the NeXT computer used "Display Postscript" to construct user-interface elements, dimensioned in points. The approach was a rousing success; the company, less so, but for other reasons. Icons are just specialized characters (with colors!) that could be represented much the same way, and wrangled with the same code.

High resolution displays and GNOME

Posted Aug 13, 2013 16:42 UTC (Tue) by smoogen (subscriber, #97) [Link]

Didn't the original Sun Windows from SunOS 4 also use Display Postscript. The major problem was that both NeXT and Sun (and the other Unix vendors) had the patent and other rights to use Postscript under proprietary licenses with Adobe which made using it in MIT/X or similar things impossible. [Each OS doing so also implemented it in a way that you couldn't get it to work on another system with some sort of "Display Postscript" which ended its usefulness for hackers.]

High resolution displays and GNOME

Posted Aug 13, 2013 17:32 UTC (Tue) by andrel (subscriber, #5166) [Link]

You're thinking of NeWS.

High resolution displays and GNOME

Posted Aug 15, 2013 21:19 UTC (Thu) by solenskiner (guest, #67077) [Link]

I believe the idea lives on in OSX, just using PDF instead of DPS.

Such far-reaching innovation

Posted Aug 8, 2013 10:05 UTC (Thu) by ncm (subscriber, #165) [Link]

"Abstract pixel" reads, to me, an awful lot like "point", as in "11-point Garamond type". Haven't we been down this road a few times already?

If only there were a way to record others' experience and propagate it widely so that all might learn from it. (We might call this "publication".) To represent experiences we would need conceptual elements (which we may call "words") accumulated into a sequence constructed according to rules we might call "syntax" by which others may analyze it and extract meaning. Maybe these "words" could have audio representations chosen such that we can express them vocally, and visual representations that can be etched or inked onto convenient surfaces. Finicky parts of the process could be automated, and repetitive thematic elements could be collected into, say, "fonts". There's no telling how sophisticated such a medium might become, if only each new generation could bring itself to build upon the achievements of the last.

But alas! this will always be only a dream.

Such far-reaching innovation

Posted Aug 8, 2013 15:15 UTC (Thu) by ovitters (subscriber, #27950) [Link]

It just does what Apple does basically. Meaning: if you specify 1 pixel, it can be interpreted as 1 pixel or a multiple of it. Why you cannot do the same as fonts/points was explained by LWN.

I don't see the purpose for your long paragraph btw.

Such far-reaching innovation

Posted Aug 8, 2013 19:38 UTC (Thu) by ncm (subscriber, #165) [Link]

I don't see the purpose for your long paragraph...

Alas!

Such far-reaching innovation

Posted Aug 8, 2013 20:11 UTC (Thu) by jimparis (subscriber, #38647) [Link]

> "Abstract pixel" reads, to me, an awful lot like "point", as in "11-point Garamond type". Haven't we been down this road a few times already?

Yeah, but I think people are only recently starting to realize that sizing things in points doesn't make much sense either, now that we have cell phones, desktops, and TVs all running the same code. Something like CSS3's px (which is really just 1px = 0.0213 arcseconds) is much better.

Such far-reaching innovation

Posted Aug 9, 2013 4:28 UTC (Fri) by Ben_P (subscriber, #74247) [Link]

Having 1px defined in terms of arcseconds sounded fantastic; but http://www.w3.org/TR/2013/CR-css3-values-20130730/#absolu... ?

Such far-reaching innovation

Posted Aug 9, 2013 15:23 UTC (Fri) by jimparis (subscriber, #38647) [Link]

> Having 1px defined in terms of arcseconds sounded fantastic; but http://www.w3.org/TR/2013/CR-css3-values-20130730/#absolu... ?

That's the page I was reading (except I messed up the units). I think it's saying that you have the option of scaling 1px so that it matches a particular angular size, when it makes sense:

"For a CSS device, these dimensions are either anchored (i) by relating the physical units to their physical measurements, or (ii) by relating the pixel unit to the reference pixel ... For such devices it is recommended that the pixel unit refer to the whole number of device pixels that best approximates the reference pixel."

"The reference pixel is the visual angle of one pixel on a device with a pixel density of 96dpi and a distance from the reader of an arm's length. For a nominal arm's length of 28 inches, the visual angle is therefore about 0.0213 degrees."

Angular inspiration

Posted Aug 9, 2013 5:38 UTC (Fri) by ncm (subscriber, #165) [Link]

I acknowledge that an angular measure is technically better than an absolute linear measure. But everybody knows what 10-point type looks like in a book held in your hands, and the ratio of (variable) height to (standard) distance is an angular measure -- indeed, radians, if you were to use the same units. And, keeping things integral is a good idea, but not exactly earth-shaking.

But I find it hard to believe 0.0213 arcseconds for any visible pixel-like object. 10-point type at 18 inches subtends 1.6K arcseconds = 24 arcminutes, or 7.7K μradians. Probably you mean 0.0213 degrees at 28 inches (which is pretty far away). So, a pretty good size for a point is 770 μradians.

Angular inspiration

Posted Aug 9, 2013 15:25 UTC (Fri) by jimparis (subscriber, #38647) [Link]

I messed up the units; you're correct. CSS says 0.0213 degrees for the "reference pixel".

Breaking things on intent

Posted Aug 26, 2013 18:29 UTC (Mon) by gvy (guest, #11981) [Link]

Some GNOME and Fedora so called developers *suck* big time: they're translating their broken "one size fits all" so called mentality onto everything.

These idiots have broken X.org regarding DPI autodetection.

And strangely enough the breakage was quite quick to go in but the patch to at least partially fix it is not:

https://bugs.freedesktop.org/23705
https://bugs.freedesktop.org/41115

Shame on you, Red Hat!

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds