Bug 1355931 - move ScaledFont::VariationSetting into separate header for sharing with thebes. r=jrmuizel
authorLee Salzman <lsalzman@mozilla.com>
Fri, 14 Apr 2017 14:11:02 -0400
changeset 353283 9ff13e2532a468213e7203455693060d496de96b
parent 353282 176ab833ca364efd64968171d4e62341dfcf8858
child 353284 322fde2d53bf49266dbc293321e6b36a4c789c12
push id31661
push userarchaeopteryx@coole-files.de
push dateSat, 15 Apr 2017 18:00:16 +0000
treeherdermozilla-central@d65b53cf8fd9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1355931
milestone55.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 1355931 - move ScaledFont::VariationSetting into separate header for sharing with thebes. r=jrmuizel MozReview-Commit-ID: 4UThWTMCuz9
gfx/2d/2D.h
gfx/2d/FontVariation.h
gfx/2d/ScaledFontMac.cpp
gfx/2d/UnscaledFontMac.h
gfx/2d/moz.build
gfx/thebes/gfxFontVariations.h
gfx/thebes/gfxMacFont.cpp
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -7,16 +7,17 @@
 #define _MOZILLA_GFX_2D_H
 
 #include "Types.h"
 #include "Point.h"
 #include "Rect.h"
 #include "Matrix.h"
 #include "Quaternion.h"
 #include "UserData.h"
+#include "FontVariation.h"
 #include <vector>
 
 // GenericRefCountedBase allows us to hold on to refcounted objects of any type
 // (contrary to RefCounted<T> which requires knowing the type T) and, in particular,
 // without having a dependency on that type. This is used for DrawTargetSkia
 // to be able to hold on to a GLContext.
 #include "mozilla/GenericRefCounted.h"
 #include "mozilla/MemoryReporting.h"
@@ -765,21 +766,16 @@ public:
    * others.
    */
   virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, const Matrix *aTransformHint = nullptr) = 0;
 
   /* This gets the metrics of a set of glyphs for the current font face.
    */
   virtual void GetGlyphDesignMetrics(const uint16_t* aGlyphIndices, uint32_t aNumGlyphs, GlyphMetrics* aGlyphMetrics) = 0;
 
-  struct VariationSetting {
-    uint32_t mTag;
-    float    mValue;
-  };
-
   typedef void (*FontInstanceDataOutput)(const uint8_t* aData, uint32_t aLength, void* aBaton);
 
   virtual bool GetFontInstanceData(FontInstanceDataOutput, void *) { return false; }
 
   virtual bool CanSerialize() { return false; }
 
   void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
     mUserData.Add(key, userData, destroy);
