[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

mrobinson at webkit.org mrobinson at webkit.org
Wed Dec 22 13:39:01 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 9ab62887cfab9a79e5faa79d17ff337c20a49a79
Author: mrobinson at webkit.org <mrobinson at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Sep 22 15:01:22 2010 +0000

    2010-09-22  Martin Robinson  <mrobinson at igalia.com>
    
            Reviewed by Xan Lopez.
    
            [GTK] FontCustomPlatformData.cpp leaks FT_Faces
            https://bugs.webkit.org/show_bug.cgi?id=16941
    
            Attach lifetime of the FontCustomPlatformData FT_Face to the resulting cairo_font_face_t.
            This will free the memory associated with the FT_Face once the cairo_font_face_t is
            destroyed.
    
            No new tests as functionality should not change.
    
            * platform/graphics/cairo/FontCustomPlatformData.cpp:
            (WebCore::releaseCustomFontData): Moved this helper method to the top of the file
            and gave it a more descriptive name.
            (WebCore::FontCustomPlatformData::FontCustomPlatformData): Changed the constructor to
            take the FT_Face and the buffer, so to better encapsulate the creation of the cairo
            face.
            (WebCore::FontCustomPlatformData::~FontCustomPlatformData): Added a comment about the
            fate of the FT_Face to the destructor.
            (WebCore::createFontCustomPlatformData): Cleaned up the code here and moved some of the
            logic into the constructor.
            * platform/graphics/cairo/FontCustomPlatformData.h: Updated method definitions.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68041 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 8e8c2da..9884a0d 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,28 @@
+2010-09-22  Martin Robinson  <mrobinson at igalia.com>
+
+        Reviewed by Xan Lopez.
+
+        [GTK] FontCustomPlatformData.cpp leaks FT_Faces
+        https://bugs.webkit.org/show_bug.cgi?id=16941
+
+        Attach lifetime of the FontCustomPlatformData FT_Face to the resulting cairo_font_face_t.
+        This will free the memory associated with the FT_Face once the cairo_font_face_t is 
+        destroyed.
+
+        No new tests as functionality should not change.
+
+        * platform/graphics/cairo/FontCustomPlatformData.cpp:
+        (WebCore::releaseCustomFontData): Moved this helper method to the top of the file
+        and gave it a more descriptive name.
+        (WebCore::FontCustomPlatformData::FontCustomPlatformData): Changed the constructor to
+        take the FT_Face and the buffer, so to better encapsulate the creation of the cairo
+        face.
+        (WebCore::FontCustomPlatformData::~FontCustomPlatformData): Added a comment about the
+        fate of the FT_Face to the destructor.
+        (WebCore::createFontCustomPlatformData): Cleaned up the code here and moved some of the
+        logic into the constructor.
+        * platform/graphics/cairo/FontCustomPlatformData.h: Updated method definitions.
+
 2010-09-22  Balazs Kelemen  <kb at inf.u-szeged.hu>
 
         Reviewed by Kenneth Rohde Christiansen.
diff --git a/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp b/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp
index 6b76c2a..7787f63 100644
--- a/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp
+++ b/WebCore/platform/graphics/cairo/FontCustomPlatformData.cpp
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008 Alp Toker <alp at atoker.com>
+ * Copyright (C) 2010 Igalia S.L.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -26,8 +27,32 @@
 
 namespace WebCore {
 
+static void releaseCustomFontData(void* data)
+{
+    static_cast<SharedBuffer*>(data)->deref();
+}
+
+FontCustomPlatformData::FontCustomPlatformData(FT_Face freeTypeFace, SharedBuffer* buffer)
+    : m_freeTypeFace(freeTypeFace)
+    , m_fontFace(cairo_ft_font_face_create_for_ft_face(freeTypeFace, 0))
+{
+    // FIXME Should we be setting some hinting options here?
+
+    buffer->ref(); // This is balanced by the buffer->deref() in releaseCustomFontData.
+    static cairo_user_data_key_t bufferKey;
+    cairo_font_face_set_user_data(m_fontFace, &bufferKey, buffer,
+         static_cast<cairo_destroy_func_t>(releaseCustomFontData));
+
+    // Cairo doesn't do FreeType reference counting, so we need to ensure that when
+    // this cairo_font_face_t is destroyed, it cleans up the FreeType face as well.
+    static cairo_user_data_key_t freeTypeFaceKey;
+    cairo_font_face_set_user_data(m_fontFace, &freeTypeFaceKey, freeTypeFace,
+         reinterpret_cast<cairo_destroy_func_t>(FT_Done_Face));
+}
+
 FontCustomPlatformData::~FontCustomPlatformData()
 {
+    // m_freeTypeFace will be destroyed along with m_fontFace. See the constructor.
     cairo_font_face_destroy(m_fontFace);
 }
 
@@ -36,38 +61,20 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, b
     return FontPlatformData(m_fontFace, size, bold, italic);
 }
 
-static void releaseData(void* data)
-{
-    static_cast<SharedBuffer*>(data)->deref();
-}
-
 FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
 {
     ASSERT_ARG(buffer, buffer);
 
-    int error;
-
     static FT_Library library = 0;
-    if (!library) {
-        error = FT_Init_FreeType(&library);
-        if (error) {
-            library = 0;
-            return 0;
-        }
+    if (!library && FT_Init_FreeType(&library)) {
+        library = 0;
+        return 0;
     }
 
-    FT_Face face;
-    error = FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer->data()), buffer->size(), 0, &face);
-    if (error)
+    FT_Face freeTypeFace;
+    if (FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer->data()), buffer->size(), 0, &freeTypeFace))
         return 0;
-
-    buffer->ref();
-    cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_ft_face(face, 0);
-
-    static cairo_user_data_key_t bufferKey;
-    cairo_font_face_set_user_data(fontFace, &bufferKey, buffer, releaseData);
-
-    return new FontCustomPlatformData(fontFace);
+    return new FontCustomPlatformData(freeTypeFace, buffer);
 }
 
 bool FontCustomPlatformData::supportsFormat(const String& format)
diff --git a/WebCore/platform/graphics/cairo/FontCustomPlatformData.h b/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
index a72a6a4..c48d110 100644
--- a/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
+++ b/WebCore/platform/graphics/cairo/FontCustomPlatformData.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008 Alp Toker <alp at atoker.com>
+ * Copyright (C) 2010 Igalia S.L.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -25,6 +26,7 @@
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 
+typedef struct FT_FaceRec_*  FT_Face;
 typedef struct _cairo_font_face cairo_font_face_t;
 
 namespace WebCore {
@@ -33,16 +35,14 @@ class FontPlatformData;
 class SharedBuffer;
 
 struct FontCustomPlatformData : Noncopyable {
-    FontCustomPlatformData(cairo_font_face_t* fontFace)
-    : m_fontFace(fontFace)
-    {}
-
+public:
+    FontCustomPlatformData(FT_Face, SharedBuffer*);
     ~FontCustomPlatformData();
-
     FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontRenderingMode = NormalRenderingMode);
-
     static bool supportsFormat(const String&);
 
+private:
+    FT_Face m_freeTypeFace;
     cairo_font_face_t* m_fontFace;
 };
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list