public static DialogResult Show(string text) { if (!Disable) { var gameRunner = GameRunner.Singleton; var activity = gameRunner.Activity; if (gameRunner.InModal || activity == null || android.os.Looper.getMainLooper().getThread() == java.lang.Thread.currentThread()) { GameRunner.Log(text); } else { gameRunner.PauseGame(true); var waitObj = new android.os.ConditionVariable(); Show(activity, text, (_) => waitObj.open()); waitObj.block(); gameRunner.ResumeGame(true); } } return(DialogResult.OK); }
// // CanResume // public static bool CanResume(android.app.Activity activity) { foreach (var renderer in GetRenderersForActivity(activity)) { if (renderer.paused.get() != 0) { // we cannot use waitObject for resuming, because the surface // may have been destroyed between pause and resume, in which // case onDrawFrame would not get called. var cond = new android.os.ConditionVariable(); renderer.surface.queueEvent(((java.lang.Runnable.Delegate)( () => cond.open())).AsInterface()); renderer.surface.onResume(); if (!cond.block(2000)) { // something is wrong if the queued event did not run return(false); } if (!renderer.paused.compareAndSet(1, 0)) { // cannot resume because we lost the GL context, // see also PauseRenderers and onSurfaceCreated return(false); } } } return(true); }
// // constructor // private Renderer(android.app.Activity activity, Action onChanged, int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize, int swapInterval, bool checkErrors) { waitObject = new android.os.ConditionVariable(); paused = new java.util.concurrent.atomic.AtomicInteger(); actionOnChanged = onChanged; this.swapInterval = swapInterval; this.checkErrors = checkErrors; activity.runOnUiThread(((java.lang.Runnable.Delegate)(() => { surface = new android.opengl.GLSurfaceView(activity); surface.setEGLContextClientVersion(3); // OpenGL ES 3.0 surface.setEGLConfigChooser(redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize); surface.setPreserveEGLContextOnPause(true); surface.setRenderer(this); surface.setRenderMode(android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY); activity.setContentView(surface); })).AsInterface()); // wait for one onDrawFrame callback, which tells us that // GLSurfaceView finished initializing the GL context if (!waitObject.block(8000)) { throw new NoSuitableGraphicsDeviceException("cannot create GLSurfaceView"); } var clientBounds = GameRunner.Singleton.ClientBounds; if (SurfaceWidth != clientBounds.Width || SurfaceHeight != clientBounds.Height) { // while not common, it is possible for the screen to rotate, // between the time the Window/GameRunner is created, and the // time the renderer is created. we want to identify this. if (actionOnChanged != null) { actionOnChanged(); } } }