Bug 1246346 - patch 1 - Expose a DesktopToDevice scale factor on nsDeviceContext. r=emk
authorJonathan Kew <jkew@mozilla.com>
Fri, 12 Feb 2016 11:07:32 +0000
changeset 284382 8c76ded2edb9adf8193020127f059d4b79d5c61c
parent 284381 bbe59290c8257dafec58e13b8f656309ca882054
child 284383 fc5233e55fec8b05f8284d407f5e1ff4be6795d0
push id19537
push userkwierso@gmail.com
push dateWed, 17 Feb 2016 19:16:23 +0000
treeherderb2g-inbound@0c04a9efadab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1246346
milestone47.0a1
Bug 1246346 - patch 1 - Expose a DesktopToDevice scale factor on nsDeviceContext. r=emk
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -717,8 +717,23 @@ nsDeviceContext::SetFullZoom(float aScal
 void
 nsDeviceContext::UpdateAppUnitsForFullZoom()
 {
     mAppUnitsPerDevPixel =
         std::max(1, NSToIntRound(float(mAppUnitsPerDevPixelAtUnitFullZoom) / mFullZoom));
     // adjust mFullZoom to reflect appunit rounding
     mFullZoom = float(mAppUnitsPerDevPixelAtUnitFullZoom) / mAppUnitsPerDevPixel;
 }
+
+DesktopToLayoutDeviceScale
+nsDeviceContext::GetDesktopToDeviceScale()
+{
+    nsCOMPtr<nsIScreen> screen;
+    FindScreen(getter_AddRefs(screen));
+
+    if (screen) {
+        double scale;
+        screen->GetContentsScaleFactor(&scale);
+        return DesktopToLayoutDeviceScale(scale);
+    }
+
+    return DesktopToLayoutDeviceScale(1.0);
+}
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -246,16 +246,18 @@ public:
      */
     float GetFullZoom() const { return mFullZoom; }
 
     /**
      * True if this device context was created for printing.
      */
     bool IsPrinterSurface();
 
+    mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale();
+
 private:
     // Private destructor, to discourage deletion outside of Release():
     ~nsDeviceContext();
 
     void SetDPI();
     void ComputeClientRectUsingScreen(nsRect *outRect);
     void ComputeFullAreaUsingScreen(nsRect *outRect);
     void FindScreen(nsIScreen **outScreen);