changeset 9830:5cd7cefce8aa jdk-9+122

8157600: Failed to launch hello.HelloSanity due to undefined symbol Reviewed-by: kcr, ddhill
author flar
date Fri, 03 Jun 2016 16:45:14 -0700
parents a1e73dd4613e
children a981d0f1a556 0c2957f718e7
files modules/graphics/src/main/native-glass/gtk/glass_screen.cpp modules/graphics/src/main/native-glass/gtk/glass_wrapper.h modules/graphics/src/main/native-glass/gtk/wrapper_gdk.c modules/graphics/src/main/native-glass/gtk/wrapper_gio.c modules/graphics/src/main/native-glass/gtk/wrapper_main.c
diffstat 5 files changed, 236 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/gtk/glass_screen.cpp	Fri Jun 03 15:15:53 2016 +0300
+++ b/modules/graphics/src/main/native-glass/gtk/glass_screen.cpp	Fri Jun 03 16:45:14 2016 -0700
@@ -27,11 +27,11 @@
 
 #include "glass_screen.h"
 #include "glass_general.h"
+#include "glass_wrapper.h"
 
 #include <X11/Xatom.h>
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
-#include <gio/gio.h>
 
 jfloat OverrideUIScale = -1.0f;
 
@@ -104,39 +104,6 @@
 
 }
 
-#undef DEBUG_GSETTINGS
-
-static guint gsettings_get_guint(const gchar *schema_name,
-                                 const gchar *key_name,
-                                 int defval)
-{
-    GSettingsSchemaSource *default_schema_source =
-            g_settings_schema_source_get_default();
-    if (default_schema_source == NULL) {
-#ifdef DEBUG_GSETTINGS
-        fprintf(stderr, "No schema source dir found!\n");
-#endif
-        return defval;
-    }
-    GSettingsSchema *the_schema =
-            g_settings_schema_source_lookup(default_schema_source, schema_name, TRUE);
-    if (the_schema == NULL) {
-#ifdef DEBUG_GSETTINGS
-        fprintf(stderr, "schema '%s' not found!\n", schema_name);
-#endif
-        return defval;
-    }
-#ifdef DEBUG_GSETTINGS
-    fprintf(stderr, "found schema '%s'\n", schema_name);
-#endif
-    GSettings *gset = g_settings_new(schema_name);
-    guint val = g_settings_get_uint(gset, key_name);
-#ifdef DEBUG_GSETTINGS
-    fprintf(stderr, "...and key '%s'\n", key_name);
-#endif
-    return val;
-}
-
 static jobject createJavaScreen(JNIEnv* env, GdkScreen* screen, gint monitor_idx)
 {
     GdkRectangle workArea = get_screen_workarea(screen);
@@ -163,8 +130,8 @@
         if (gdk_scale > 0) {
             uiScale = (jfloat) gdk_scale;
         } else {
-            uiScale = (jfloat) gsettings_get_guint("org.gnome.desktop.interface",
-                                                   "scaling-factor", 0);
+            uiScale = (jfloat) glass_settings_get_guint_opt("org.gnome.desktop.interface",
+                                                            "scaling-factor", 0);
             if (uiScale < 1) {
                 uiScale = 1;
             }
--- a/modules/graphics/src/main/native-glass/gtk/glass_wrapper.h	Fri Jun 03 15:15:53 2016 +0300
+++ b/modules/graphics/src/main/native-glass/gtk/glass_wrapper.h	Fri Jun 03 16:45:14 2016 -0700
@@ -40,6 +40,7 @@
 extern int wrapper_load_symbols_gtk(int version, void *handle);
 extern int wrapper_load_symbols_gdk(int version, void *handle);
 extern int wrapper_load_symbols_pix(int version, void * handle);
+extern int wrapper_load_symbols_gio(void * handle);
 
 extern int wrapper_debug;
 extern int wrapper_loaded;
@@ -136,6 +137,11 @@
 GdkWindow *
 glass_gdk_drag_context_get_dest_window (GdkDragContext * context);
 
+guint
+glass_settings_get_guint_opt (const gchar *schema_name,
+                    const gchar *key_name,
+                    int defval);
+
 #ifdef __cplusplus
 }
 #endif
--- a/modules/graphics/src/main/native-glass/gtk/wrapper_gdk.c	Fri Jun 03 15:15:53 2016 +0300
+++ b/modules/graphics/src/main/native-glass/gtk/wrapper_gdk.c	Fri Jun 03 16:45:14 2016 -0700
@@ -186,6 +186,12 @@
                          gint monitor_num,
                          GdkRectangle * dest);
 static gint (*_gdk_screen_get_n_monitors) (GdkScreen * screen);
