Bug 1337616 - Stop adding a new font key for every glyph array. r=jmuizelaar
authorMason Chang <mchang@mozilla.com>
Tue, 14 Feb 2017 15:16:23 -0800
changeset 372998 935cd55673ed501555d1f0273c3909c37fe17507
parent 372997 669d6b1f3031116d74d1d53b8b67c802c698693d
child 372999 886a6144728780d4c8630d5e812eee1d5ae7bbda
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmuizelaar
bugs1337616
milestone54.0a1
Bug 1337616 - Stop adding a new font key for every glyph array. r=jmuizelaar
gfx/2d/ScaledFontMac.h
gfx/layers/wr/WebRenderBridgeParent.cpp
gfx/layers/wr/WebRenderTextLayer.cpp
--- a/gfx/2d/ScaledFontMac.h
+++ b/gfx/2d/ScaledFontMac.h
@@ -45,16 +45,17 @@ public:
   virtual ~ScaledFontMac();
 
   virtual FontType GetType() const { return FontType::MAC; }
 #ifdef USE_SKIA
   virtual SkTypeface* GetSkTypeface();
 #endif
   virtual already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
   virtual bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton);
+  virtual bool CanSerialize() override { return true; }
 
 #ifdef USE_CAIRO_SCALED_FONT
   cairo_font_face_t* GetCairoFontFace();
 #endif
 
 private:
   friend class DrawTargetSkia;
   CGFontRef mFont;
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -354,23 +354,23 @@ WebRenderBridgeParent::ProcessWebrenderC
           NS_ERROR("ReceiveCompositableUpdate failed");
         }
         break;
       }
       case WebRenderCommand::TOpDPPushText: {
         const OpDPPushText& op = cmd.get_OpDPPushText();
         const nsTArray<WrGlyphArray>& glyph_array = op.glyph_array();
 
+        // TODO: We are leaking the key
+        wr::FontKey fontKey;
+        auto slice = Range<uint8_t>(op.font_buffer().mData, op.font_buffer_length());
+        fontKey = mApi->AddRawFont(slice);
+
         for (size_t i = 0; i < glyph_array.Length(); i++) {
           const nsTArray<WrGlyphInstance>& glyphs = glyph_array[i].glyphs;
-
-          // TODO: We are leaking the key
-          wr::FontKey fontKey;
-          auto slice = Range<uint8_t>(op.font_buffer().mData, op.font_buffer_length());
-          fontKey = mApi->AddRawFont(slice);
           builder.PushText(op.bounds(),
                            op.clip(),
                            glyph_array[i].color,
                            fontKey,
                            Range<const WrGlyphInstance>(glyphs.Elements(), glyphs.Length()),
                            op.glyph_size());
         }
 
--- a/gfx/layers/wr/WebRenderTextLayer.cpp
+++ b/gfx/layers/wr/WebRenderTextLayer.cpp
@@ -11,19 +11,19 @@
 #include "mozilla/gfx/2D.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
 static void
-DWriteFontFileData(const uint8_t* aData, uint32_t aLength, uint32_t aIndex,
-                   float aGlyphSize, uint32_t aVariationCount,
-                   const ScaledFont::VariationSetting* aVariations, void* aBaton)
+WriteFontFileData(const uint8_t* aData, uint32_t aLength, uint32_t aIndex,
+                  float aGlyphSize, uint32_t aVariationCount,
+                  const ScaledFont::VariationSetting* aVariations, void* aBaton)
 {
     WebRenderTextLayer* layer = static_cast<WebRenderTextLayer*>(aBaton);
 
     uint8_t* fontData = (uint8_t*)malloc(aLength * sizeof(uint8_t));
     memcpy(fontData, aData, aLength * sizeof(uint8_t));
 
     layer->mFontData = fontData;
     layer->mFontDataLength = aLength;
@@ -41,18 +41,19 @@ WebRenderTextLayer::RenderLayer()
     gfx::Rect rect = RelativeToParent(GetTransform().TransformBounds(IntRectToRect(mBounds)));
     gfx::Rect clip;
     if (GetClipRect().isSome()) {
       clip = RelativeToParent(IntRectToRect(GetClipRect().ref().ToUnknownRect()));
     } else {
       clip = rect;
     }
 
-    MOZ_ASSERT(mFont->GetType() == FontType::DWRITE);
-    mFont->GetFontFileData(&DWriteFontFileData, this);
+    MOZ_ASSERT((mFont->GetType() == FontType::DWRITE) ||
+                (mFont->GetType() == FontType::MAC));
+    mFont->GetFontFileData(&WriteFontFileData, this);
     wr::ByteBuffer fontBuffer(mFontDataLength, mFontData);
 
     nsTArray<WrGlyphArray> wr_glyphs;
     wr_glyphs.SetLength(mGlyphs.Length());
 
     for (size_t i = 0; i < mGlyphs.Length(); i++) {
         GlyphArray glyph_array = mGlyphs[i];
         nsTArray<Glyph>& glyphs = glyph_array.glyphs();