39
39
import android .view .MotionEvent ;
40
40
import android .view .KeyEvent ;
41
41
import android .os .Build ;
42
- import android .os .PowerManager ;
42
+ import android .os .PowerManager ;
43
43
44
44
import java .io .IOException ;
45
45
import java .io .InputStream ;
@@ -263,7 +263,7 @@ private void printConfig(EGL10 egl, EGLDisplay display,
263
263
protected int mStencilSize ;
264
264
private int [] mValue = new int [1 ];
265
265
}
266
-
266
+
267
267
// The activity we're a part of.
268
268
private Activity mActivity ;
269
269
@@ -272,28 +272,22 @@ private void printConfig(EGL10 egl, EGLDisplay display,
272
272
273
273
// Is Python ready to receive input events?
274
274
static boolean mInputActivated = false ;
275
-
276
- // The number of swaps we should skip. Experimentally derived from
277
- // watching SDL initialize.
278
- // XXX Kivy no swap skips, because kivy draw when needed.
279
- // XXX If we lost our first frame, we have a black screen.
280
- private int mSwapSkips = 0 ;
281
275
282
276
// The number of times we should clear the screen after swap.
283
277
private int mClears = 2 ;
284
-
278
+
285
279
// Has the display been changed?
286
280
private boolean mChanged = false ;
287
281
288
282
// Are we running yet?
289
283
private boolean mRunning = false ;
290
-
284
+
291
285
// The EGL used by our thread.
292
286
private EGL10 mEgl = null ;
293
287
294
288
// The EGL Display used.
295
289
private EGLDisplay mEglDisplay = null ;
296
-
290
+
297
291
// The EGL Context used.
298
292
private EGLContext mEglContext = null ;
299
293
@@ -305,7 +299,7 @@ private void printConfig(EGL10 egl, EGLDisplay display,
305
299
306
300
// The user program is not participating in the pause protocol.
307
301
public final int PAUSE_NOT_PARTICIPATING = 0 ;
308
-
302
+
309
303
// A pause has not been requested by the OS.
310
304
public final int PAUSE_NONE = 1 ;
311
305
@@ -320,12 +314,12 @@ private void printConfig(EGL10 egl, EGLDisplay display,
320
314
private int mPause = PAUSE_NOT_PARTICIPATING ;
321
315
322
316
323
- private PowerManager .WakeLock wakeLock ;
324
-
317
+ private PowerManager .WakeLock wakeLock ;
318
+
325
319
// The width and height. (This should be set at startup time -
326
320
// these values just prevent segfaults and divide by zero, etc.)
327
321
int mWidth = 100 ;
328
- int mHeight = 100 ;
322
+ int mHeight = 100 ;
329
323
330
324
// The name of the directory where the context stores its files.
331
325
String mFilesDirectory = null ;
@@ -335,22 +329,22 @@ private void printConfig(EGL10 egl, EGLDisplay display,
335
329
336
330
// The resource manager we use.
337
331
ResourceManager mResourceManager ;
338
-
332
+
339
333
public SDLSurfaceView (Activity act , String argument ) {
340
334
super (act );
341
335
342
336
mActivity = act ;
343
337
mResourceManager = new ResourceManager (act );
344
-
338
+
345
339
SurfaceHolder holder = getHolder ();
346
340
holder .addCallback (this );
347
341
holder .setType (SurfaceHolder .SURFACE_TYPE_GPU );
348
342
349
343
mFilesDirectory = mActivity .getFilesDir ().getAbsolutePath ();
350
344
mArgument = argument ;
351
345
352
- PowerManager pm = (PowerManager ) act .getSystemService (Context .POWER_SERVICE );
353
- wakeLock = pm .newWakeLock (PowerManager .SCREEN_BRIGHT_WAKE_LOCK , "Screen On" );
346
+ PowerManager pm = (PowerManager ) act .getSystemService (Context .POWER_SERVICE );
347
+ wakeLock = pm .newWakeLock (PowerManager .SCREEN_BRIGHT_WAKE_LOCK , "Screen On" );
354
348
}
355
349
356
350
@@ -370,7 +364,7 @@ public int checkPause() {
370
364
return 0 ;
371
365
}
372
366
}
373
-
367
+
374
368
375
369
/**
376
370
* The user program should call this quickly after checkPause
@@ -380,7 +374,7 @@ public int checkPause() {
380
374
*
381
375
* While we're waiting in this method, android is allowed to
382
376
* kill us to reclaim memory, without any further warning.
383
- */
377
+ */
384
378
public void waitForResume () {
385
379
synchronized (this ) {
386
380
mPause = PAUSE_WAIT_FOR_RESUME ;
@@ -396,7 +390,7 @@ public void waitForResume() {
396
390
}
397
391
}
398
392
}
399
-
393
+
400
394
/**
401
395
* Inform the view that the activity is paused. The owner of this view must
402
396
* call this method when the activity is paused. Calling this method will
@@ -405,7 +399,7 @@ public void waitForResume() {
405
399
*/
406
400
public void onPause () {
407
401
408
- synchronized (this ) {
402
+ synchronized (this ) {
409
403
if (mPause == PAUSE_NONE ) {
410
404
mPause = PAUSE_REQUEST ;
411
405
@@ -420,9 +414,9 @@ public void onPause() {
420
414
}
421
415
422
416
wakeLock .release ();
423
-
417
+
424
418
}
425
-
419
+
426
420
/**
427
421
* Inform the view that the activity is resumed. The owner of this view must
428
422
* call this method when the activity is resumed. Calling this method will
@@ -431,10 +425,10 @@ public void onPause() {
431
425
* Must not be called before a renderer has been set.
432
426
*/
433
427
public void onResume () {
434
- synchronized (this ) {
428
+ synchronized (this ) {
435
429
if (mPause == PAUSE_WAIT_FOR_RESUME ) {
436
430
mPause = PAUSE_NONE ;
437
- this .notifyAll ();
431
+ this .notifyAll ();
438
432
}
439
433
}
440
434
@@ -474,7 +468,7 @@ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
474
468
}
475
469
476
470
if (!mRunning ) {
477
- mRunning = true ;
471
+ mRunning = true ;
478
472
new Thread (this ).start ();
479
473
} else {
480
474
mChanged = true ;
@@ -573,9 +567,9 @@ private void glCheck(GL10 gl) {
573
567
int gle = gl .glGetError ();
574
568
if (gle != gl .GL_NO_ERROR ) {
575
569
throw new RuntimeException ("GL Error: " + gle );
576
- }
570
+ }
577
571
}
578
-
572
+
579
573
private void waitForStart () {
580
574
581
575
int presplashId = mResourceManager .getIdentifier ("presplash" , "drawable" );
@@ -708,7 +702,7 @@ private void waitForStart() {
708
702
this .wait (250 );
709
703
} catch (InterruptedException e ) {
710
704
continue ;
711
- }
705
+ }
712
706
}
713
707
}
714
708
@@ -724,22 +718,22 @@ private void waitForStart() {
724
718
GLES20 .glDeleteProgram (mProgram );
725
719
}
726
720
727
-
721
+
728
722
public void start () {
729
723
this .setFocusableInTouchMode (true );
730
724
this .setFocusable (true );
731
- this .requestFocus ();
732
-
733
- synchronized (this ) {
725
+ this .requestFocus ();
726
+
727
+ synchronized (this ) {
734
728
mStarted = true ;
735
729
this .notify ();
736
730
}
737
731
738
732
}
739
-
740
- public boolean createSurface () {
733
+
734
+ public boolean createSurface () {
741
735
mChanged = false ;
742
-
736
+
743
737
// Destroy the old surface.
744
738
if (mEglSurface != null ) {
745
739
@@ -773,12 +767,6 @@ public boolean createSurface() {
773
767
}
774
768
775
769
public int swapBuffers () {
776
-
777
- // Prevent us from drawing too early, at startup.
778
- if (mSwapSkips -- > 0 ) {
779
- return 1 ;
780
- }
781
-
782
770
// If the display has been changed, then disregard all the
783
771
// rendering we've done to it, and make a new surface.
784
772
//
@@ -787,19 +775,15 @@ public int swapBuffers() {
787
775
createSurface ();
788
776
mClears = 2 ;
789
777
return 0 ;
790
-
791
- } else {
792
778
779
+ } else {
793
780
mEgl .eglSwapBuffers (mEglDisplay , mEglSurface );
794
-
795
- if (mClears -- != 0 ) {
781
+ if (mClears -- > 0 )
796
782
GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
797
- }
798
-
799
783
return 1 ;
800
784
}
801
785
802
- }
786
+ }
803
787
804
788
private static final int INVALID_POINTER_ID = -1 ;
805
789
private int mActivePointerId = INVALID_POINTER_ID ;
@@ -855,7 +839,7 @@ public boolean onTouchEvent(final MotionEvent event) {
855
839
if ( pointerIndex == -1 || pointerIndex == i ) {
856
840
857
841
/**
858
- Log.i("python", String.format("mouse id=%d action=%d x=%f y=%f",
842
+ Log.i("python", String.format("mouse id=%d action=%d x=%f y=%f",
859
843
event.getPointerId(i),
860
844
sdlAction,
861
845
event.getX(i),
@@ -874,18 +858,13 @@ public boolean onTouchEvent(final MotionEvent event) {
874
858
}
875
859
876
860
}
877
- synchronized (this ) {
878
- try {
879
- this .wait (1000 / 60 );
880
- } catch (InterruptedException e ) { }
881
- }
882
-
861
+
883
862
return true ;
884
863
};
885
-
864
+
886
865
@ Override
887
866
public boolean onKeyDown (int keyCode , final KeyEvent event ) {
888
- Log .i ("python" , String .format ("key down %d" , keyCode ));
867
+ // Log.i("python", String.format("key down %d", keyCode));
889
868
if (mInputActivated && nativeKey (keyCode , 1 , event .getUnicodeChar ())) {
890
869
return true ;
891
870
} else {
@@ -895,7 +874,7 @@ public boolean onKeyDown(int keyCode, final KeyEvent event) {
895
874
896
875
@ Override
897
876
public boolean onKeyUp (int keyCode , final KeyEvent event ) {
898
- Log .i ("python" , String .format ("key up %d" , keyCode ));
877
+ // Log.i("python", String.format("key up %d", keyCode));
899
878
if (mInputActivated && nativeKey (keyCode , 0 , event .getUnicodeChar ())) {
900
879
return true ;
901
880
} else {
@@ -967,13 +946,13 @@ private void checkGlError(String op) {
967
946
private static final int TRIANGLE_VERTICES_DATA_POS_OFFSET = 0 ;
968
947
private static final int TRIANGLE_VERTICES_DATA_UV_OFFSET = 3 ;
969
948
private final float [] mTriangleVerticesData = {
970
- // X, Y, Z, U, V
971
- -0.5f , -0.5f , 0 , 1.0f , 0.0f ,
972
- 0.5f , -0.5f , 0 , 0.0f , 0.0f ,
973
- 0.5f , 0.5f , 0 , 0.0f , 1.0f ,
974
- -0.5f , -0.5f , 0 , 1.0f , 0.0f ,
975
- 0.5f , 0.5f , 0 , 0.0f , 1.0f ,
976
- -0.5f , 0.5f , 0 , 1.0f , 1.0f ,
949
+ // X, Y, Z, U, V
950
+ -0.5f , -0.5f , 0 , 1.0f , 0.0f ,
951
+ 0.5f , -0.5f , 0 , 0.0f , 0.0f ,
952
+ 0.5f , 0.5f , 0 , 0.0f , 1.0f ,
953
+ -0.5f , -0.5f , 0 , 1.0f , 0.0f ,
954
+ 0.5f , 0.5f , 0 , 0.0f , 1.0f ,
955
+ -0.5f , 0.5f , 0 , 1.0f , 1.0f ,
977
956
};
978
957
979
958
private FloatBuffer mTriangleVertices ;
@@ -997,8 +976,8 @@ private void checkGlError(String op) {
997
976
public static native boolean nativeKey (int keyCode , int down , int unicode );
998
977
public static native void nativeSetMouseUsed ();
999
978
public static native void nativeSetMultitouchUsed ();
1000
-
979
+
1001
980
public native void nativeResize (int width , int height );
1002
981
public native void nativeInitJavaCallbacks ();
1003
-
982
+
1004
983
}
0 commit comments