2
|
1 |
/*
|
|
2 |
* Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
#include <stdlib.h>
|
|
27 |
#include <string.h>
|
|
28 |
#include <sys/time.h>
|
|
29 |
#include <sys/utsname.h>
|
|
30 |
#include <sys/types.h>
|
|
31 |
#include <errno.h>
|
|
32 |
#include <dlfcn.h>
|
|
33 |
#include "jni.h"
|
|
34 |
#include <jni_util.h>
|
|
35 |
#include "awt_Mlib.h"
|
|
36 |
#include "java_awt_image_BufferedImage.h"
|
|
37 |
|
|
38 |
static void start_timer(int numsec);
|
|
39 |
static void stop_timer(int numsec, int ntimes);
|
|
40 |
|
|
41 |
/*
|
|
42 |
* This is called by awt_ImagingLib.initLib() to figure out if we
|
|
43 |
* can use the VIS version of medialib
|
|
44 |
*/
|
|
45 |
mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
|
|
46 |
mlibSysFnS_t *sMlibSysFns) {
|
|
47 |
int status;
|
|
48 |
jstring jstr = NULL;
|
|
49 |
mlibFnS_t *mptr;
|
|
50 |
void *(*vPtr)();
|
|
51 |
int (*intPtr)();
|
|
52 |
mlib_status (*fPtr)();
|
|
53 |
int i;
|
|
54 |
void *handle = NULL;
|
|
55 |
mlibSysFnS_t tempSysFns;
|
|
56 |
static int s_timeIt = 0;
|
|
57 |
static int s_verbose = 1;
|
|
58 |
mlib_status ret = MLIB_SUCCESS;
|
|
59 |
struct utsname name;
|
|
60 |
|
|
61 |
/*
|
|
62 |
* Find out the machine name. If it is an SUN ultra, we
|
|
63 |
* can use the vis library
|
|
64 |
*/
|
|
65 |
if ((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 |
{
|
|
70 |
handle = dlopen("libmlib_image_v.so", RTLD_LAZY);
|
|
71 |
}
|
|
72 |
|
|
73 |
if (handle == NULL) {
|
|
74 |
handle = dlopen("libmlib_image.so", RTLD_LAZY);
|
|
75 |
}
|
|
76 |
|
|
77 |
if (handle == NULL) {
|
|
78 |
if (s_timeIt || s_verbose) {
|
|
79 |
printf ("error in dlopen: %s", dlerror());
|
|
80 |
}
|
|
81 |
return MLIB_FAILURE;
|
|
82 |
}
|
|
83 |
|
|
84 |
/* So, if we are here, then either vis or generic version of
|
|
85 |
* medialib library was sucessfuly loaded.
|
|
86 |
* Let's try to initialize handlers...
|
|
87 |
*/
|
|
88 |
if ((tempSysFns.createFP = (MlibCreateFP_t)dlsym(handle,
|
|
89 |
"j2d_mlib_ImageCreate")) == NULL) {
|
|
90 |
if (s_timeIt) {
|
|
91 |
printf ("error in dlsym: %s", dlerror());
|
|
92 |
}
|
|
93 |
ret = MLIB_FAILURE;
|
|
94 |
}
|
|
95 |
|
|
96 |
if (ret == MLIB_SUCCESS) {
|
|
97 |
if ((tempSysFns.createStructFP = (MlibCreateStructFP_t)dlsym(handle,
|
|
98 |
"j2d_mlib_ImageCreateStruct")) == NULL) {
|
|
99 |
if (s_timeIt) {
|
|
100 |
printf ("error in dlsym: %s", dlerror());
|
|
101 |
}
|
|
102 |
ret = MLIB_FAILURE;
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
if (ret == MLIB_SUCCESS) {
|
|
107 |
if ((tempSysFns.deleteImageFP = (MlibDeleteFP_t)dlsym(handle,
|
|
108 |
"j2d_mlib_ImageDelete")) == NULL) {
|
|
109 |
if (s_timeIt) {
|
|
110 |
printf ("error in dlsym: %s", dlerror());
|
|
111 |
}
|
|
112 |
ret = MLIB_FAILURE;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
/* Set the system functions */
|
|
117 |
if (ret == MLIB_SUCCESS) {
|
|
118 |
*sMlibSysFns = tempSysFns;
|
|
119 |
}
|
|
120 |
|
|
121 |
/* Loop through all of the fns and load them from the next library */
|
|
122 |
mptr = sMlibFns;
|
|
123 |
i = 0;
|
|
124 |
while ((ret == MLIB_SUCCESS) && (mptr[i].fname != NULL)) {
|
|
125 |
fPtr = (mlib_status (*)())dlsym(handle, mptr[i].fname);
|
|
126 |
if (fPtr != NULL) {
|
|
127 |
mptr[i].fptr = fPtr;
|
|
128 |
} else {
|
|
129 |
ret = MLIB_FAILURE;
|
|
130 |
}
|
|
131 |
i++;
|
|
132 |
}
|
|
133 |
if (ret != MLIB_SUCCESS) {
|
|
134 |
dlclose(handle);
|
|
135 |
}
|
|
136 |
return ret;
|
|
137 |
}
|
|
138 |
|
|
139 |
mlib_start_timer awt_setMlibStartTimer() {
|
|
140 |
return start_timer;
|
|
141 |
}
|
|
142 |
|
|
143 |
mlib_stop_timer awt_setMlibStopTimer() {
|
|
144 |
return stop_timer;
|
|
145 |
}
|
|
146 |
|
|
147 |
void awt_getBIColorOrder(int type, int *colorOrder) {
|
|
148 |
switch(type) {
|
|
149 |
case java_awt_image_BufferedImage_TYPE_INT_ARGB:
|
|
150 |
case java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE:
|
|
151 |
colorOrder[0] = 1;
|
|
152 |
colorOrder[1] = 2;
|
|
153 |
colorOrder[2] = 3;
|
|
154 |
colorOrder[3] = 0;
|
|
155 |
break;
|
|
156 |
case java_awt_image_BufferedImage_TYPE_INT_BGR:
|
|
157 |
colorOrder[0] = 2;
|
|
158 |
colorOrder[1] = 1;
|
|
159 |
colorOrder[2] = 0;
|
|
160 |
break;
|
|
161 |
case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR:
|
|
162 |
case java_awt_image_BufferedImage_TYPE_4BYTE_ABGR_PRE:
|
|
163 |
colorOrder[0] = 3;
|
|
164 |
colorOrder[1] = 2;
|
|
165 |
colorOrder[2] = 1;
|
|
166 |
colorOrder[3] = 0;
|
|
167 |
break;
|
|
168 |
case java_awt_image_BufferedImage_TYPE_3BYTE_BGR:
|
|
169 |
colorOrder[0] = 2;
|
|
170 |
colorOrder[1] = 1;
|
|
171 |
colorOrder[2] = 0;
|
|
172 |
break;
|
|
173 |
case java_awt_image_BufferedImage_TYPE_INT_RGB:
|
|
174 |
colorOrder[0] = 1;
|
|
175 |
colorOrder[1] = 2;
|
|
176 |
colorOrder[2] = 3;
|
|
177 |
break;
|
|
178 |
case java_awt_image_BufferedImage_TYPE_USHORT_565_RGB:
|
|
179 |
case java_awt_image_BufferedImage_TYPE_USHORT_555_RGB:
|
|
180 |
colorOrder[0] = 0;
|
|
181 |
colorOrder[1] = 1;
|
|
182 |
colorOrder[2] = 2;
|
|
183 |
break;
|
|
184 |
case java_awt_image_BufferedImage_TYPE_BYTE_GRAY:
|
|
185 |
case java_awt_image_BufferedImage_TYPE_USHORT_GRAY:
|
|
186 |
case java_awt_image_BufferedImage_TYPE_BYTE_BINARY:
|
|
187 |
case java_awt_image_BufferedImage_TYPE_BYTE_INDEXED:
|
|
188 |
colorOrder[0] = 0;
|
|
189 |
break;
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
/***************************************************************************
|
|
194 |
* Static Functions *
|
|
195 |
***************************************************************************/
|
|
196 |
|
|
197 |
static void start_timer(int numsec)
|
|
198 |
{
|
|
199 |
struct itimerval interval;
|
|
200 |
|
|
201 |
interval.it_interval.tv_sec = numsec;
|
|
202 |
interval.it_interval.tv_usec = 0;
|
|
203 |
interval.it_value.tv_sec = numsec;
|
|
204 |
interval.it_value.tv_usec = 0;
|
|
205 |
setitimer(ITIMER_REAL, &interval, 0);
|
|
206 |
}
|
|
207 |
|
|
208 |
|
|
209 |
static void stop_timer(int numsec, int ntimes)
|
|
210 |
{
|
|
211 |
struct itimerval interval;
|
|
212 |
double sec;
|
|
213 |
|
|
214 |
getitimer(ITIMER_REAL, &interval);
|
|
215 |
sec = (((double) (numsec - 1)) - (double) interval.it_value.tv_sec) +
|
|
216 |
(1000000.0 - interval.it_value.tv_usec)/1000000.0;
|
|
217 |
sec = sec/((double) ntimes);
|
|
218 |
printf("%f msec per update\n", sec * 1000.0);
|
|
219 |
interval.it_interval.tv_sec = 0;
|
|
220 |
interval.it_interval.tv_usec = 0;
|
|
221 |
interval.it_value.tv_sec = 0;
|
|
222 |
interval.it_value.tv_usec = 0;
|
|
223 |
setitimer(ITIMER_PROF, &interval, 0);
|
|
224 |
}
|