Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb83d83d authored by Yuli Huang's avatar Yuli Huang
Browse files

Fix b/5392171 and b/5389281.

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
parent 26f894d2
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -238,8 +238,10 @@ public class FilterStack {
            @Override
            public void run() {
                Filter.releaseContext();
                for (int i = 0; i < buffers.length; i++) {
                // Textures will be automatically deleted when GL context is lost.
                photoView.setPhoto(null, false);
                source = null;
                for (int i = 0; i < buffers.length; i++) {
                    buffers[i] = null;
                }
            }
@@ -249,14 +251,6 @@ public class FilterStack {

    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;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public class PhotoView extends GLSurfaceView {
            if (!queue.isEmpty()) {
                requestRender();
            }
            RendererUtils.renderBackground();
            if (photo != null) {
                RendererUtils.renderTexture(renderContext, photo.texture(), viewWidth, viewHeight);
            }
+5 −2
Original line number Diff line number Diff line
@@ -174,6 +174,11 @@ public class RendererUtils {
        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
@@ -204,8 +209,6 @@ public class RendererUtils {
        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);
    }

+6 −4
Original line number Diff line number Diff line
@@ -37,10 +37,9 @@ public abstract class Filter {

    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.
@@ -63,6 +62,9 @@ public abstract class Filter {
    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);