Backed out 1 changesets (bug 1582749) for build bustage at /builds/worker/workspace/build/src/gfx/thebes/gfxFT2FontBase
authorDaniel Varga <dvarga@mozilla.com>
Sun, 22 Sep 2019 21:01:58 +0300
changeset 494450 2b8364cfdb04bfdfde7c01589e48e24973c1ce9c
parent 494449 db3d77b313a039dd81a586ffb60fb333cdf5da2d
child 494451 0621d05839f67e04c7fd97f52283fa0f9a71676c
push id36606
push userdvarga@mozilla.com
push dateSun, 22 Sep 2019 21:33:41 +0000
treeherdermozilla-central@2b8364cfdb04 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1582749
milestone71.0a1
backs outdb3d77b313a039dd81a586ffb60fb333cdf5da2d
first release with
nightly linux32
2b8364cfdb04 / 71.0a1 / 20190922213341 / files
nightly linux64
2b8364cfdb04 / 71.0a1 / 20190922213341 / files
nightly mac
2b8364cfdb04 / 71.0a1 / 20190922213341 / files
nightly win32
2b8364cfdb04 / 71.0a1 / 20190922213341 / files
nightly win64
2b8364cfdb04 / 71.0a1 / 20190922213341 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 1 changesets (bug 1582749) for build bustage at /builds/worker/workspace/build/src/gfx/thebes/gfxFT2FontBase Backed out changeset db3d77b313a0 (bug 1582749)
gfx/thebes/gfxFT2FontBase.cpp
gfx/thebes/gfxFT2FontBase.h
--- a/gfx/thebes/gfxFT2FontBase.cpp
+++ b/gfx/thebes/gfxFT2FontBase.cpp
@@ -133,42 +133,30 @@ static void SnapLineToPixels(gfxFloat& a
   gfxFloat snappedSize = std::max(floor(aSize + 0.5), 1.0);
   // Correct offset for change in size
   gfxFloat offset = aOffset - 0.5 * (aSize - snappedSize);
   // Snap offset
   aOffset = floor(offset + 0.5);
   aSize = snappedSize;
 }
 
