Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/unix/native/libawt/awt/awt_Mlib.c
41152 views
1
/*
2
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* 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 "jvm_md.h"
36
#include "awt_Mlib.h"
37
#include "java_awt_image_BufferedImage.h"
38
39
#ifdef STATIC_BUILD
40
#include "mlib_image.h"
41
#endif
42
43
static void start_timer(int numsec);
44
static void stop_timer(int numsec, int ntimes);
45
46
#ifdef STATIC_BUILD
47
// Mapping functions to their names for runtime check
48
static mlibFnS_t sMlibFnsStatic[] = {
49
{j2d_mlib_ImageConvMxN, "j2d_mlib_ImageConvMxN"},
50
{j2d_mlib_ImageAffine, "j2d_mlib_ImageAffine"},
51
{j2d_mlib_ImageLookUp, "j2d_mlib_ImageLookUp"},
52
{j2d_mlib_ImageConvKernelConvert, "j2d_mlib_ImageConvKernelConvert"},
53
};
54
55
mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
56
mlibSysFnS_t *sMlibSysFns) {
57
mlibFnS_t *mptr;
58
int i;
59
char *fName;
60
mlibSysFnS_t tempSysFns;
61
mlib_status ret = MLIB_SUCCESS;
62
63
tempSysFns.createFP = j2d_mlib_ImageCreate;
64
tempSysFns.createStructFP = j2d_mlib_ImageCreateStruct;
65
tempSysFns.deleteImageFP = j2d_mlib_ImageDelete;
66
*sMlibSysFns = tempSysFns;
67
68
mptr = sMlibFns;
69
i = 0;
70
while (mptr[i].fname != NULL) {
71
fName = mptr[i].fname;
72
if(strcmp(fName, sMlibFnsStatic[i].fname) == 0) {
73
mptr[i].fptr = sMlibFnsStatic[i].fptr;
74
} else {
75
ret = MLIB_FAILURE;
76
}
77
i++;
78
}
79
80
return ret;
81
}
82
#else
83
/*
84
* This is called by awt_ImagingLib.initLib()
85
*/
86
mlib_status awt_getImagingLib(JNIEnv *env, mlibFnS_t *sMlibFns,
87
mlibSysFnS_t *sMlibSysFns) {
88
int status;
89
jstring jstr = NULL;
90
mlibFnS_t *mptr;
91
void *(*vPtr)();
92
int (*intPtr)();
93
mlib_status (*fPtr)();
94
int i;
95
void *handle = NULL;
96
mlibSysFnS_t tempSysFns;
97
static int s_timeIt = 0;
98
static int s_verbose = 1;
99
mlib_status ret = MLIB_SUCCESS;
100
struct utsname name;
101
102
handle = dlopen(JNI_LIB_NAME("mlib_image"), RTLD_LAZY);
103
104
if (handle == NULL) {
105
if (s_timeIt || s_verbose) {
106
printf ("error in dlopen: %s", dlerror());
107
}
108
return MLIB_FAILURE;
109
}
110
111
/* So, if we are here, then either vis or generic version of
112
* medialib library was sucessfuly loaded.
113
* Let's try to initialize handlers...
114
*/
115
if ((tempSysFns.createFP = (MlibCreateFP_t)dlsym(handle,
116
"j2d_mlib_ImageCreate")) == NULL) {
117
if (s_timeIt) {
118
printf ("error in dlsym: %s", dlerror());
119
}
120
ret = MLIB_FAILURE;
121
}
122
123
if (ret == MLIB_SUCCESS) {
124
if ((tempSysFns.createStructFP = (MlibCreateStructFP_t)dlsym(handle,
125
"j2d_mlib_ImageCreateStruct")) == NULL) {
126
if (s_timeIt) {
127
printf ("error in dlsym: %s", dlerror());
128
}
129
ret = MLIB_FAILURE;
130
}
131
}
132
133
if (ret == MLIB_SUCCESS) {
134
if ((tempSysFns.deleteImageFP = (MlibDeleteFP_t)dlsym(handle,
135
"j2d_mlib_ImageDelete")) == NULL) {
136
if (s_timeIt) {
137
printf ("error in dlsym: %s", dlerror());
138
}
139
ret = MLIB_FAILURE;
140
}
141
}
142
143
/* Set the system functions */
144
if (ret == MLIB_SUCCESS) {
145
*sMlibSysFns = tempSysFns;
146
}
147
148
/* Loop through all of the fns and load them from the next library */
149
mptr = sMlibFns;
150
i = 0;
151
while ((ret == MLIB_SUCCESS) && (mptr[i].fname != NULL)) {
152
fPtr = (mlib_status (*)())dlsym(handle, mptr[i].fname);
153
if (fPtr != NULL) {
154
mptr[i].fptr = fPtr;
155
} else {
156
ret = MLIB_FAILURE;
157
}
158
i++;
159
}
160
if (ret != MLIB_SUCCESS) {
161
dlclose(handle);
162
}
163
return ret;
164
}
165
#endif
166
167
mlib_start_timer awt_setMlibStartTimer() {
168
return start_timer;
169
}
170
171
mlib_stop_timer awt_setMlibStopTimer() {
172
return stop_timer;
173
}
174
175
/***************************************************************************
176
* Static Functions *
177
***************************************************************************/
178
179
static void start_timer(int numsec)
180
{
181
struct itimerval interval;
182
183
interval.it_interval.tv_sec = numsec;
184
interval.it_interval.tv_usec = 0;
185
interval.it_value.tv_sec = numsec;
186
interval.it_value.tv_usec = 0;
187
setitimer(ITIMER_REAL, &interval, 0);
188
}
189
190
191
static void stop_timer(int numsec, int ntimes)
192
{
193
struct itimerval interval;
194
double sec;
195
196
getitimer(ITIMER_REAL, &interval);
197
sec = (((double) (numsec - 1)) - (double) interval.it_value.tv_sec) +
198
(1000000.0 - interval.it_value.tv_usec)/1000000.0;
199
sec = sec/((double) ntimes);
200
printf("%f msec per update\n", sec * 1000.0);
201
interval.it_interval.tv_sec = 0;
202
interval.it_interval.tv_usec = 0;
203
interval.it_value.tv_sec = 0;
204
interval.it_value.tv_usec = 0;
205
setitimer(ITIMER_PROF, &interval, 0);
206
}
207
208