[libbluray-devel] BDFontMetrics: Release libfreetype2 resources on lib shutdown

tourettes git at videolan.org
Fri Jun 13 08:31:40 CEST 2014


libbluray | branch: master | tourettes <tourettes at team-mediaportal.com> | Wed Jun 11 22:07:12 2014 +0300| [9f660050ec4a60bd989aadcd63e70961dcb8ab9a] | committer: hpi1

BDFontMetrics: Release libfreetype2 resources on lib shutdown

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=9f660050ec4a60bd989aadcd63e70961dcb8ab9a
---

 src/libbluray/bdj/java/java/awt/BDFontMetrics.java |   41 +++++++++-----------
 src/libbluray/bdj/java/org/videolan/Libbluray.java |    1 +
 2 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/src/libbluray/bdj/java/java/awt/BDFontMetrics.java b/src/libbluray/bdj/java/java/awt/BDFontMetrics.java
index 54f6c48..d0b63a9 100644
--- a/src/libbluray/bdj/java/java/awt/BDFontMetrics.java
+++ b/src/libbluray/bdj/java/java/awt/BDFontMetrics.java
@@ -32,7 +32,7 @@ public class BDFontMetrics extends FontMetrics {
     private static native long initN();
     private static native void destroyN(long ftLib);
 
-    public static void init() {
+    public synchronized static void init() {
         //System.loadLibrary("bluray");
 
         if (ftLib != 0)
@@ -45,24 +45,6 @@ public class BDFontMetrics extends FontMetrics {
             throw new AWTError("freetype lib not loaded");
         }
 
-        Runtime.getRuntime().addShutdownHook(
-            new Thread() {
-                public void run() {
-                    Iterator it = fontMetricsMap.values().iterator();
-                    while (it.hasNext()) {
-                        try {
-                            BDFontMetrics fm = (BDFontMetrics)it.next();
-                            it.remove();
-                            fm.destroy();
-                        } catch (Throwable e) {
-                            e.printStackTrace();
-                        }
-                    }
-                    BDFontMetrics.destroyN(BDFontMetrics.ftLib);
-                }
-            }
-        );
-
         String javaHome = (String) AccessController.doPrivileged(new PrivilegedAction() {
                 public Object run() {
                     return System.getProperty("java.home");
@@ -99,6 +81,21 @@ public class BDFontMetrics extends FontMetrics {
         fontNameMap.put("default.3", dir + "LucidaSansDemiOblique.ttf");
     }
 
+    public synchronized static void shutdown() {
+        Iterator it = fontMetricsMap.values().iterator();
+        while (it.hasNext()) {
+            try {
+                BDFontMetrics fm = (BDFontMetrics)it.next();
+                it.remove();
+                fm.destroy();
+            } catch (Throwable e) {
+                e.printStackTrace();
+            }
+        }
+        destroyN(BDFontMetrics.ftLib);
+        ftLib = 0;
+    }
+
     /** A map which maps a native font name and size to a font metrics object. This is used
      as a cache to prevent loading the same fonts multiple times. */
     private static Map fontMetricsMap = new HashMap();
@@ -124,7 +121,7 @@ public class BDFontMetrics extends FontMetrics {
         return fm;
     }
 
-    static String[] getFontList() {
+    static synchronized String[] getFontList() {
         init();
 
         ArrayList fontNames = new ArrayList();
@@ -151,13 +148,13 @@ public class BDFontMetrics extends FontMetrics {
         }
     }
 
-    public static boolean registerFont(File f) {
+    public synchronized static boolean registerFont(File f) {
         //TODO
         org.videolan.Logger.unimplemented("BDFontMetrics", "registerFont");
         return false;
     }
 
-    public static void unregisterFont(String name, int style) {
+    public synchronized static void unregisterFont(String name, int style) {
         name = name.toLowerCase() + "." + style;
         fontNameMap.remove(name);
     }
diff --git a/src/libbluray/bdj/java/org/videolan/Libbluray.java b/src/libbluray/bdj/java/org/videolan/Libbluray.java
index 0a15577..183d5d5 100644
--- a/src/libbluray/bdj/java/org/videolan/Libbluray.java
+++ b/src/libbluray/bdj/java/org/videolan/Libbluray.java
@@ -136,6 +136,7 @@ public class Libbluray {
             MountManager.unmountAll();
             GUIManager.shutdown();
             BDToolkit.shutdownDisc();
+            java.awt.BDFontMetrics.shutdown();
             SIManagerImpl.shutdown();
             IxcRegistry.shutdown();
             EventManager.shutdown();



More information about the libbluray-devel mailing list