0N/A/*
2362N/A * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#include <stdlib.h>
0N/A#include <string.h>
0N/A#include <sys/time.h>
0N/A#include <sys/utsname.h>
0N/A#include <sys/types.h>
0N/A#include <errno.h>
0N/A#include <dlfcn.h>
0N/A#include "jni.h"
0N/A#include <jni_util.h>
4632N/A#include "jvm_md.h"
0N/A#include "awt_Mlib.h"
0N/A#include "java_awt_image_BufferedImage.h"
0N/A
0N/Astatic void start_timer(int numsec);
0N/Astatic void stop_timer(int numsec, int ntimes);
0N/A
0N/A/*
0N/A * This is called by awt_ImagingLib.initLib() to figure out if we
0N/A * can use the VIS version of medialib
0N/A */
0N/Amlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
0N/A mlibSysFnS_t *sMlibSysFns) {
0N/A int status;
0N/A jstring jstr = NULL;
0N/A mlibFnS_t *mptr;
0N/A void *(*vPtr)();
0N/A int (*intPtr)();
0N/A mlib_status (*fPtr)();
0N/A int i;
0N/A void *handle = NULL;
0N/A mlibSysFnS_t tempSysFns;
0N/A static int s_timeIt = 0;
0N/A static int s_verbose = 1;
0N/A mlib_status ret = MLIB_SUCCESS;
0N/A struct utsname name;
0N/A
0N/A /*
0N/A * Find out the machine name. If it is an SUN ultra, we
0N/A * can use the vis library
0N/A */
0N/A if ((uname(&name) >= 0) && (getenv("NO_VIS") == NULL) &&
0N/A (strncmp(name.machine, "sun4u" , 5) == 0) ||
0N/A ((strncmp(name.machine, "sun4v" , 5) == 0) &&
0N/A (getenv("USE_VIS_ON_SUN4V") != NULL)))
0N/A {
4632N/A handle = dlopen(JNI_LIB_NAME("mlib_image_v"), RTLD_LAZY);
0N/A }
0N/A
0N/A if (handle == NULL) {
4632N/A handle = dlopen(JNI_LIB_NAME("mlib_image"), RTLD_LAZY);
0N/A }
0N/A
0N/A if (handle == NULL) {
0N/A if (s_timeIt || s_verbose) {
0N/A printf ("error in dlopen: %s", dlerror());
0N/A }
0N/A return MLIB_FAILURE;
0N/A }
0N/A
0N/A /* So, if we are here, then either vis or generic version of
0N/A * medialib library was sucessfuly loaded.
0N/A * Let's try to initialize handlers...
0N/A */
0N/A if ((tempSysFns.createFP = (MlibCreateFP_t)dlsym(handle,
0N/A "j2d_mlib_ImageCreate")) == NULL) {
0N/A if (s_timeIt) {
0N/A printf ("error in dlsym: %s", dlerror());
0N/A }
0N/A ret = MLIB_FAILURE;
0N/A }
0N/A
0N/A if (ret == MLIB_SUCCESS) {
0N/A if ((tempSysFns.createStructFP = (MlibCreateStructFP_t)dlsym(handle,
0N/A "j2d_mlib_ImageCreateStruct")) == NULL) {
0N/A if (s_timeIt) {
0N/A printf ("error in dlsym: %s", dlerror());
0N/A }
0N/A ret = MLIB_FAILURE;
0N/A }
0N/A }
0N/A
0N/A if (ret == MLIB_SUCCESS) {
0N/A if ((tempSysFns.deleteImageFP = (MlibDeleteFP_t)dlsym(handle,
0N/A "j2d_mlib_ImageDelete")) == NULL) {
0N/A if (s_timeIt) {
0N/A printf ("error in dlsym: %s", dlerror());
0N/A }
0N/A ret = MLIB_FAILURE;
0N/A }
0N/A }
0N/A
0N/A /* Set the system functions */
0N/A if (ret == MLIB_SUCCESS) {
0N/A *sMlibSysFns = tempSysFns;
0N/A }
0N/A
0N/A /* Loop through all of the fns and load them from the next library */
0N/A mptr = sMlibFns;
0N/A i = 0;
0N/A while ((ret == MLIB_SUCCESS) && (mptr[i].fname != NULL)) {
0N/A fPtr = (mlib_status (*)())dlsym(handle, mptr[i].fname);
0N/A if (fPtr != NULL) {
0N/A mptr[i].fptr = fPtr;
0N/A } else {
0N/A ret = MLIB_FAILURE;
0N/A }
0N/A i++;
0N/A }
0N/A if (ret != MLIB_SUCCESS) {
0N/A dlclose(handle);
0N/A }
0N/A return ret;
0N/A}
0N/A
0N/Amlib_start_timer awt_setMlibStartTimer() {
0N/A return start_timer;
0N/A}
0N/A
0N/Amlib_stop_timer awt_setMlibStopTimer() {
0N/A return stop_timer;
0N/A}
0N/A
0N/Avoid awt_getBIColorOrder(int type, int *colorOrder) {
0N/A switch(type) {
0N/A case java_awt_image_BufferedImage_TYPE_INT_ARGB:
0N/A case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
0N/A colorOrder[0] = 1;
0N/A colorOrder[1] = 2;
0N/A colorOrder[2] = 3;
0N/A colorOrder[3] = 0;
0N/A break;
0N/A case java_awt_image_BufferedImage_TYPE_INT_BGR:
0N/A colorOrder[0] = 2;
0N/A colorOrder[1] = 1;
0N/A colorOrder[2] = 0;
0N/A break;
0N/A case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
0N/A case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
0N/A colorOrder[0] = 3;
0N/A colorOrder[1] = 2;
0N/A colorOrder[2] = 1;
0N/A colorOrder[3] = 0;
0N/A break;
0N/A case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
0N/A colorOrder[0] = 2;
0N/A colorOrder[1] = 1;
0N/A colorOrder[2] = 0;
0N/A break;
0N/A case java_awt_image_BufferedImage_TYPE_INT_RGB:
0N/A colorOrder[0] = 1;
0N/A colorOrder[1] = 2;
0N/A colorOrder[2] = 3;
0N/A break;
0N/A case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
0N/A case java_awt_image_BufferedImage_TYPE_USHORT_555_RGB:
0N/A colorOrder[0] = 0;
0N/A colorOrder[1] = 1;
0N/A colorOrder[2] = 2;
0N/A break;
0N/A case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
0N/A case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
0N/A case java_awt_image_BufferedImage_TYPE_BYTE_BINARY:
0N/A case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
0N/A colorOrder[0] = 0;
0N/A break;
0N/A }
0N/A}
0N/A
0N/A/***************************************************************************
0N/A * Static Functions *
0N/A ***************************************************************************/
0N/A
0N/Astatic void start_timer(int numsec)
0N/A{
0N/A struct itimerval interval;
0N/A
0N/A interval.it_interval.tv_sec = numsec;
0N/A interval.it_interval.tv_usec = 0;
0N/A interval.it_value.tv_sec = numsec;
0N/A interval.it_value.tv_usec = 0;
0N/A setitimer(ITIMER_REAL, &interval, 0);
0N/A}
0N/A
0N/A
0N/Astatic void stop_timer(int numsec, int ntimes)
0N/A{
0N/A struct itimerval interval;
0N/A double sec;
0N/A
0N/A getitimer(ITIMER_REAL, &interval);
0N/A sec = (((double) (numsec - 1)) - (double) interval.it_value.tv_sec) +
0N/A (1000000.0 - interval.it_value.tv_usec)/1000000.0;
0N/A sec = sec/((double) ntimes);
0N/A printf("%f msec per update\n", sec * 1000.0);
0N/A interval.it_interval.tv_sec = 0;
0N/A interval.it_interval.tv_usec = 0;
0N/A interval.it_value.tv_sec = 0;
0N/A interval.it_value.tv_usec = 0;
0N/A setitimer(ITIMER_PROF, &interval, 0);
0N/A}