summaryrefslogtreecommitdiffstats
path: root/opengl/tools
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-05-07 18:28:29 -0700
committerJack Palevich <jackpal@google.com>2009-05-07 18:28:29 -0700
commit46d25a371d58c63cbd72f5d08348e9b75c2ac22c (patch)
tree0e45712e9f287bc3cc49b7b5f27144230427810c /opengl/tools
parentc1d9854e399e21bc93bf64480ab1dad726d05718 (diff)
downloadframeworks_native-46d25a371d58c63cbd72f5d08348e9b75c2ac22c.zip
frameworks_native-46d25a371d58c63cbd72f5d08348e9b75c2ac22c.tar.gz
frameworks_native-46d25a371d58c63cbd72f5d08348e9b75c2ac22c.tar.bz2
Require native-order direct buffers for glXXXPointer APIs.
This was always a documented restriction, but was not enforced by the runtime until now. Until now, if you passed in some other kind of buffer, it would sometimes work, and sometimes fail. The failures happened when the Java VM moved the buffer data while OpenGL was still holding a pointer to it. Now we throw an exception rather than leaving the system in a potentially bad state.
Diffstat (limited to 'opengl/tools')
-rw-r--r--opengl/tools/glgen/src/JniCodeEmitter.java67
1 files changed, 48 insertions, 19 deletions
diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java
index ef0dbd0..b0997b1 100644
--- a/opengl/tools/glgen/src/JniCodeEmitter.java
+++ b/opengl/tools/glgen/src/JniCodeEmitter.java
@@ -454,6 +454,15 @@ public class JniCodeEmitter {
String iii = indent + indent;
+ // emitBoundsChecks(jfunc, out, iii);
+ emitFunctionCall(jfunc, out, iii, false);
+
+ // Set the pointer after we call the native code, so that if
+ // the native code throws an exception we don't modify the
+ // pointer. We assume that the native code is written so that
+ // if an exception is thrown, then the underlying glXXXPointer
+ // function will not have been called.
+
String fname = jfunc.getName();
if (isPointerFunc) {
// TODO - deal with VBO variants
@@ -498,9 +507,6 @@ public class JniCodeEmitter {
}
}
- // emitBoundsChecks(jfunc, out, iii);
- emitFunctionCall(jfunc, out, iii, false);
-
boolean isVoid = jfunc.getType().isVoid();
if (!isVoid) {
@@ -873,19 +879,39 @@ public class JniCodeEmitter {
String array = numBufferArgs <= 1 ? "_array" :
"_" + bufferArgNames.get(bufArgIdx++) + "Array";
- boolean nullAllowed = isNullAllowed(cfunc);
+ boolean nullAllowed = isNullAllowed(cfunc) || isPointerFunc;
if (nullAllowed) {
out.println(indent + "if (" + cname + "_buf) {");
out.print(indent);
}
- out.println(indent +
+ if (isPointerFunc) {
+ out.println(indent +
cname +
" = (" +
cfunc.getArgType(cIndex).getDeclaration() +
- ")getPointer(_env, " +
- cname +
- "_buf, &" + array + ", &" + remaining + ");");
+ ") _env->GetDirectBufferAddress(" +
+ (mUseCPlusPlus ? "" : "_env, ") +
+ cname + "_buf);");
+ String iii = " ";
+ out.println(iii + indent + "if ( ! " + cname + " ) {");
+ out.println(iii + iii + indent +
+ (mUseCPlusPlus ? "_env" : "(*_env)") +
+ "->ThrowNew(" +
+ (mUseCPlusPlus ? "" : "_env, ") +
+ "IAEClass, \"Must use a native order direct Buffer\");");
+ out.println(iii + iii + indent + "return;");
+ out.println(iii + indent + "}");
+ } else {
+ out.println(indent +
+ cname +
+ " = (" +
+ cfunc.getArgType(cIndex).getDeclaration() +
+ ")getPointer(_env, " +
+ cname +
+ "_buf, &" + array + ", &" + remaining +
+ ");");
+ }
if (nullAllowed) {
out.println(indent + "}");
@@ -987,17 +1013,20 @@ public class JniCodeEmitter {
");");
out.println(indent + "}");
} else if (jfunc.getArgType(idx).isBuffer()) {
- String array = numBufferArgs <= 1 ? "_array" :
- "_" + bufferArgNames.get(bufArgIdx++) + "Array";
- out.println(indent + "if (" + array + ") {");
- out.println(indent + indent +
- "releasePointer(_env, " + array + ", " +
- cfunc.getArgName(cIndex) +
- ", " +
- (cfunc.getArgType(cIndex).isConst() ?
- "JNI_FALSE" : "_exception ? JNI_FALSE : JNI_TRUE") +
- ");");
- out.println(indent + "}");
+ if (! isPointerFunc) {
+ String array = numBufferArgs <= 1 ? "_array" :
+ "_" + bufferArgNames.get(bufArgIdx++) + "Array";
+ out.println(indent + "if (" + array + ") {");
+ out.println(indent + indent +
+ "releasePointer(_env, " + array + ", " +
+ cfunc.getArgName(cIndex) +
+ ", " +
+ (cfunc.getArgType(cIndex).isConst() ?
+ "JNI_FALSE" : "_exception ? JNI_FALSE :" +
+ " JNI_TRUE") +
+ ");");
+ out.println(indent + "}");
+ }
}
}
}