[webkit-dev] Possible device scale factor emulation approaches?
abarth at webkit.org
Wed Dec 5 17:28:17 PST 2012
On Wed, Dec 5, 2012 at 7:16 AM, Alexander Pavlov <apavlov at chromium.org> wrote:
> I'm working on emulating the device scale factor with Web Inspector. My goal
> is to let web developers see their pages on "normal" (device pixel ratio ==
> 1) monitors the way they would look on e.g. retina screens.
> Page::setDeviceScaleFactor() is not something we can use, since it will have
> the reverse effect when used by platform-specific compositor code (which I
> saw on Chromium, and its compositor is far from being ready for such
> abnormal treatment.)
I'm not sure I fully understand what you're trying to accomplish. Is
the developer using a high density screen or a low density screen?
Chromium has a command line option for setting a fake device pixel
ratio. For example, if you're using a low density screen, you can
pass something like --device-pixel-ratio 2 to ask Chromium to render
as if your device has a high density display. The net effect is that
the glyphs get really big (since they use 2x the pixels in each
Alternatively, I can imagine that the developer is using a high
density screen but wants to develop a web site that looks good on a
low density screen. In that case, they want to set a
--device-pixel-ratio 1 but then render the web page pixel doubled
(i.e., rasterizing each pixel as a 2x2 quad). I don't think there's a
command line option for that in Chromium, but it's something you might
reasonably do in the compositor.
In general, though, trying to shim this feature into WebCore isn't
likely the right approach. For WebKit2, for example, both the UI
process and the web process need to agree about the device pixel ratio
or else the system gets confused about how big various regions of
memory ought to be. If you look at how we test high density rendering
on low density machines, you'll see that we override the device's
actual pixel density via the WebKit/WebKit2 API. That's to avoid this
> I took the approach of instrumenting the WebCore/css and WebCore/page code
> relying on the page->deviceScaleFactor() value. This worked pretty well, and
> you can see the respective patch at
> (https://bugs.webkit.org/show_bug.cgi?id=100762), but now I'm wondering if
> there are better ways to implement this without instrumenting lots of
> page->deviceScaleFactor() call sites.
> Comments, ideas, suggestions, please?
If you want to see how this is done in Chromium, you might want to
study the --device-pixel-ratio command line flag. In general, I don't
think you want to try to implementing this feature by hacking WebCore
as it requires coordination beyond WebCore to do correctly.
More information about the webkit-dev