jdk/src/solaris/native/sun/awt/awt_Mlib.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "awt_Mlib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "java_awt_image_BufferedImage.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
static void start_timer(int numsec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
static void stop_timer(int numsec, int ntimes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This is called by awt_ImagingLib.initLib() to figure out if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * can use the VIS version of medialib
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                              mlibSysFnS_t *sMlibSysFns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    jstring jstr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    mlibFnS_t *mptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    void *(*vPtr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    int (*intPtr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    mlib_status (*fPtr)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    void *handle = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    mlibSysFnS_t tempSysFns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static int s_timeIt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static int s_verbose = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    mlib_status ret = MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    struct utsname name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Find out the machine name. If it is an SUN ultra, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * can use the vis library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    if ((uname(&name) >= 0) && (getenv("NO_VIS") == NULL) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        (strncmp(name.machine, "sun4u" , 5) == 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        ((strncmp(name.machine, "sun4v" , 5) == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         (getenv("USE_VIS_ON_SUN4V") != NULL)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        handle = dlopen("libmlib_image_v.so", RTLD_LAZY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    if (handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        handle = dlopen("libmlib_image.so", RTLD_LAZY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    if (handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (s_timeIt || s_verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            printf ("error in dlopen: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /* So, if we are here, then either vis or generic version of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * medialib library was sucessfuly loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Let's try to initialize handlers...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    if ((tempSysFns.createFP = (MlibCreateFP_t)dlsym(handle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                       "j2d_mlib_ImageCreate")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (s_timeIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            printf ("error in dlsym: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    if (ret == MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if ((tempSysFns.createStructFP = (MlibCreateStructFP_t)dlsym(handle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                          "j2d_mlib_ImageCreateStruct")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (s_timeIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                printf ("error in dlsym: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    if (ret == MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if ((tempSysFns.deleteImageFP = (MlibDeleteFP_t)dlsym(handle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                                 "j2d_mlib_ImageDelete")) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (s_timeIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                printf ("error in dlsym: %s", dlerror());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /* Set the system functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    if (ret == MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        *sMlibSysFns = tempSysFns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /* Loop through all of the fns and load them from the next library */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    mptr = sMlibFns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    while ((ret == MLIB_SUCCESS) && (mptr[i].fname != NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        fPtr = (mlib_status (*)())dlsym(handle, mptr[i].fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (fPtr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            mptr[i].fptr = fPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            ret = MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (ret != MLIB_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        dlclose(handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
mlib_start_timer awt_setMlibStartTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    return start_timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
mlib_stop_timer awt_setMlibStopTimer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    return stop_timer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
void awt_getBIColorOrder(int type, int *colorOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    switch(type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    case java_awt_image_BufferedImage_TYPE_INT_ARGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        colorOrder[0] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        colorOrder[1] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        colorOrder[2] = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        colorOrder[3] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    case java_awt_image_BufferedImage_TYPE_INT_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        colorOrder[0] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        colorOrder[1] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        colorOrder[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        colorOrder[0] = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        colorOrder[1] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        colorOrder[2] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        colorOrder[3] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        colorOrder[0] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        colorOrder[1] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        colorOrder[2] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    case java_awt_image_BufferedImage_TYPE_INT_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        colorOrder[0] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        colorOrder[1] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        colorOrder[2] = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    case java_awt_image_BufferedImage_TYPE_USHORT_555_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        colorOrder[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        colorOrder[1] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        colorOrder[2] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    case java_awt_image_BufferedImage_TYPE_BYTE_BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        colorOrder[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
/***************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *                          Static Functions                               *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 ***************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
static void start_timer(int numsec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    struct itimerval interval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    interval.it_interval.tv_sec = numsec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    interval.it_interval.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    interval.it_value.tv_sec = numsec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    interval.it_value.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    setitimer(ITIMER_REAL, &interval, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
static void stop_timer(int numsec, int ntimes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    struct itimerval interval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    double sec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    getitimer(ITIMER_REAL, &interval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    sec = (((double) (numsec - 1)) - (double) interval.it_value.tv_sec) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            (1000000.0 - interval.it_value.tv_usec)/1000000.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    sec = sec/((double) ntimes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    printf("%f msec per update\n", sec * 1000.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    interval.it_interval.tv_sec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    interval.it_interval.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    interval.it_value.tv_sec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    interval.it_value.tv_usec = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    setitimer(ITIMER_PROF, &interval, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
}