Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/awt/awt_Mlib.c
32287 views
/*1* Copyright (c) 1998, 2013, 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*/2425#include <stdlib.h>26#include <string.h>27#include <sys/time.h>28#include <sys/utsname.h>29#include <sys/types.h>30#include <errno.h>31#include <dlfcn.h>32#include "jni.h"33#include <jni_util.h>34#include "jvm_md.h"35#include "awt_Mlib.h"36#include "java_awt_image_BufferedImage.h"3738static void start_timer(int numsec);39static void stop_timer(int numsec, int ntimes);4041/*42* This is called by awt_ImagingLib.initLib() to figure out if we43* can use the VIS version of medialib44*/45mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,46mlibSysFnS_t *sMlibSysFns) {47int status;48jstring jstr = NULL;49mlibFnS_t *mptr;50void *(*vPtr)();51int (*intPtr)();52mlib_status (*fPtr)();53int i;54void *handle = NULL;55mlibSysFnS_t tempSysFns;56static int s_timeIt = 0;57static int s_verbose = 1;58mlib_status ret = MLIB_SUCCESS;59struct utsname name;6061/*62* Find out the machine name. If it is an SUN ultra, we63* can use the vis library64*/65if ((uname(&name) >= 0) && (getenv("NO_VIS") == NULL) &&66(strncmp(name.machine, "sun4u" , 5) == 0) ||67((strncmp(name.machine, "sun4v" , 5) == 0) &&68(getenv("USE_VIS_ON_SUN4V") != NULL)))69{70handle = dlopen(JNI_LIB_NAME("mlib_image_v"), RTLD_LAZY);71}7273if (handle == NULL) {74handle = dlopen(JNI_LIB_NAME("mlib_image"), RTLD_LAZY);75}7677if (handle == NULL) {78if (s_timeIt || s_verbose) {79printf ("error in dlopen: %s", dlerror());80}81return MLIB_FAILURE;82}8384/* So, if we are here, then either vis or generic version of85* medialib library was sucessfuly loaded.86* Let's try to initialize handlers...87*/88if ((tempSysFns.createFP = (MlibCreateFP_t)dlsym(handle,89"j2d_mlib_ImageCreate")) == NULL) {90if (s_timeIt) {91printf ("error in dlsym: %s", dlerror());92}93ret = MLIB_FAILURE;94}9596if (ret == MLIB_SUCCESS) {97if ((tempSysFns.createStructFP = (MlibCreateStructFP_t)dlsym(handle,98"j2d_mlib_ImageCreateStruct")) == NULL) {99if (s_timeIt) {100printf ("error in dlsym: %s", dlerror());101}102ret = MLIB_FAILURE;103}104}105106if (ret == MLIB_SUCCESS) {107if ((tempSysFns.deleteImageFP = (MlibDeleteFP_t)dlsym(handle,108"j2d_mlib_ImageDelete")) == NULL) {109if (s_timeIt) {110printf ("error in dlsym: %s", dlerror());111}112ret = MLIB_FAILURE;113}114}115116/* Set the system functions */117if (ret == MLIB_SUCCESS) {118*sMlibSysFns = tempSysFns;119}120121/* Loop through all of the fns and load them from the next library */122mptr = sMlibFns;123i = 0;124while ((ret == MLIB_SUCCESS) && (mptr[i].fname != NULL)) {125fPtr = (mlib_status (*)())dlsym(handle, mptr[i].fname);126if (fPtr != NULL) {127mptr[i].fptr = fPtr;128} else {129ret = MLIB_FAILURE;130}131i++;132}133if (ret != MLIB_SUCCESS) {134dlclose(handle);135}136return ret;137}138139mlib_start_timer awt_setMlibStartTimer() {140return start_timer;141}142143mlib_stop_timer awt_setMlibStopTimer() {144return stop_timer;145}146147/***************************************************************************148* Static Functions *149***************************************************************************/150151static void start_timer(int numsec)152{153struct itimerval interval;154155interval.it_interval.tv_sec = numsec;156interval.it_interval.tv_usec = 0;157interval.it_value.tv_sec = numsec;158interval.it_value.tv_usec = 0;159setitimer(ITIMER_REAL, &interval, 0);160}161162163static void stop_timer(int numsec, int ntimes)164{165struct itimerval interval;166double sec;167168getitimer(ITIMER_REAL, &interval);169sec = (((double) (numsec - 1)) - (double) interval.it_value.tv_sec) +170(1000000.0 - interval.it_value.tv_usec)/1000000.0;171sec = sec/((double) ntimes);172printf("%f msec per update\n", sec * 1000.0);173interval.it_interval.tv_sec = 0;174interval.it_interval.tv_usec = 0;175interval.it_value.tv_sec = 0;176interval.it_value.tv_usec = 0;177setitimer(ITIMER_PROF, &interval, 0);178}179180181