1. Fix b/
5392171 by moving effect context creation into Filter to make
sure it'd be created when needed.
2. Revise the fix for b/
5389281 by clearing surface background even
there's no photo.
Change-Id: I212a552291c7df28b75a909bf6560634ba061e9f
@Override
public void run() {
Filter.releaseContext();
+ // Textures will be automatically deleted when GL context is lost.
+ photoView.setPhoto(null, false);
+ source = null;
for (int i = 0; i < buffers.length; i++) {
- // Textures will be automatically deleted when GL context is lost.
buffers[i] = null;
}
}
public void onResume() {
photoView.onResume();
- photoView.queue(new Runnable() {
-
- @Override
- public void run() {
- // Create effect context after GL context is created or recreated.
- Filter.createContextWithCurrentGlContext();
- }
- });
paused = false;
}
}
if (!queue.isEmpty()) {
requestRender();
}
+ RendererUtils.renderBackground();
if (photo != null) {
RendererUtils.renderTexture(renderContext, photo.texture(), viewWidth, viewHeight);
}
context.posVertices = createVerticesBuffer(vertices);
}
+ public static void renderBackground() {
+ GLES20.glClearColor(0, 0, 0, 1);
+ GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
+ }
+
public static void renderTexture(
RenderContext context, int texture, int viewWidth, int viewHeight) {
// Use our shader program
GLES20.glUniform1i(context.texSamplerHandle, 0);
// Draw!
- GLES20.glClearColor(0, 0, 0, 1);
- GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
private boolean isValid;
- public static void createContextWithCurrentGlContext() {
- context = EffectContext.createWithCurrentGlContext();
- }
-
+ /**
+ * Filter context should be released before the current GL context is lost.
+ */
public static void releaseContext() {
if (context != null) {
// Release all effects created with the releasing context.
protected Effect getEffect(String name) {
Effect effect = effects.get(this);
if (effect == null) {
+ if (context == null) {
+ context = EffectContext.createWithCurrentGlContext();
+ }
effect = context.getFactory().createEffect(name);
effect.setParameter("tile_size", DEFAULT_TILE_SIZE);
effects.put(this, effect);