Skip to content

Commit f5e4ab6

Browse files
author
hongyun.mhy
committed
before 开始搞EGLContext的构造函数问题
1 parent ee7012c commit f5e4ab6

File tree

4 files changed

+102
-20
lines changed

4 files changed

+102
-20
lines changed

app/src/main/cpp/native-lib.cpp

+64-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <jni.h>
44
#include <string>
55
#include "android/log.h"
6+
#include <sys/system_properties.h>
7+
68
extern "C"
79

810
//JNIEXPORT jstring JNICALL
@@ -16,7 +18,7 @@ extern "C"
1618

1719
JNIEXPORT jfloatArray JNICALL
1820
Java_cookbook_testjni_MainActivity_setFloatArray(
19-
JNIEnv * env,
21+
JNIEnv *env,
2022
jobject thiz,
2123
jfloatArray fArray) {
2224

@@ -28,27 +30,27 @@ Java_cookbook_testjni_MainActivity_setFloatArray(
2830
// jchar *jcharBuffer;
2931
// env->GetStringRegion(jstring1,0,3,jcharBuffer);
3032

31-
int fLength = env->GetArrayLength(fArray);
32-
const float * floatArray = env->GetFloatArrayElements(fArray,0);
33+
int fLength = env->GetArrayLength(fArray);
34+
const float *floatArray = env->GetFloatArrayElements(fArray, 0);
3335

34-
for(int i=0;i<fLength;i++){
35-
__android_log_print(ANDROID_LOG_ERROR,"andymao","for loop item=%d,i=%d",*floatArray,i);
36-
}
36+
for (int i = 0; i < fLength; i++) {
37+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "for loop item=%d,i=%d", *floatArray, i);
38+
}
3739

38-
Test test(1,3,5);
39-
test.setTransforamMatrix(floatArray);
40+
Test test(1, 3, 5);
41+
test.setTransforamMatrix(floatArray);
4042

4143
// int aaa[5] = { 1, 2, 3, 4, 5};
4244
//
4345
// for(int j=0;j<5;j++){
4446
// __android_log_print(ANDROID_LOG_ERROR,"andymao","for loop item=%d,j=%d",aaa[j],j);
4547
// }
4648

47-
int newLength = fLength+2;
48-
jfloatArray jfloatArray1 = env->NewFloatArray(newLength);
49+
int newLength = fLength + 2;
50+
jfloatArray jfloatArray1 = env->NewFloatArray(newLength);
4951
// env->SetFloatArrayRegion(jfloatArray1,0,fLength,floatArray);
5052

51-
return jfloatArray1;
53+
return jfloatArray1;
5254

5355
}
5456

@@ -58,4 +60,55 @@ Java_cookbook_testjni_MainActivity_setFloatArray(
5860
//
5961
//
6062
// }
63+
void fillIntArray(jint*& array) {
64+
jint *fkJintArray = new jint[12];
65+
for (int i = 0; i < 12; ++i) {
66+
fkJintArray[i] = i;
67+
}
68+
69+
array = fkJintArray;
70+
}
71+
/**
72+
* http://androidxref.com/4.3_r2.1/xref/frameworks/base/opengl/java/android/opengl/EGLContext.java
73+
* http://androidxref.com/4.4_r1/xref/frameworks/base/opengl/java/android/opengl/EGLContext.java
74+
*
75+
* https://developer.android.com/reference/android/opengl/EGLObjectHandle.html#getHandle()
76+
* Use getNativeHandle() instead. Handles on 64 bit platforms will be wider than java ints.
77+
*/
78+
extern "C"
79+
JNIEXPORT void JNICALL
80+
Java_cookbook_testjni_MainActivity_getIntArray(JNIEnv *env, jobject instance,
81+
jintArray intArrays_) {
82+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "111");
83+
jclass eglcontextClassLocal = env->FindClass("android/opengl/EGLContext");
84+
jmethodID eglcontextConstructor;
85+
jobject jobject1;
86+
try {
87+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "xxxx");
88+
eglcontextConstructor=env->GetMethodID(eglcontextClassLocal, "<init>", "(J)V");
89+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "xxxx222");
90+
jobject1 = env->NewObject(eglcontextClassLocal, eglcontextConstructor,
91+
reinterpret_cast<jlong>(jlong(10000)));
92+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "333");
93+
}catch (...){
94+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "111--->111");
95+
eglcontextConstructor=env->GetMethodID(eglcontextClassLocal, "<init>", "(I)V");
96+
jobject1 = env->NewObject(eglcontextClassLocal, eglcontextConstructor,
97+
reinterpret_cast<jlong>(jlong(10000)));
98+
}
99+
100+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "222");
101+
102+
103+
104+
__android_log_print(ANDROID_LOG_ERROR, "andymao", "kkkkkkkk");
105+
106+
jint *intArrays = env->GetIntArrayElements(intArrays_, NULL);
107+
108+
fillIntArray(intArrays);
109+
110+
env->ReleaseIntArrayElements(intArrays_, intArrays, 0);
111+
}
112+
113+
61114

app/src/main/cpp/native-lib.h

-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ Java_cookbook_testjni_MainActivity_setFloatArray(
1414
JNIEnv * env,
1515
jobject thiz,
1616
jfloatArray fArray);
17-

app/src/main/java/cookbook/testjni/MainActivity.java

+27-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Bundle;
44
import android.support.v7.app.AppCompatActivity;
55
import android.util.Log;
6+
import android.view.View;
67
import android.widget.TextView;
78

89
public class MainActivity extends AppCompatActivity {
@@ -21,23 +22,41 @@ protected void onCreate(Bundle savedInstanceState) {
2122
TextView tv = (TextView) findViewById(R.id.sample_text);
2223
// tv.setText(stringFromJNI());
2324

24-
float[] floats = new float[]{
25-
12f, 23f, 31f, 14f, 5f
26-
};
2725

2826
// setFloatArray();
2927

30-
float[] outFloats = setFloatArray(floats);
31-
for (int i = 0; i < outFloats.length; i++) {
32-
Log.d("andymao", "" + outFloats[i]);
33-
}
28+
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
29+
@Override
30+
public void onClick(View v) {
31+
// float[] floats = new float[]{
32+
// 12f, 23f, 31f, 14f, 5f
33+
// };
34+
// float[] outFloats = setFloatArray(floats);
35+
// for (int i = 0; i < outFloats.length; i++) {
36+
// Log.d("andymao", "" + outFloats[i]);
37+
// }
38+
39+
int[] intArray = new int[12];
40+
try {
41+
getIntArray(intArray);
42+
} catch (Throwable e) {
43+
e.printStackTrace();
44+
}
45+
46+
for (int i = 0; i < intArray.length; i++) {
47+
Log.d("andymao", intArray[i] + "");
48+
}
49+
}
50+
});
51+
3452
}
3553

3654
/**
3755
* A native method that is implemented by the 'native-lib' native library,
3856
* which is packaged with this application.
3957
*/
4058
// public native String stringFromJNI();
41-
4259
public native float[] setFloatArray(float[] arrInput);
60+
61+
public native void getIntArray(int[] intArrays);
4362
}

app/src/main/res/layout/activity_main.xml

+11
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@
1616
app:layout_constraintRight_toRightOf="parent"
1717
app:layout_constraintTop_toTopOf="parent" />
1818

19+
<Button
20+
android:id="@+id/button"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:layout_marginStart="52dp"
24+
android:layout_marginTop="44dp"
25+
android:text="Button"
26+
app:layout_constraintStart_toStartOf="parent"
27+
app:layout_constraintTop_toTopOf="parent" />
28+
29+
1930
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)