freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2019-moazin 033dc30 27/47: Store the rendering port's s


From: Moazin Khatti
Subject: [freetype2] GSoC-2019-moazin 033dc30 27/47: Store the rendering port's state in library.
Date: Fri, 26 Jul 2019 10:02:07 -0400 (EDT)

branch: GSoC-2019-moazin
commit 033dc3000d1d4c755dd2cade17b1600259c9c798
Author: Moazin Khatti <address@hidden>
Commit: Moazin Khatti <address@hidden>

    Store the rendering port's state in library.
    
    Before this commit, the state of a rendering port was being
    held globally. Now, it'll be stored in library->svg_renderer_state.
---
 include/freetype/internal/ftobjs.h |  6 ++++++
 include/freetype/svgrenderer.h     | 18 +++++++++++++-----
 src/base/ftglyph.c                 |  7 +++++++
 src/svg/ftsvg.c                    | 24 +++++++++++++++---------
 4 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/include/freetype/internal/ftobjs.h 
b/include/freetype/internal/ftobjs.h
index 2f20509..d5786d2 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -890,6 +890,10 @@ FT_BEGIN_HEADER
    *     created.  @FT_Reference_Library increments this counter, and
    *     @FT_Done_Library only destroys a library if the counter is~1,
    *     otherwise it simply decrements it.
+   *
+   *   svg_renderer_state ::
+   *     A pointer to a state object that will have the state of the SVG
+   *     Renderer. This will be totally managed by the renderer.
    */
   typedef struct  FT_LibraryRec_
   {
@@ -917,6 +921,8 @@ FT_BEGIN_HEADER
 
     FT_Int             refcount;
 
+    void*              svg_renderer_state;
+
   } FT_LibraryRec;
 
 
diff --git a/include/freetype/svgrenderer.h b/include/freetype/svgrenderer.h
index c8aad1f..e6c9aa4 100644
--- a/include/freetype/svgrenderer.h
+++ b/include/freetype/svgrenderer.h
@@ -38,12 +38,18 @@ FT_BEGIN_HEADER
    * @description:
    *   A callback used to initiate the SVG Rendering port
    *
+   * @input:
+   *   library::
+   *     A instance of library. This is required to initialize the renderer's
+   *     state which will be held in the library.
+   *
+   *
    * @return:
    *   FreeType error code.  0 means success.
    */
 
   typedef FT_Error
-  (*SVG_Lib_Init)(  );
+  (*SVG_Lib_Init)( FT_Library  library );
 
 
   /**************************************************************************
@@ -55,12 +61,14 @@ FT_BEGIN_HEADER
    *   A callback used to free the SVG Rendering port. Calling this callback
    *   shall do all cleanups that the SVG Rendering port wants to do.
    *
-   * @return:
-   *   FreeType error code.  0 means success.
+   * @input:
+   *   library::
+   *     A instance of library. This is required to free the renderer's state
+   *     which will be held in the library.
    */
 
-  typedef FT_Error
-  (*SVG_Lib_Free)(  );
+  typedef void
+  (*SVG_Lib_Free)( FT_Library  library );
 
 
   /**************************************************************************
diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c
index ab3be17..ae6480b 100644
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -716,6 +716,7 @@
     const FT_Glyph_Class*     clazz;
 
     FT_Library                library;
+    FT_Memory                 memory = library->memory;
 
 
     /* check argument */
@@ -763,7 +764,13 @@
     /* prepare dummy slot for rendering */
     error = clazz->glyph_prepare( glyph, &dummy );
     if ( !error )
+    {
       error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
+      if ( clazz == &ft_svg_glyph_class )
+      {
+        FT_FREE( dummy.other );
+      }
+    }
 
 #if 1
     if ( !destroy && origin )
diff --git a/src/svg/ftsvg.c b/src/svg/ftsvg.c
index 0bda218..445cf65 100644
--- a/src/svg/ftsvg.c
+++ b/src/svg/ftsvg.c
@@ -37,13 +37,20 @@
   static FT_Error
   ft_svg_init( SVG_Renderer svg_module )
   {
-    FT_Error  error = FT_Err_Ok;
-
-
+    FT_Error    error = FT_Err_Ok;
     svg_module->loaded = FALSE;
     return error;
   }
 
+  static void
+  ft_svg_done( SVG_Renderer svg_module )
+  {
+    FT_Library  library = svg_module->root.root.library;
+    if ( svg_module->loaded = TRUE )
+      svg_module->hooks.svg_lib_free( library );
+    svg_module->loaded = FALSE;
+  }
+
   static FT_Error
   ft_svg_render( FT_Renderer       renderer,
                  FT_GlyphSlot      slot,
@@ -51,14 +58,13 @@
                  const FT_Vector*  origin )
   {
     SVG_Renderer  svg_renderer = (SVG_Renderer)renderer;
-
-
-    if( svg_renderer->loaded == FALSE )
+    FT_Library    library      = renderer->root.library;
+    FT_Error      error;
+    if ( svg_renderer->loaded == FALSE )
     {
+      error = svg_renderer->hooks.svg_lib_init( library );
       svg_renderer->loaded = TRUE;
-      svg_renderer->hooks.svg_lib_init();
     }
-
     return svg_renderer->hooks.svg_lib_render( slot );
   }
 
@@ -96,7 +102,7 @@
       0x20000L,
       (const void*)&svg_renderer_interface,   /* module specific interface */
       (FT_Module_Constructor)ft_svg_init,     /* module_init */
-      NULL,
+      (FT_Module_Destructor)ft_svg_done,      /* module_done */
       NULL,
       FT_GLYPH_FORMAT_SVG,
       (FT_Renderer_RenderFunc)ft_svg_render,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]