Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/awt/gtk_interface.c
32287 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24#include <dlfcn.h>25#include <stdlib.h>26#include "jvm_md.h"27#include "gtk_interface.h"2829GtkApi* gtk2_load(JNIEnv *env, const char* lib_name);30GtkApi* gtk3_load(JNIEnv *env, const char* lib_name);3132gboolean gtk2_check(const char* lib_name, gboolean load);33gboolean gtk3_check(const char* lib_name, gboolean load);3435GtkApi *gtk;3637typedef struct {38GtkVersion version;39const char* name;40const char* vname;41GtkApi* (*load)(JNIEnv *env, const char* lib_name);42gboolean (*check)(const char* lib_name, gboolean load);43} GtkLib;4445static GtkLib gtk_libs[] = {46{47GTK_3,48JNI_LIB_NAME("gtk-3"),49VERSIONED_JNI_LIB_NAME("gtk-3", "0"),50>k3_load,51>k3_check52},53{54GTK_2,55JNI_LIB_NAME("gtk-x11-2.0"),56VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0"),57>k2_load,58>k2_check59}60};6162static GtkLib** get_libs_order(GtkVersion version) {63static GtkLib** load_order;64static int n_libs = 0;65if (!n_libs) {66n_libs = sizeof(gtk_libs) / sizeof(GtkLib);67load_order = calloc(n_libs + 1, sizeof(GtkLib *));68}69int i, first = 0;70for (i = 0; i < n_libs; i++) {71load_order[i] = >k_libs[i];72if (load_order[i]->version == version) {73first = i;74}75}76if (first) {77for (i = first; i > 0; i--) {78load_order[i] = load_order[i - 1];79}80load_order[0] = >k_libs[first];81}82return load_order;83}8485static GtkLib* get_loaded() {86GtkLib** libs = get_libs_order(GTK_ANY);87while(!gtk && *libs) {88GtkLib* lib = *libs++;89if (lib->check(lib->vname, /* load = */FALSE)) {90return lib;91}92if (lib->check(lib->name, /* load = */FALSE)) {93return lib;94}95}96return NULL;97}9899gboolean gtk_load(JNIEnv *env, GtkVersion version, gboolean verbose) {100if (gtk == NULL) {101GtkLib* lib = get_loaded();102if (lib) {103if (verbose) {104fprintf(stderr, "Looking for GTK%d library...\n",105lib->version);106}107gtk = lib->load(env, lib->vname);108if (!gtk) {109gtk = lib->load(env, lib->name);110}111} else {112GtkLib** libs = get_libs_order(version);113while (!gtk && *libs) {114lib = *libs++;115if (version == GTK_ANY || lib->version == version) {116if (verbose) {117fprintf(stderr, "Looking for GTK%d library...\n",118lib->version);119}120gtk = lib->load(env, lib->vname);121if (!gtk) {122gtk = lib->load(env, lib->name);123}124if (verbose && !gtk) {125fprintf(stderr, "Not found.\n");126}127}128}129}130if (verbose) {131if (gtk) {132fprintf(stderr, "GTK%d library loaded.\n", lib->version);133} else {134fprintf(stderr, "Failed to load GTK library.\n");135}136}137}138return gtk != NULL;139}140141static gboolean check_version(GtkVersion version) {142GtkLib** libs = get_libs_order(version);143while (*libs) {144GtkLib* lib = *libs++;145if (lib->check(lib->vname, /* load = */TRUE)) {146return TRUE;147}148if (lib->check(lib->name, /* load = */TRUE)) {149return TRUE;150}151}152return FALSE;153}154155gboolean gtk_check_version(GtkVersion version) {156if (gtk || get_loaded()) {157return TRUE;158}159return check_version(version);160}161162163