src/java.desktop/unix/native/libawt/awt/awt_Mlib.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 47216 71c04702a3d5
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 15502
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <sys/utsname.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <jni_util.h>
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    35
#include "jvm_md.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "awt_Mlib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "java_awt_image_BufferedImage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
static void start_timer(int numsec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
static void stop_timer(int numsec, int ntimes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This is called by awt_ImagingLib.initLib() to figure out if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * can use the VIS version of medialib
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                              mlibSysFnS_t *sMlibSysFns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    jstring jstr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    mlibFnS_t *mptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    void *(*vPtr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    int (*intPtr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    mlib_status (*fPtr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    void *handle = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    mlibSysFnS_t tempSysFns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static int s_timeIt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static int s_verbose = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    mlib_status ret = MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    struct utsname name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Find out the machine name. If it is an SUN ultra, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * can use the vis library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    if ((uname(&name) >= 0) && (getenv("NO_VIS") == NULL) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        (strncmp(name.machine, "sun4u" , 5) == 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        ((strncmp(name.machine, "sun4v" , 5) == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         (getenv("USE_VIS_ON_SUN4V") != NULL)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    71
        handle = dlopen(JNI_LIB_NAME("mlib_image_v"), RTLD_LAZY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    if (handle == NULL) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
    75
        handle = dlopen(JNI_LIB_NAME("mlib_image"), RTLD_LAZY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    if (handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (s_timeIt || s_verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            printf ("error in dlopen: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /* So, if we are here, then either vis or generic version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * medialib library was sucessfuly loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Let's try to initialize handlers...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    if ((tempSysFns.createFP = (MlibCreateFP_t)dlsym(handle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                       "j2d_mlib_ImageCreate")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (s_timeIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            printf ("error in dlsym: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    if (ret == MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if ((tempSysFns.createStructFP = (MlibCreateStructFP_t)dlsym(handle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                          "j2d_mlib_ImageCreateStruct")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            if (s_timeIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                printf ("error in dlsym: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    if (ret == MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if ((tempSysFns.deleteImageFP = (MlibDeleteFP_t)dlsym(handle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                                 "j2d_mlib_ImageDelete")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (s_timeIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                printf ("error in dlsym: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /* Set the system functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    if (ret == MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        *sMlibSysFns = tempSysFns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /* Loop through all of the fns and load them from the next library */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    mptr = sMlibFns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    while ((ret == MLIB_SUCCESS) && (mptr[i].fname != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        fPtr = (mlib_status (*)())dlsym(handle, mptr[i].fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (fPtr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            mptr[i].fptr = fPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    if (ret != MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        dlclose(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   140
mlib_start_timer awt_setMlibStartTimer(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return start_timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 47216
diff changeset
   144
mlib_stop_timer awt_setMlibStopTimer(void) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    return stop_timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
/***************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *                          Static Functions                               *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 ***************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
static void start_timer(int numsec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    struct itimerval interval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    interval.it_interval.tv_sec = numsec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    interval.it_interval.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    interval.it_value.tv_sec = numsec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    interval.it_value.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    setitimer(ITIMER_REAL, &interval, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
static void stop_timer(int numsec, int ntimes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    struct itimerval interval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    double sec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    getitimer(ITIMER_REAL, &interval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    sec = (((double) (numsec - 1)) - (double) interval.it_value.tv_sec) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            (1000000.0 - interval.it_value.tv_usec)/1000000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    sec = sec/((double) ntimes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    printf("%f msec per update\n", sec * 1000.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    interval.it_interval.tv_sec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    interval.it_interval.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    interval.it_value.tv_sec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    interval.it_value.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    setitimer(ITIMER_PROF, &interval, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}