diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java index 1c5aa61c7..54fc437b8 100644 --- a/android/core/src/processing/core/PApplet.java +++ b/android/core/src/processing/core/PApplet.java @@ -659,6 +659,13 @@ public class PApplet extends Activity implements PConstants, Runnable { // return surfaceHolder; } + + /** Not official API, not guaranteed to work in the future. */ + public SurfaceView getSurfaceView() { + return surfaceView; + } + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -927,17 +934,6 @@ public class PApplet extends Activity implements PConstants, Runnable { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - /** Holy crap this was an ugly one. Need to fix. */ - public void andresNeedsBetterAPI() { - if (looping) { // This "if" is needed to avoid flickering when looping is disabled. - ((GLSurfaceView) surfaceView).requestRender(); - } - } - - - // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - - /** * Called by the sketch surface view, thought it could conceivably be called * by Android as well. @@ -1933,7 +1929,7 @@ public class PApplet extends Activity implements PConstants, Runnable { // width and height that have been set by surfaceChanged(). // boolean validSize = width != 0 && height != 0; // println("valid size = " + validSize + " (" + width + "x" + height + ")"); - if (g != null && surfaceReady && !paused && (looping || redraw)) { + if (canDraw()) { // if (!g.canDraw()) { // // Don't draw if the renderer is not yet ready. // // (e.g. OpenGL has to wait for a peer to be on screen) @@ -2008,6 +2004,12 @@ public class PApplet extends Activity implements PConstants, Runnable { } + /** Not official API, not guaranteed to work in the future. */ + public boolean canDraw() { + return g != null && surfaceReady && !paused && (looping || redraw); + } + + ////////////////////////////////////////////////////////////// diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index 6d4064e59..9a0655082 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -333,6 +333,9 @@ public class PGL { /** The current opengl context */ public static EGLContext context; + /** The current surface view */ + public static GLSurfaceView glview; + /** The PGraphics object using this interface */ protected PGraphicsOpenGL pg; @@ -452,6 +455,7 @@ public class PGL { protected void initSurface(int antialias) { + glview = (GLSurfaceView)pg.parent.getSurfaceView(); reqNumSamples = qualityToSamples(antialias); fboLayerCreated = false; fboLayerInUse = false; @@ -460,7 +464,7 @@ public class PGL { protected void deleteSurface() { - if (glColorTex != null) { + if (threadIsCurrent() && glColorTex != null) { deleteTextures(2, glColorTex); deleteFramebuffers(1, glColorFbo); deleteFramebuffers(1, glMultiFbo); @@ -469,6 +473,7 @@ public class PGL { deleteRenderbuffers(1, glDepth); deleteRenderbuffers(1, glStencil); } + fboLayerCreated = false; fboLayerInUse = false; firstFrame = true; @@ -821,9 +826,9 @@ public class PGL { if (!fboLayerByDefault) { // The result of this assignment is the following: if the user requested - // at some point the use of the FBO layer, but subsequently didn't do + // at some point the use of the FBO layer, but subsequently didn't // request it again, then the rendering won't use the FBO layer if not - // needed, since it is slower than simple onscreen rendering. + // needed, since it is slower than simple on-screen rendering. FORCE_SCREEN_FBO = false; } } @@ -861,7 +866,9 @@ public class PGL { protected void requestDraw() { - pg.parent.andresNeedsBetterAPI(); + if (pg.initialized && pg.parent.canDraw()) { + glview.requestRender(); + } } diff --git a/android/examples/Demos/Tests/RedrawTest/RedrawTest.pde b/android/examples/Demos/Tests/RedrawTest/RedrawTest.pde index 9a6c4c16c..e88a3af5f 100644 --- a/android/examples/Demos/Tests/RedrawTest/RedrawTest.pde +++ b/android/examples/Demos/Tests/RedrawTest/RedrawTest.pde @@ -1,7 +1,5 @@ -// Issues: doesn't redraw - void setup() { - size(400, 400, P3D); + size(400, 400, P2D); noLoop(); } @@ -11,6 +9,7 @@ void draw() { println("draw"); } -void keyPressed() { +void mousePressed() { redraw(); } + diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 411bd2200..f57731281 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -2207,7 +2207,7 @@ public class PApplet extends Applet //synchronized public void handleDisplay() { public void handleDraw() { debug("handleDraw() " + g + " " + looping + " " + redraw + " valid:" + this.isValid() + " visible:" + this.isVisible()); - if (g != null && (looping || redraw)) { + if (canDraw()) { if (!g.canDraw()) { debug("g.canDraw() is false"); // Don't draw if the renderer is not yet ready. @@ -2311,6 +2311,12 @@ public class PApplet extends Applet } + /** Not official API, not guaranteed to work in the future. */ + public boolean canDraw() { + return g != null && (looping || redraw); + } + + ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 3bb1c088d..9b85d414d 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -1189,7 +1189,7 @@ public class PGL { protected void requestDraw() { - if (pg.initialized) { + if (pg.initialized && pg.parent.canDraw()) { try { if (toolkit == AWT) { canvasAWT.display();