1 |
|
|
2 |
|
#include <cstring> |
3 |
#include <vector> |
#include <vector> |
4 |
#include "gzz_gfx_gl_GL.h" |
#include "gzz_gfx_gl_GL.h" |
5 |
|
|
104 |
jstring stdstr2jstr(JNIEnv *env, std::string stdstr) { |
jstring stdstr2jstr(JNIEnv *env, std::string stdstr) { |
105 |
return env->NewStringUTF(stdstr.c_str()); |
return env->NewStringUTF(stdstr.c_str()); |
106 |
} |
} |
107 |
|
|
108 |
/** Converts jstring to unistring _without_ asking |
/** Converts jstring to unistring _without_ asking |
109 |
* string length from JNIEnv. This could have been |
* string length from JNIEnv. This could have been |
110 |
* the non-null-string bug, Benja founded. Although, |
* the non-null-string bug, Benja founded. |
|
* std::basic_string <unsigned short> doesn't seem |
|
|
* to be valid anymore: "undefined symbol: |
|
|
* std::char_traits<unsigned short>::length(unsigned short const*)" |
|
111 |
* |
* |
112 |
* Anyway, these can be dropped, when cleaning Gzz-Gl-jni |
* Anyway, these can be dropped, when cleaning Gzz-Gl-jni |
113 |
* and this is considered to be irrelevant. |
* and this is considered to be irrelevant. |
114 |
*/ |
*/ |
115 |
/* |
/** And this specialization of char_traits propably does |
116 |
|
not belong to here, but it exists only for this |
117 |
|
non-null-string bug test. */ |
118 |
|
namespace std { |
119 |
|
template<> |
120 |
|
struct char_traits<unsigned short> |
121 |
|
{ |
122 |
|
typedef unsigned short char_type; |
123 |
|
typedef int int_type; |
124 |
|
typedef streampos pos_type; |
125 |
|
typedef streamoff off_type; |
126 |
|
typedef mbstate_t state_type; |
127 |
|
|
128 |
|
static void |
129 |
|
assign(char_type& __c1, const char_type& __c2) |
130 |
|
{ __c1 = __c2; } |
131 |
|
|
132 |
|
static bool |
133 |
|
eq(const char_type& __c1, const char_type& __c2) |
134 |
|
{ return __c1 == __c2; } |
135 |
|
|
136 |
|
static bool |
137 |
|
lt(const char_type& __c1, const char_type& __c2) |
138 |
|
{ return __c1 < __c2; } |
139 |
|
|
140 |
|
static int |
141 |
|
compare(const char_type* __s1, const char_type* __s2, size_t __n) |
142 |
|
{ return memcmp(__s1, __s2, __n*2); } |
143 |
|
|
144 |
|
static size_t |
145 |
|
length(const char_type* __s) { |
146 |
|
size_t count = 0; |
147 |
|
while (__s[count] != '\0') count++; |
148 |
|
return count; |
149 |
|
} |
150 |
|
|
151 |
|
static const char_type* |
152 |
|
find(const char_type* __s, size_t __n, const char_type& __a) |
153 |
|
{ return static_cast<const char_type*>(memchr(__s, __a, __n*2)); } |
154 |
|
|
155 |
|
static char_type* |
156 |
|
move(char_type* __s1, const char_type* __s2, size_t __n) |
157 |
|
{ return static_cast<char_type*>(memmove(__s1, __s2, __n*2)); } |
158 |
|
|
159 |
|
static char_type* |
160 |
|
copy(char_type* __s1, const char_type* __s2, size_t __n) |
161 |
|
{ return static_cast<char_type*>(memcpy(__s1, __s2, __n*2)); } |
162 |
|
|
163 |
|
static char_type* |
164 |
|
assign(char_type* __s, size_t __n, char_type __a) |
165 |
|
{ return static_cast<char_type*>(memset(__s, __a, __n*2)); } |
166 |
|
|
167 |
|
static char_type |
168 |
|
to_char_type(const int_type& __c) |
169 |
|
{ return static_cast<char_type>(__c); } |
170 |
|
|
171 |
|
// To keep both the byte 0xff and the eof symbol 0xffffffff |
172 |
|
// from ending up as 0xffffffff. |
173 |
|
static int_type |
174 |
|
to_int_type(const char_type& __c) |
175 |
|
{ return static_cast<int_type>(static_cast<unsigned char>(__c)); } |
176 |
|
|
177 |
|
static bool |
178 |
|
eq_int_type(const int_type& __c1, const int_type& __c2) |
179 |
|
{ return __c1 == __c2; } |
180 |
|
|
181 |
|
static int_type |
182 |
|
eof() { return static_cast<int_type>(EOF); } |
183 |
|
|
184 |
|
static int_type |
185 |
|
not_eof(const int_type& __c) |
186 |
|
{ return (__c == eof()) ? 0 : __c; } |
187 |
|
}; |
188 |
|
} |
189 |
|
|
190 |
typedef std::basic_string<unsigned short> unistring; |
typedef std::basic_string<unsigned short> unistring; |
191 |
unistring jstr2unistr_failing(JNIEnv *env, jstring jstr) { |
unistring jstr2unistr_failing(JNIEnv *env, jstring jstr) { |
192 |
const jchar *strptr = env->GetStringChars(jstr, 0); |
const jchar *strptr = env->GetStringChars(jstr, 0); |
194 |
env->ReleaseStringChars(jstr, strptr); |
env->ReleaseStringChars(jstr, strptr); |
195 |
return unistr; |
return unistr; |
196 |
} |
} |
|
/* |
|
197 |
jstring unistr2jstr_failing(JNIEnv *env, unistring unistr) { |
jstring unistr2jstr_failing(JNIEnv *env, unistring unistr) { |
198 |
return env->NewString(&(unistr[0]), unistr.size()); |
return env->NewString(&(unistr[0]), unistr.size()); |
199 |
} |
} |
200 |
*/ |
/** **/ |
201 |
|
|
202 |
|
|
203 |
Os::Window *getWindowByWID(int wid) { |
Os::Window *getWindowByWID(int wid) { |
204 |
return (wid<0 ? defaultWindow : windows.get(wid)); |
return (wid<0 ? defaultWindow : windows.get(wid)); |
338 |
return (jdouble) atof(jstr2stdstr(env, jstr).c_str()); |
return (jdouble) atof(jstr2stdstr(env, jstr).c_str()); |
339 |
} |
} |
340 |
|
|
341 |
/* |
|
342 |
|
/** Tests convert jstring to unistring _without_ asking |
343 |
|
* string length from JNIEnv. |
344 |
|
*/ |
345 |
JNIEXPORT jstring JNICALL Java_gzz_gfx_gl_GL_1Testing_loopUnistrConvFailing |
JNIEXPORT jstring JNICALL Java_gzz_gfx_gl_GL_1Testing_loopUnistrConvFailing |
346 |
(JNIEnv *env, jobject obj, jstring jstr) { |
(JNIEnv *env, jobject obj, jstring jstr) { |
347 |
return unistr2jstr_failing(env, jstr2unistr_failing(env, jstr)); |
return unistr2jstr_failing(env, jstr2unistr_failing(env, jstr)); |
348 |
} |
} |
349 |
*/ |
/** **/ |
350 |
|
|
351 |
|
|
352 |
JNIEXPORT jint JNICALL Java_gzz_gfx_gl_GL_init |
JNIEXPORT jint JNICALL Java_gzz_gfx_gl_GL_init |
353 |
(JNIEnv *env, jclass, jint) { |
(JNIEnv *env, jclass, jint) { |