Title: [226635] trunk/Source/WebCore
Revision
226635
Author
[email protected]
Date
2018-01-09 08:23:54 -0800 (Tue, 09 Jan 2018)

Log Message

[FreeType] Use FastMalloc for FreeType
https://bugs.webkit.org/show_bug.cgi?id=181387

Reviewed by Michael Catanzaro.

Add custom memory allocator for FreeType to use FastMalloc.

* platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp:
(WebCore::initializeFreeTypeLibrary):
(WebCore::createFontCustomPlatformData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (226634 => 226635)


--- trunk/Source/WebCore/ChangeLog	2018-01-09 16:15:23 UTC (rev 226634)
+++ trunk/Source/WebCore/ChangeLog	2018-01-09 16:23:54 UTC (rev 226635)
@@ -1,3 +1,16 @@
+2018-01-09  Yusuke Suzuki  <[email protected]>
+
+        [FreeType] Use FastMalloc for FreeType
+        https://bugs.webkit.org/show_bug.cgi?id=181387
+
+        Reviewed by Michael Catanzaro.
+
+        Add custom memory allocator for FreeType to use FastMalloc.
+
+        * platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp:
+        (WebCore::initializeFreeTypeLibrary):
+        (WebCore::createFontCustomPlatformData):
+
 2018-01-09  Zalan Bujtas  <[email protected]>
 
         [RenderTreeBuilder] Move RenderTable* addChild mutation logic to RenderTreeBuilder

Modified: trunk/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp (226634 => 226635)


--- trunk/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp	2018-01-09 16:15:23 UTC (rev 226634)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontCustomPlatformDataFreeType.cpp	2018-01-09 16:23:54 UTC (rev 226635)
@@ -26,6 +26,8 @@
 #include "SharedBuffer.h"
 #include <cairo-ft.h>
 #include <cairo.h>
+#include <ft2build.h>
+#include FT_MODULE_H
 
 namespace WebCore {
 
@@ -59,10 +61,39 @@
     return FontPlatformData(m_fontFace, description, bold, italic);
 }
 
+static bool initializeFreeTypeLibrary(FT_Library& library)
+{
+    // https://www.freetype.org/freetype2/docs/design/design-4.html
+    // https://lists.nongnu.org/archive/html/freetype-devel/2004-10/msg00022.html
+
+    FT_Memory memory = bitwise_cast<FT_Memory>(ft_smalloc(sizeof(*memory)));
+    if (!memory)
+        return false;
+
+    memory->user = nullptr;
+    memory->alloc = [](FT_Memory, long size) -> void* {
+        return fastMalloc(size);
+    };
+    memory->free = [](FT_Memory, void* block) -> void {
+        fastFree(block);
+    };
+    memory->realloc = [](FT_Memory, long, long newSize, void* block) -> void* {
+        return fastRealloc(block, newSize);
+    };
+
+    if (FT_New_Library(memory, &library)) {
+        ft_sfree(memory);
+        return false;
+    }
+
+    FT_Add_Default_Modules(library);
+    return true;
+}
+
 std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer& buffer)
 {
     static FT_Library library;
-    if (!library && FT_Init_FreeType(&library)) {
+    if (!library && !initializeFreeTypeLibrary(library)) {
         library = nullptr;
         return nullptr;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to