+static gint (*_gdk_screen_get_monitor_width_mm) (GdkScreen *screen,
+                         gint monitor_num);
+static gint (*_gdk_screen_get_monitor_height_mm) (GdkScreen *screen,
+                         gint monitor_num);
+static gint (*_gdk_screen_get_width_mm) (GdkScreen *screen);
+static gint (*_gdk_screen_get_height_mm) (GdkScreen *screen);
 static gdouble (*_gdk_screen_get_resolution) (GdkScreen * screen);
 static GdkColormap *(*_gdk_screen_get_rgba_colormap) (GdkScreen * screen);
 static GdkColormap *(*_gdk_screen_get_rgb_colormap) (GdkScreen * screen);
@@ -403,6 +409,10 @@
     PRELOAD_SYMBOL_GDK (gdk_screen_get_monitor_at_point);
     PRELOAD_SYMBOL_GDK (gdk_screen_get_monitor_geometry);
     PRELOAD_SYMBOL_GDK (gdk_screen_get_n_monitors);
+    PRELOAD_SYMBOL_GDK (gdk_screen_get_monitor_width_mm);
+    PRELOAD_SYMBOL_GDK (gdk_screen_get_monitor_height_mm);
+    PRELOAD_SYMBOL_GDK (gdk_screen_get_width_mm);
+    PRELOAD_SYMBOL_GDK (gdk_screen_get_height_mm);
     PRELOAD_SYMBOL_GDK (gdk_screen_get_resolution);
     PRELOAD_SYMBOL_GDK (gdk_screen_get_root_window);
     PRELOAD_SYMBOL_GDK (gdk_screen_get_system_visual);
@@ -898,6 +908,30 @@
     return (*_gdk_screen_get_n_monitors) (screen);
 }
 
