Skip to content

Commit 1e88c08

Browse files
committed
remove wait in touch event, fix screen clear and remove skipswap (not used)
1 parent 499db8c commit 1e88c08

File tree

1 file changed

+49
-70
lines changed

1 file changed

+49
-70
lines changed

src/src/org/renpy/android/SDLSurfaceView.java

Lines changed: 49 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import android.view.MotionEvent;
4040
import android.view.KeyEvent;
4141
import android.os.Build;
42-
import android.os.PowerManager;
42+
import android.os.PowerManager;
4343

4444
import java.io.IOException;
4545
import java.io.InputStream;
@@ -263,7 +263,7 @@ private void printConfig(EGL10 egl, EGLDisplay display,
263263
protected int mStencilSize;
264264
private int[] mValue = new int[1];
265265
}
266-
266+
267267
// The activity we're a part of.
268268
private Activity mActivity;
269269

@@ -272,28 +272,22 @@ private void printConfig(EGL10 egl, EGLDisplay display,
272272

273273
// Is Python ready to receive input events?
274274
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;
281275

282276
// The number of times we should clear the screen after swap.
283277
private int mClears = 2;
284-
278+
285279
// Has the display been changed?
286280
private boolean mChanged = false;
287281

288282
// Are we running yet?
289283
private boolean mRunning = false;
290-
284+
291285
// The EGL used by our thread.
292286
private EGL10 mEgl = null;
293287

294288
// The EGL Display used.
295289
private EGLDisplay mEglDisplay = null;
296-
290+
297291
// The EGL Context used.
298292
private EGLContext mEglContext = null;
299293

@@ -305,7 +299,7 @@ private void printConfig(EGL10 egl, EGLDisplay display,
305299

306300
// The user program is not participating in the pause protocol.
307301
public final int PAUSE_NOT_PARTICIPATING = 0;
308-
302+
309303
// A pause has not been requested by the OS.
310304
public final int PAUSE_NONE = 1;
311305

@@ -320,12 +314,12 @@ private void printConfig(EGL10 egl, EGLDisplay display,
320314
private int mPause = PAUSE_NOT_PARTICIPATING;
321315

322316

323-
private PowerManager.WakeLock wakeLock;
324-
317+
private PowerManager.WakeLock wakeLock;
318+
325319
// The width and height. (This should be set at startup time -
326320
// these values just prevent segfaults and divide by zero, etc.)
327321
int mWidth = 100;
328-
int mHeight = 100;
322+
int mHeight = 100;
329323

330324
// The name of the directory where the context stores its files.
331325
String mFilesDirectory = null;
@@ -335,22 +329,22 @@ private void printConfig(EGL10 egl, EGLDisplay display,
335329

336330
// The resource manager we use.
337331
ResourceManager mResourceManager;
338-
332+
339333
public SDLSurfaceView(Activity act, String argument) {
340334
super(act);
341335

342336
mActivity = act;
343337
mResourceManager = new ResourceManager(act);
344-
338+
345339
SurfaceHolder holder = getHolder();
346340
holder.addCallback(this);
347341
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
348342

349343
mFilesDirectory = mActivity.getFilesDir().getAbsolutePath();
350344
mArgument = argument;
351345

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");
354348
}
355349

356350

@@ -370,7 +364,7 @@ public int checkPause() {
370364
return 0;
371365
}
372366
}
373-
367+
374368

375369
/**
376370
* The user program should call this quickly after checkPause
@@ -380,7 +374,7 @@ public int checkPause() {
380374
*
381375
* While we're waiting in this method, android is allowed to
382376
* kill us to reclaim memory, without any further warning.
383-
*/
377+
*/
384378
public void waitForResume() {
385379
synchronized (this) {
386380
mPause = PAUSE_WAIT_FOR_RESUME;
@@ -396,7 +390,7 @@ public void waitForResume() {
396390
}
397391
}
398392
}
399-
393+
400394
/**
401395
* Inform the view that the activity is paused. The owner of this view must
402396
* call this method when the activity is paused. Calling this method will
@@ -405,7 +399,7 @@ public void waitForResume() {
405399
*/
406400
public void onPause() {
407401

408-
synchronized (this) {
402+
synchronized (this) {
409403
if (mPause == PAUSE_NONE) {
410404
mPause = PAUSE_REQUEST;
411405

@@ -420,9 +414,9 @@ public void onPause() {
420414
}
421415

422416
wakeLock.release();
423-
417+
424418
}
425-
419+
426420
/**
427421
* Inform the view that the activity is resumed. The owner of this view must
428422
* call this method when the activity is resumed. Calling this method will
@@ -431,10 +425,10 @@ public void onPause() {
431425
* Must not be called before a renderer has been set.
432426
*/
433427
public void onResume() {
434-
synchronized (this) {
428+
synchronized (this) {
435429
if (mPause == PAUSE_WAIT_FOR_RESUME) {
436430
mPause = PAUSE_NONE;
437-
this.notifyAll();
431+
this.notifyAll();
438432
}
439433
}
440434

@@ -474,7 +468,7 @@ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
474468
}
475469

476470
if (!mRunning) {
477-
mRunning = true;
471+
mRunning = true;
478472
new Thread(this).start();
479473
} else {
480474
mChanged = true;
@@ -573,9 +567,9 @@ private void glCheck(GL10 gl) {
573567
int gle = gl.glGetError();
574568
if (gle != gl.GL_NO_ERROR) {
575569
throw new RuntimeException("GL Error: " + gle);
576-
}
570+
}
577571
}
578-
572+
579573
private void waitForStart() {
580574

581575
int presplashId = mResourceManager.getIdentifier("presplash", "drawable");
@@ -708,7 +702,7 @@ private void waitForStart() {
708702
this.wait(250);
709703
} catch (InterruptedException e) {
710704
continue;
711-
}
705+
}
712706
}
713707
}
714708

@@ -724,22 +718,22 @@ private void waitForStart() {
724718
GLES20.glDeleteProgram(mProgram);
725719
}
726720

727-
721+
728722
public void start() {
729723
this.setFocusableInTouchMode(true);
730724
this.setFocusable(true);
731-
this.requestFocus();
732-
733-
synchronized (this) {
725+
this.requestFocus();
726+
727+
synchronized (this) {
734728
mStarted = true;
735729
this.notify();
736730
}
737731

738732
}
739-
740-
public boolean createSurface() {
733+
734+
public boolean createSurface() {
741735
mChanged = false;
742-
736+
743737
// Destroy the old surface.
744738
if (mEglSurface != null) {
745739

@@ -773,12 +767,6 @@ public boolean createSurface() {
773767
}
774768

775769
public int swapBuffers() {
776-
777-
// Prevent us from drawing too early, at startup.
778-
if (mSwapSkips-- > 0) {
779-
return 1;
780-
}
781-
782770
// If the display has been changed, then disregard all the
783771
// rendering we've done to it, and make a new surface.
784772
//
@@ -787,19 +775,15 @@ public int swapBuffers() {
787775
createSurface();
788776
mClears = 2;
789777
return 0;
790-
791-
} else {
792778

779+
} else {
793780
mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
794-
795-
if (mClears-- != 0) {
781+
if (mClears-- > 0)
796782
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
797-
}
798-
799783
return 1;
800784
}
801785

802-
}
786+
}
803787

804788
private static final int INVALID_POINTER_ID = -1;
805789
private int mActivePointerId = INVALID_POINTER_ID;
@@ -855,7 +839,7 @@ public boolean onTouchEvent(final MotionEvent event) {
855839
if ( pointerIndex == -1 || pointerIndex == i ) {
856840

857841
/**
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",
859843
event.getPointerId(i),
860844
sdlAction,
861845
event.getX(i),
@@ -874,18 +858,13 @@ public boolean onTouchEvent(final MotionEvent event) {
874858
}
875859

876860
}
877-
synchronized (this) {
878-
try {
879-
this.wait(1000 / 60);
880-
} catch (InterruptedException e) { }
881-
}
882-
861+
883862
return true;
884863
};
885-
864+
886865
@Override
887866
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));
889868
if (mInputActivated && nativeKey(keyCode, 1, event.getUnicodeChar())) {
890869
return true;
891870
} else {
@@ -895,7 +874,7 @@ public boolean onKeyDown(int keyCode, final KeyEvent event) {
895874

896875
@Override
897876
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));
899878
if (mInputActivated && nativeKey(keyCode, 0, event.getUnicodeChar())) {
900879
return true;
901880
} else {
@@ -967,13 +946,13 @@ private void checkGlError(String op) {
967946
private static final int TRIANGLE_VERTICES_DATA_POS_OFFSET = 0;
968947
private static final int TRIANGLE_VERTICES_DATA_UV_OFFSET = 3;
969948
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,
977956
};
978957

979958
private FloatBuffer mTriangleVertices;
@@ -997,8 +976,8 @@ private void checkGlError(String op) {
997976
public static native boolean nativeKey(int keyCode, int down, int unicode);
998977
public static native void nativeSetMouseUsed();
999978
public static native void nativeSetMultitouchUsed();
1000-
979+
1001980
public native void nativeResize(int width, int height);
1002981
public native void nativeInitJavaCallbacks();
1003-
982+
1004983
}

0 commit comments

Comments
 (0)