-static inline gfxRect ScaleGlyphBounds(const IntRect& aBounds,
-                                       gfxFloat aScale) {
-  return gfxRect(FLOAT_FROM_26_6(aBounds.x) * aScale,
-                 FLOAT_FROM_26_6(aBounds.y) * aScale,
-                 FLOAT_FROM_26_6(aBounds.width) * aScale,
-                 FLOAT_FROM_26_6(aBounds.height) * aScale);
-}
-
 /**
  * Get extents for a simple character representable by a single glyph.
  * The return value is the glyph id of that glyph or zero if no such glyph
  * exists.  aWidth/aBounds is only set when this returns a non-zero glyph id.
  * This is just for use during initialization, and doesn't use the width cache.
  */
 uint32_t gfxFT2FontBase::GetCharExtents(char aChar, gfxFloat* aWidth,
                                         gfxRect* aBounds) {
   FT_UInt gid = GetGlyph(aChar);
   int32_t width;
-  IntRect bounds;
-  if (gid && GetFTGlyphExtents(gid, &width, &bounds)) {
+  if (gid && GetFTGlyphExtents(gid, &width, aBounds)) {
     if (aWidth) {
       *aWidth = FLOAT_FROM_16_16(width);
     }
-    if (aBounds) {
-      *aBounds = ScaleGlyphBounds(bounds, GetAdjustedSize() / mFTSize);
-    }
     return gid;
   } else {
     return 0;
   }
 }
 
 /**
  * Find the closest available fixed strike size, if applicable, to the
@@ -496,17 +484,17 @@ uint32_t gfxFT2FontBase::GetGlyph(uint32
     }
     return 0;
   }
 
   return GetGlyph(unicode);
 }
 
 FT_Vector gfxFT2FontBase::GetEmboldenStrength(FT_Face aFace) {
-  FT_Vector strength = {0, 0};
+  FT_Vector strength = { 0, 0 };
   if (!mEmbolden) {
     return strength;
   }
   // This is the embolden "strength" used by FT_GlyphSlot_Embolden.
   strength.x =
       FT_MulFix(aFace->units_per_EM, aFace->size->metrics.y_scale) / 24;
   strength.y = strength.x;
   if (aFace->glyph->format == FT_GLYPH_FORMAT_BITMAP) {
@@ -515,26 +503,27 @@ FT_Vector gfxFT2FontBase::GetEmboldenStr
       strength.x = 64;
     }
     strength.y &= -64;
   }
   return strength;
 }
 
 bool gfxFT2FontBase::GetFTGlyphExtents(uint16_t aGID, int32_t* aAdvance,
-                                       IntRect* aBounds) {
+                                       gfxRect* aBounds) {
   gfxFT2LockedFace face(this);
   MOZ_ASSERT(face.get());
   if (!face.get()) {
     // Failed to get the FT_Face? Give up already.
     NS_WARNING("failed to get FT_Face!");
     return false;
   }
 
-  if (Factory::LoadFTGlyph(face.get(), aGID, mFTLoadFlags) != FT_Err_Ok) {
+  FT_Error ftError = Factory::LoadFTGlyph(face.get(), aGID, mFTLoadFlags);
+  if (ftError != FT_Err_Ok) {
     // FT_Face was somehow broken/invalid? Don't try to access glyph slot.
     // This probably shouldn't happen, but does: see bug 1440938.
     NS_WARNING("failed to load glyph!");
     return false;
   }
 
   bool hintMetrics = ShouldHintMetrics();
 
@@ -578,66 +567,46 @@ bool gfxFT2FontBase::GetFTGlyphExtents(u
     y -= bold.y;
     x2 += bold.x;
     if (hintMetrics && (mFTLoadFlags & FT_LOAD_NO_HINTING)) {
       x &= -64;
       y &= -64;
       x2 = (x2 + 63) & -64;
       y2 = (y2 + 63) & -64;
     }
-    *aBounds = IntRect(x, y, x2 - x, y2 - y);
+    *aBounds = gfxRect(FLOAT_FROM_26_6(x) * extentsScale,
+                       FLOAT_FROM_26_6(y) * extentsScale,
+                       FLOAT_FROM_26_6(x2 - x) * extentsScale,
+                       FLOAT_FROM_26_6(y2 - y) * extentsScale);
   }
   return true;
 }
 
-/**
- * Get the cached glyph metrics for the glyph id if available. Otherwise, query
- * FreeType for the glyph extents and initialize the glyph metrics.
- */
-const gfxFT2FontBase::GlyphMetrics& gfxFT2FontBase::GetCachedGlyphMetrics(
-    uint16_t aGID) {
-  if (!mGlyphMetrics) {
-    mGlyphMetrics =
-        mozilla::MakeUnique<nsDataHashtable<nsUint32HashKey, GlyphMetrics>>(
-            128);
+int32_t gfxFT2FontBase::GetGlyphWidth(uint16_t aGID) {
+  if (!mGlyphWidths) {
+    mGlyphWidths =
+        mozilla::MakeUnique<nsDataHashtable<nsUint32HashKey, int32_t>>(128);
   }
 
-  if (const GlyphMetrics* metrics = mGlyphMetrics->GetValue(aGID)) {
-    return *metrics;
+  int32_t width;
+  if (mGlyphWidths->Get(aGID, &width)) {
+    return width;
   }
 
-  GlyphMetrics& metrics = mGlyphMetrics->GetOrInsert(aGID);
-  IntRect bounds;
-  if (GetFTGlyphExtents(aGID, &metrics.mAdvance, &bounds)) {
-    metrics.SetBounds(bounds);
+  if (!GetFTGlyphExtents(aGID, &width)) {
+    width = 0;
   }
-  return metrics;
-}
+  mGlyphWidths->Put(aGID, width);
 
-int32_t gfxFT2FontBase::GetGlyphWidth(uint16_t aGID) {
-  return GetCachedGlyphMetrics(aGID).mAdvance;
+  return width;
 }
 
 bool gfxFT2FontBase::GetGlyphBounds(uint16_t aGID, gfxRect* aBounds,
                                     bool aTight) {
-  const GlyphMetrics& metrics = GetCachedGlyphMetrics(aGID);
-  if (!metrics.HasValidBounds()) {
-    return false;
-  }
-  // Check if there are cached bounds and use those if available. Otherwise,
-  // fall back to directly querying the glyph extents.
-  IntRect bounds;
-  if (metrics.HasCachedBounds()) {
-    bounds = metrics.GetBounds();
-  } else if (!GetFTGlyphExtents(aGID, nullptr, &bounds)) {
-    return false;
-  }
-  // The bounds are stored unscaled, so must be scaled to the adjusted size.
-  *aBounds = ScaleGlyphBounds(bounds, GetAdjustedSize() / mFTSize);
-  return true;
+  return GetFTGlyphExtents(aGID, nullptr, aBounds);
 }
 
 // For variation fonts, figure out the variation coordinates to be applied
 // for each axis, in freetype's order (which may not match the order of
 // axes in mStyle.variationSettings, so we need to search by axis tag).
 /*static*/
 void gfxFT2FontBase::SetupVarCoords(
     FT_MM_Var* aMMVar, const nsTArray<gfxFontVariation>& aVariations,
--- a/gfx/thebes/gfxFT2FontBase.h
+++ b/gfx/thebes/gfxFT2FontBase.h
@@ -43,17 +43,17 @@ class gfxFT2FontBase : public gfxFont {
 
  private:
   uint32_t GetCharExtents(char aChar, gfxFloat* aWidth,
                           gfxRect* aBounds = nullptr);
 
   // Get advance (and optionally bounds) of a single glyph from FreeType,
   // and return true, or return false if we failed.
   bool GetFTGlyphExtents(uint16_t aGID, int32_t* aWidth,
-                         mozilla::gfx::IntRect* aBounds = nullptr);
+                         gfxRect* aBounds = nullptr);
 
  protected:
   void InitMetrics();
   const Metrics& GetHorizontalMetrics() override;
   FT_Vector GetEmboldenStrength(FT_Face aFace);
 
   RefPtr<mozilla::gfx::SharedFTFace> mFTFace;
 
@@ -65,60 +65,17 @@ class gfxFT2FontBase : public gfxFont {
 
   // For variation/multiple-master fonts, this will be an array of the values
   // for each axis, as specified by mStyle.variationSettings (or the font's
   // default for axes not present in variationSettings). Values here are in
   // freetype's 16.16 fixed-point format, and clamped to the valid min/max
   // range reported by the face.
   nsTArray<FT_Fixed> mCoords;
 
-  // Store cached glyph metrics for reasonably small glyph sizes. The bounds
-  // are stored unscaled to losslessly compress 26.6 fixed point to an int16_t.
-  // Larger glyphs are handled directly via GetFTGlyphExtents.
-  struct GlyphMetrics {
-    // Set the X coord to INT16_MIN to signal the bounds are invalid, or
-    // INT16_MAX to signal that the bounds would overflow an int16_t.
-    enum { INVALID = INT16_MIN, OVERFLOW = INT16_MAX };
-
-    GlyphMetrics() : mAdvance(0), mX(INVALID), mY(0), mWidth(0), mHeight(0) {}
-
-    bool HasValidBounds() const { return mX != INVALID; }
-    bool HasCachedBounds() const { return mX != OVERFLOW; }
-
-    // If the bounds can fit in an int16_t, set them. Otherwise, leave the
-    // bounds invalid to signal that GetFTGlyphExtents should be queried
-    // directly.
-    void SetBounds(const mozilla::gfx::IntRect& aBounds) {
-      if (aBounds.x > INT16_MIN && aBounds.x < INT16_MAX &&
-          aBounds.y > INT16_MIN && aBounds.y < INT16_MAX &&
-          aBounds.width <= UINT16_MAX && aBounds.height <= UINT16_MAX) {
-        mX = aBounds.x;
-        mY = aBounds.y;
-        mWidth = aBounds.width;
-        mHeight = aBounds.height;
-      } else {
-        mX = OVERFLOW;
-      }
-    }
-
-    mozilla::gfx::IntRect GetBounds() const {
-      return mozilla::gfx::IntRect(mX, mY, mWidth, mHeight);
-    }
-
-    int32_t mAdvance;
-    int16_t mX;
-    int16_t mY;
-    uint16_t mWidth;
-    uint16_t mHeight;
-  };
-
-  const GlyphMetrics& GetCachedGlyphMetrics(uint16_t aGID);
-
-  mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey, GlyphMetrics>>
-      mGlyphMetrics;
+  mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey, int32_t>> mGlyphWidths;
 };
 
 // Helper classes used for clearing out user font data when FT font
 // face is destroyed. Since multiple faces may use the same data, be
 // careful to assure that the data is only cleared out when all uses
 // expire. The font entry object contains a refptr to FTUserFontData and
 // each FT face created from that font entry contains a refptr to that
 // same FTUserFontData object.