static <L, E extends Input.Impl> void tryInteract (AbstractLayer layer, Class<L> listenerType, Interaction<L, E> interaction, E event) { try { layer.interact(listenerType, interaction, event); } catch (Throwable t) { PlayN.reportError("Interaction failure [layer=" + layer + ", iact=" + interaction + ", event=" + event + "]", t); } }
@Override public void onSurfaceLost() { try { AndroidGLContext actx = (AndroidGLContext) ctx; bindFramebuffer(); ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4); actx.gl.glReadPixels(0, 0, texWidth, texHeight, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer); actx.checkGLError("glReadPixels"); try { cachedPixels = new File(cacheDir, "surface-" + Integer.toHexString(hashCode())); FileOutputStream out = new FileOutputStream(cachedPixels); out.write(pixelBuffer.array()); out.close(); } catch (IOException e) { PlayN.reportError("IOException writing cached Surface to file.", e); cachedPixels = null; } pixelBuffer = null; } catch (OutOfMemoryError e) { PlayN.reportError("OutOfMemoryError reading cached Surface to buffer.", e); cachedPixels = null; } clearTexture(); } }
@Override public void onSurfaceLost() { try { AndroidGLContext actx = (AndroidGLContext) ctx; bindFramebuffer(); ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4); actx.gl.glReadPixels(0, 0, texWidth, texHeight, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer); actx.checkGLError("glReadPixels"); try { cachedPixels = new File(cacheDir, "surface-" + Integer.toHexString(hashCode())); FileOutputStream out = new FileOutputStream(cachedPixels); out.write(pixelBuffer.array()); out.close(); } catch (IOException e) { PlayN.reportError("IOException writing cached Surface to file.", e); cachedPixels = null; } pixelBuffer = null; } catch (OutOfMemoryError e) { PlayN.reportError("OutOfMemoryError reading cached Surface to buffer.", e); cachedPixels = null; } clearTexture(); } }
@Override public void onSurfaceCreated() { createTexture(); if (cachedPixels != null) { try { AndroidGLContext actx = (AndroidGLContext) ctx; ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4); FileInputStream in = new FileInputStream(cachedPixels); in.read(pixelBuffer.array()); in.close(); int bufferTex = actx.createTexture(false, false, false); actx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, texWidth, texHeight, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer); // bind our surface framebuffer and render the saved texture data into it bindFramebuffer(); ctx.quadShader(null).prepareTexture(bufferTex, Tint.NOOP_TINT).addQuad( StockInternalTransform.IDENTITY, 0, texHeight, texWidth, 0, 0, 0, 1, 1); // rebind the default frame buffer (which will flush the rendering operation) ctx.bindFramebuffer(); ctx.destroyTexture(bufferTex); pixelBuffer = null; cachedPixels.delete(); cachedPixels = null; } catch (IOException e) { PlayN.reportError("Error reading cached surface pixels from file.", e); } } }
@Override public void onSurfaceCreated() { createTexture(); if (cachedPixels != null) { try { AndroidGLContext actx = (AndroidGLContext) ctx; ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4); FileInputStream in = new FileInputStream(cachedPixels); in.read(pixelBuffer.array()); in.close(); int bufferTex = actx.createTexture(false, false, false); actx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, texWidth, texHeight, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer); // bind our surface framebuffer and render the saved texture data into it bindFramebuffer(); ctx.quadShader(null).prepareTexture(bufferTex, Tint.NOOP_TINT).addQuad( StockInternalTransform.IDENTITY, 0, texHeight, texWidth, 0, 0, 0, 1, 1); // rebind the default frame buffer (which will flush the rendering operation) ctx.bindFramebuffer(); ctx.destroyTexture(bufferTex); pixelBuffer = null; cachedPixels.delete(); cachedPixels = null; } catch (IOException e) { PlayN.reportError("Error reading cached surface pixels from file.", e); } } }