new file mode 100644
--- /dev/null
+++ b/gfx/2d/FontVariation.h
@@ -0,0 +1,26 @@
+/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef MOZILLA_GFX_FONTVARIATION_H_
+#define MOZILLA_GFX_FONTVARIATION_H_
+
+namespace mozilla {
+namespace gfx {
+
+// An OpenType variation tag and value pair
+struct FontVariation
+{
+  uint32_t mTag;
+  float mValue;
+
+  bool operator==(const FontVariation& aOther) const {
+    return mTag == aOther.mTag && mValue == aOther.mValue;
+  }
+};
+
+} // namespace gfx
+} // namespace mozilla
+
+#endif /* MOZILLA_GFX_FONTVARIATION_H_ */
--- a/gfx/2d/ScaledFontMac.cpp
+++ b/gfx/2d/ScaledFontMac.cpp
@@ -233,17 +233,17 @@ struct writeBuf
     unsigned char *data;
     int offset;
 };
 
 static void CollectVariationSetting(const void *key, const void *value, void *context)
 {
   auto keyPtr = static_cast<const CFTypeRef>(key);
   auto valuePtr = static_cast<const CFTypeRef>(value);
-  auto vpp = static_cast<ScaledFont::VariationSetting**>(context);
+  auto vpp = static_cast<FontVariation**>(context);
   if (CFGetTypeID(keyPtr) == CFNumberGetTypeID() &&
       CFGetTypeID(valuePtr) == CFNumberGetTypeID()) {
     uint64_t t;
     double v;
     if (CFNumberGetValue(static_cast<CFNumberRef>(keyPtr), kCFNumberSInt64Type, &t) &&
         CFNumberGetValue(static_cast<CFNumberRef>(valuePtr), kCFNumberDoubleType, &v)) {
       (*vpp)->mTag = t;
       (*vpp)->mValue = v;
@@ -326,44 +326,44 @@ UnscaledFontMac::GetFontFileData(FontFil
     return true;
 }
 
 bool
 ScaledFontMac::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
 {
     // Collect any variation settings that were incorporated into the CTFont.
     uint32_t variationCount = 0;
-    VariationSetting* variations = nullptr;
+    FontVariation* variations = nullptr;
     // Avoid calling potentially buggy variation APIs on pre-Sierra macOS
     // versions (see bug 1331683)
     if (nsCocoaFeatures::OnSierraOrLater()) {
       if (mCTFont) {
         CFDictionaryRef dict = CTFontCopyVariation(mCTFont);
         if (dict) {
           CFIndex count = CFDictionaryGetCount(dict);
           if (count > 0) {
-            variations = new VariationSetting[count];
-            VariationSetting* vPtr = variations;
+            variations = new FontVariation[count];
+            FontVariation* vPtr = variations;
             CFDictionaryApplyFunction(dict, CollectVariationSetting, &vPtr);
             variationCount = vPtr - variations;
           }
           CFRelease(dict);
         }
       }
     }
 
-    aCb(reinterpret_cast<uint8_t*>(variations), variationCount * sizeof(VariationSetting), aBaton);
+    aCb(reinterpret_cast<uint8_t*>(variations), variationCount * sizeof(FontVariation), aBaton);
     delete[] variations;
 
     return true;
 }
 
 static CFDictionaryRef
 CreateVariationDictionaryOrNull(CGFontRef aCGFont, uint32_t aVariationCount,
-                                const ScaledFont::VariationSetting* aVariations)
+                                const FontVariation* aVariations)
 {
   // Avoid calling potentially buggy variation APIs on pre-Sierra macOS
   // versions (see bug 1331683)
   if (!nsCocoaFeatures::OnSierraOrLater()) {
     return nullptr;
   }
 
   AutoRelease<CTFontRef>
@@ -455,17 +455,17 @@ CreateVariationDictionaryOrNull(CGFontRe
   }
 
   return dict.forget();
 }
 
 CGFontRef
 UnscaledFontMac::CreateCGFontWithVariations(CGFontRef aFont,
                                             uint32_t aVariationCount,
-                                            const ScaledFont::VariationSetting* aVariations)
+                                            const FontVariation* aVariations)
 {
   MOZ_ASSERT(aVariationCount > 0);
   MOZ_ASSERT(aVariations);
 
   AutoRelease<CFDictionaryRef>
     varDict(CreateVariationDictionaryOrNull(aFont, aVariationCount, aVariations));
   if (!varDict) {
     return nullptr;
@@ -475,19 +475,19 @@ UnscaledFontMac::CreateCGFontWithVariati
 }
 
 already_AddRefed<ScaledFont>
 UnscaledFontMac::CreateScaledFont(Float aGlyphSize,
                                   const uint8_t* aInstanceData,
                                   uint32_t aInstanceDataLength)
 {
   uint32_t variationCount =
-    aInstanceDataLength / sizeof(ScaledFont::VariationSetting);
-  const ScaledFont::VariationSetting* variations =
-    reinterpret_cast<const ScaledFont::VariationSetting*>(aInstanceData);
+    aInstanceDataLength / sizeof(FontVariation);
+  const FontVariation* variations =
+    reinterpret_cast<const FontVariation*>(aInstanceData);
 
   CGFontRef fontRef = mFont;
   if (variationCount > 0) {
     CGFontRef varFont =
       CreateCGFontWithVariations(mFont, variationCount, variations);
     if (varFont) {
       fontRef = varFont;
     }
--- a/gfx/2d/UnscaledFontMac.h
+++ b/gfx/2d/UnscaledFontMac.h
@@ -41,17 +41,17 @@ public:
   already_AddRefed<ScaledFont>
     CreateScaledFont(Float aGlyphSize,
                      const uint8_t* aInstanceData,
                      uint32_t aInstanceDataLength) override;
 
   static CGFontRef
     CreateCGFontWithVariations(CGFontRef aFont,
                                uint32_t aVariationCount,
-                               const ScaledFont::VariationSetting* aVariations);
+                               const FontVariation* aVariations);
 
 private:
   CGFontRef mFont;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
--- a/gfx/2d/moz.build
+++ b/gfx/2d/moz.build
@@ -21,16 +21,17 @@ EXPORTS.mozilla.gfx += [
     'Blur.h',
     'BorrowedContext.h',
     'Coord.h',
     'CriticalSection.h',
     'DataSurfaceHelpers.h',
     'DrawEventRecorder.h',
     'DrawTargetTiled.h',
     'Filters.h',
+    'FontVariation.h',
     'Helpers.h',
     'HelpersCairo.h',
     'IterableArena.h',
     'JobScheduler.h',
     'JobScheduler_posix.h',
     'JobScheduler_win32.h',
     'Logging.h',
     'LoggingConstants.h',
--- a/gfx/thebes/gfxFontVariations.h
+++ b/gfx/thebes/gfxFontVariations.h
@@ -2,21 +2,13 @@
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_FONT_VARIATIONS_H
 #define GFX_FONT_VARIATIONS_H
 
-// An OpenType variation tag and value pair
-struct gfxFontVariation {
-    uint32_t mTag;
-    float mValue;
-};
+#include "mozilla/gfx/FontVariation.h"
 
-inline bool
-operator==(const gfxFontVariation& a, const gfxFontVariation& b)
-{
-    return (a.mTag == b.mTag) && (a.mValue == b.mValue);
-}
+typedef mozilla::gfx::FontVariation gfxFontVariation;
 
 #endif
--- a/gfx/thebes/gfxMacFont.cpp
+++ b/gfx/thebes/gfxMacFont.cpp
@@ -36,23 +36,21 @@ gfxMacFont::gfxMacFont(const RefPtr<Unsc
     mApplySyntheticBold = aNeedsBold;
 
     if (mVariationFont && aFontStyle->variationSettings.Length() > 0) {
         CGFontRef baseFont = aUnscaledFont->GetFont();
         if (!baseFont) {
             mIsValid = false;
             return;
         }
-        MOZ_ASSERT(sizeof(ScaledFont::VariationSetting) == sizeof(gfxFontVariation));
         mCGFont =
             UnscaledFontMac::CreateCGFontWithVariations(
                 baseFont,
                 aFontStyle->variationSettings.Length(),
-                reinterpret_cast<const ScaledFont::VariationSetting*>(
-                    aFontStyle->variationSettings.Elements()));
+                aFontStyle->variationSettings.Elements());
         if (!mCGFont) {
           ::CFRetain(baseFont);
           mCGFont = baseFont;
         }
     } else {
         mCGFont = aUnscaledFont->GetFont();
         if (!mCGFont) {
             mIsValid = false;