+gint gdk_screen_get_width_mm (GdkScreen * screen)
+{
+    CHECK_LOAD_SYMBOL_GDK (gdk_screen_get_width_mm);
+    return (*_gdk_screen_get_width_mm) (screen);
+}
+
+gint gdk_screen_get_height_mm (GdkScreen * screen)
+{
+    CHECK_LOAD_SYMBOL_GDK (gdk_screen_get_height_mm);
+    return (*_gdk_screen_get_height_mm) (screen);
+}
+
+gint gdk_screen_get_monitor_width_mm (GdkScreen * screen, gint monitor_num)
+{
+    CHECK_LOAD_SYMBOL_GDK (gdk_screen_get_monitor_width_mm);
+    return (*_gdk_screen_get_monitor_width_mm) (screen, monitor_num);
+}
+
+gint gdk_screen_get_monitor_height_mm (GdkScreen * screen, gint monitor_num)
+{
+    CHECK_LOAD_SYMBOL_GDK (gdk_screen_get_monitor_height_mm);
+    return (*_gdk_screen_get_monitor_height_mm) (screen, monitor_num);
+}
+
 gdouble gdk_screen_get_resolution (GdkScreen * screen)
 {
     CHECK_LOAD_SYMBOL_GDK (gdk_screen_get_resolution);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/gtk/wrapper_gio.c	Fri Jun 03 16:45:14 2016 -0700
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/fb.h>
+#include <fcntl.h>
+#ifndef __USE_GNU       // required for dladdr() & Dl_info
+#define __USE_GNU
+#endif
+#include <dlfcn.h>
+#include <sys/ioctl.h>
+
+#include <string.h>
+#include <strings.h>
+
+#include <assert.h>
+
+#include <gio/gio.h>
+
+#include "glass_wrapper.h"
+
+static GSettingsSchemaSource *(*_g_settings_schema_source_get_default) ();
+static GSettingsSchema *(*_g_settings_schema_source_lookup) (
+                        GSettingsSchemaSource *source,
+                        const gchar *schema_id,
+                        gboolean recursive);
+static gboolean (*_g_settings_schema_has_key) (
+                        GSettingsSchema *schema,
+                        const gchar *name);
+static GSettings *(*_g_settings_new) (const gchar *schema_id);
+static guint (*_g_settings_get_uint) (GSettings *settings,
+                        const gchar *key);
+
+/***************************************************************************/
+
+#define PRELOAD_SYMBOL_GIO_OPT(x) \
+    _##x = dlsym(libgio, #x); \
+    if (!_##x && wrapper_debug) { \
+        symbol_load_missing++; \
+        fprintf(stderr, "did not find %s\n", #x); \
+    } else if (wrapper_debug) { \
+        fprintf(stderr, "found %s = 0x%08lx\n", #x, (long)_##x); \
+    }
+
+int wrapper_load_symbols_gio (void *libgio)
+{
+    int symbol_load_missing = 0;
+    int symbol_load_errors = 0;
+
+    PRELOAD_SYMBOL_GIO_OPT (g_settings_schema_source_get_default);
+    PRELOAD_SYMBOL_GIO_OPT (g_settings_schema_source_lookup);
+    PRELOAD_SYMBOL_GIO_OPT (g_settings_schema_has_key);
+    PRELOAD_SYMBOL_GIO_OPT (g_settings_new);
+    PRELOAD_SYMBOL_GIO_OPT (g_settings_get_uint);
+
+    if (symbol_load_errors && wrapper_debug)
+    {
+      fprintf (stderr, "failed to load %d required gio symbols\n",
+           symbol_load_errors);
+    }
+    if (symbol_load_missing && wrapper_debug)
+    {
+      fprintf (stderr, "missing %d optional gio symbols\n",
+           symbol_load_missing);
+    }
+
+    return symbol_load_errors;
+}
+
+#define CHECK_LOAD_SYMBOL_GIO(x) \
+    { \
+        if (!_##x) { \
+            if (wrapper_debug) fprintf(stderr, "missing %s\n", #x); \
+            assert(_##x); \
+        } else { \
+            if (wrapper_debug) { \
+               fprintf(stderr, "using %s\n", #x); \
+               fflush(stderr); \
+            } \
+        } \
+    }
+
+#define CHECK_LOAD_SYMBOL_GIO_OPT(x, retval) \
+    { \
+        if (!_##x) { \
+            if (wrapper_debug) fprintf(stderr, "missing %s\n", #x); \
+            return retval; \
+        } else { \
+            if (wrapper_debug) { \
+               fprintf(stderr, "using %s\n", #x); \
+               fflush(stderr); \
+            } \
+        } \
+    }
+
+GSettingsSchemaSource *g_settings_schema_source_get_default ()
+{
+    CHECK_LOAD_SYMBOL_GIO_OPT(g_settings_schema_source_get_default, NULL)
+    return (*_g_settings_schema_source_get_default) ();
+}
+
+GSettingsSchema *g_settings_schema_source_lookup (
+                    GSettingsSchemaSource *source,
+                    const gchar *schema_id,
+                    gboolean recursive)
+{
+    CHECK_LOAD_SYMBOL_GIO_OPT(g_settings_schema_source_lookup, NULL)
+    if (source == NULL) {
+        return NULL;
+    }
+    return (*_g_settings_schema_source_lookup) (source, schema_id, recursive);
+}
+
+gboolean g_settings_schema_has_key (GSettingsSchema *schema,
+                    const gchar *name)
+{
+    CHECK_LOAD_SYMBOL_GIO_OPT(g_settings_schema_has_key, FALSE)
+    return (*_g_settings_schema_has_key) (schema, name);
+}
+
+GSettings *g_settings_new (const gchar *schema_id)
+{
+    CHECK_LOAD_SYMBOL_GIO (g_settings_new)
+    return (*_g_settings_new) (schema_id);
+}
+
+guint g_settings_get_uint (GSettings *settings,
+                        const gchar *key)
+{
+    CHECK_LOAD_SYMBOL_GIO (g_settings_get_uint)
+    return (*_g_settings_get_uint) (settings, key);
+}
+
+//--------------------------------------------------------------------------------------
+
+guint glass_settings_get_guint_opt (const gchar *schema_name,
+                    const gchar *key_name,
+                    int defval)
+{
+    GSettingsSchemaSource *default_schema_source =
+            g_settings_schema_source_get_default();
+    if (default_schema_source == NULL) {
+        if (wrapper_debug) {
+            fprintf(stderr, "No schema source dir found!\n");
+        }
+        return defval;
+    }
+    GSettingsSchema *the_schema =
+            g_settings_schema_source_lookup(default_schema_source, schema_name, TRUE);
+    if (the_schema == NULL) {
+        if (wrapper_debug) {
+            fprintf(stderr, "schema '%s' not found!\n", schema_name);
+        }
+        return defval;
+    }
+    if (!g_settings_schema_has_key(the_schema, key_name)) {
+        if (wrapper_debug) {
+            fprintf(stderr, "key '%s' not found in schema '%s'!\n", key_name, schema_name);
+        }
+        return defval;
+    }
+    if (wrapper_debug) {
+        fprintf(stderr, "found schema '%s' and key '%s'\n", schema_name, key_name);
+    }
+    GSettings *gset = g_settings_new(schema_name);
+    return g_settings_get_uint(gset, key_name);
+}
--- a/modules/graphics/src/main/native-glass/gtk/wrapper_main.c	Fri Jun 03 15:15:53 2016 +0300
+++ b/modules/graphics/src/main/native-glass/gtk/wrapper_main.c	Fri Jun 03 16:45:14 2016 -0700
@@ -189,6 +189,9 @@
         return -1;
     }
 
+    void *libgio = dlopen ("libgio-2.0.so", RTLD_LAZY | RTLD_GLOBAL);
+    wrapper_load_symbols_gio(libgio);
+
     wrapper_loaded = 1;
 
     return wrapper_gtk_version;