Bug 1509358. Replace DCFromDrawTarget with DCForMetrics. r=jfkthame
authorJeff Muizelaar <jrmuizel@gmail.com>
Mon, 26 Nov 2018 16:01:19 +0000
changeset 504428 ef8fb4300e67a3857a65a2c9aa2528f65c6a07cb
parent 504427 374a4bf1482e462845215fded70e4f7854b10271
child 504429 61c3a6ce72a0de3582d7a5bd08b173facdfba901
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1509358
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509358. Replace DCFromDrawTarget with DCForMetrics. r=jfkthame The GDI font code path is very rarely used, further when it used we don't ever seem to get any DrawTarget that's not Skia and so never try to pull the DC out of the DrawTarget anyways. I tested this by forcing on GDI fonts, running the browser and printing, with and without e10s. However, Jonathan Kew was able to trigger this path. I'm not sure why. Making this change will let us rip out a bunch of code that threads the DrawTarget through the text code. Differential Revision: https://phabricator.services.mozilla.com/D12689
gfx/thebes/gfxGDIFont.cpp
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
--- a/gfx/thebes/gfxGDIFont.cpp
+++ b/gfx/thebes/gfxGDIFont.cpp
@@ -523,17 +523,17 @@ gfxGDIFont::GetGlyphWidth(DrawTarget& aD
         mGlyphWidths = MakeUnique<nsDataHashtable<nsUint32HashKey,int32_t>>(128);
     }
 
     int32_t width;
     if (mGlyphWidths->Get(aGID, &width)) {
         return width;
     }
 
-    DCFromDrawTarget dc(aDrawTarget);
+    DCForMetrics dc;
     AutoSelectFont fs(dc, GetHFONT());
 
     int devWidth;
     if (GetCharWidthI(dc, aGID, 1, nullptr, &devWidth)) {
         // clamp value to range [0..0x7fff], and convert to 16.16 fixed-point
         devWidth = std::min(std::max(0, devWidth), 0x7fff);
         width = devWidth << 16;
         mGlyphWidths->Put(aGID, width);
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -90,44 +90,21 @@
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 using namespace mozilla::widget;
 using namespace mozilla::image;
 using namespace mozilla::unicode;
 
-DCFromDrawTarget::DCFromDrawTarget(DrawTarget& aDrawTarget)
+DCForMetrics::DCForMetrics()
 {
-  mDC = nullptr;
-  if (aDrawTarget.GetBackendType() == BackendType::CAIRO) {
-    cairo_t* ctx = static_cast<cairo_t*>
-      (aDrawTarget.GetNativeSurface(NativeSurfaceType::CAIRO_CONTEXT));
-    if (ctx) {
-      cairo_surface_t* surf = cairo_get_group_target(ctx);
-      if (surf) {
-        cairo_surface_type_t surfaceType = cairo_surface_get_type(surf);
-        if (surfaceType == CAIRO_SURFACE_TYPE_WIN32 ||
-            surfaceType == CAIRO_SURFACE_TYPE_WIN32_PRINTING) {
-          mDC = cairo_win32_surface_get_dc(surf);
-          mNeedsRelease = false;
-          SaveDC(mDC);
-          cairo_scaled_font_t* scaled = cairo_get_scaled_font(ctx);
-          cairo_win32_scaled_font_select_font(scaled, mDC);
-        }
-      }
-    }
-  }
-
-  if (!mDC) {
-    // Get the whole screen DC:
-    mDC = GetDC(nullptr);
-    SetGraphicsMode(mDC, GM_ADVANCED);
-    mNeedsRelease = true;
-  }
+  // Get the whole screen DC:
+  mDC = GetDC(nullptr);
+  SetGraphicsMode(mDC, GM_ADVANCED);
 }
 
 class GfxD2DVramReporter final : public nsIMemoryReporter
 {
     ~GfxD2DVramReporter() {}
 
 public:
     NS_DECL_ISUPPORTS
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -57,36 +57,31 @@ struct IDirect3DDevice9;
 struct ID3D11Device;
 struct IDXGIAdapter1;
 
 /**
  * Utility to get a Windows HDC from a Moz2D DrawTarget.  If the DrawTarget is
  * not backed by a HDC this will get the HDC for the screen device context
  * instead.
  */
-class MOZ_STACK_CLASS DCFromDrawTarget final
+class MOZ_STACK_CLASS DCForMetrics final
 {
 public:
-    explicit DCFromDrawTarget(mozilla::gfx::DrawTarget& aDrawTarget);
+    explicit DCForMetrics();
 
-    ~DCFromDrawTarget() {
-        if (mNeedsRelease) {
-            ReleaseDC(nullptr, mDC);
-        } else {
-            RestoreDC(mDC, -1);
-        }
+    ~DCForMetrics() {
+        ReleaseDC(nullptr, mDC);
     }
 
     operator HDC () {
         return mDC;
     }
 
 private:
     HDC mDC;
-    bool mNeedsRelease;
 };
 
 // ClearType parameters set by running ClearType tuner
 struct ClearTypeParameterInfo {
     ClearTypeParameterInfo() :
         gamma(-1), pixelStructure(-1), clearTypeLevel(-1), enhancedContrast(-1)
     { }