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

Commit 603f6de3 authored by Chet Haase's avatar Chet Haase
Browse files

Fix occasional crash bug with layers

Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).

When this happens, if the memory got corrupted, it's possible to crash.

The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.

Issue #6994632 Native crash in launcher when trying to launch all apps screen

Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
parent cc5dd18d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ class GLES20Canvas extends HardwareCanvas {
    
    static native int nCreateTextureLayer(boolean opaque, int[] layerInfo);
    static native int nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo);
    static native void nResizeLayer(int layerId, int width, int height, int[] layerInfo);
    static native boolean nResizeLayer(int layerId, int width, int height, int[] layerInfo);
    static native void nSetOpaqueLayer(int layerId, boolean isOpaque);
    static native void nSetLayerPaint(int layerId, int nativePaint);
    static native void nSetLayerColorFilter(int layerId, int nativeColorFilter);
+12 −6
Original line number Diff line number Diff line
@@ -54,8 +54,8 @@ class GLES20RenderLayer extends GLES20Layer {
    }

    @Override
    void resize(int width, int height) {
        if (!isValid() || width <= 0 || height <= 0) return;
    boolean resize(int width, int height) {
        if (!isValid() || width <= 0 || height <= 0) return false;

        mWidth = width;
        mHeight = height;
@@ -63,11 +63,17 @@ class GLES20RenderLayer extends GLES20Layer {
        if (width != mLayerWidth || height != mLayerHeight) {
            int[] layerInfo = new int[2];

            GLES20Canvas.nResizeLayer(mLayer, width, height, layerInfo);

            if (GLES20Canvas.nResizeLayer(mLayer, width, height, layerInfo)) {
                mLayerWidth = layerInfo[0];
                mLayerHeight = layerInfo[1];
            } else {
                // Failure: not enough GPU resources for requested size
                mLayer = 0;
                mLayerWidth = 0;
                mLayerHeight = 0;
            }
        }
        return isValid();
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ class GLES20TextureLayer extends GLES20Layer {
    }

    @Override
    void resize(int width, int height) {
    boolean resize(int width, int height) {
        return isValid();
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -135,8 +135,9 @@ abstract class HardwareLayer {
     * 
     * @param width The new desired minimum width for this layer
     * @param height The new desired minimum height for this layer
     * @return True if the resulting layer is valid, false otherwise
     */
    abstract void resize(int width, int height);
    abstract boolean resize(int width, int height);

    /**
     * Returns a hardware canvas that can be used to render onto
+4 −3
Original line number Diff line number Diff line
@@ -12213,9 +12213,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                mLocalDirtyRect.set(0, 0, width, height);
            } else {
                if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) {
                    mHardwareLayer.resize(width, height);
                    if (mHardwareLayer.resize(width, height)) {
                        mLocalDirtyRect.set(0, 0, width, height);
                    }
                }
                // This should not be necessary but applications that change
                // the parameters of their background drawable without calling
@@ -12225,7 +12226,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                computeOpaqueFlags();
                final boolean opaque = isOpaque();
                if (mHardwareLayer.isOpaque() != opaque) {
                if (mHardwareLayer.isValid() && mHardwareLayer.isOpaque() != opaque) {
                    mHardwareLayer.setOpaque(opaque);
                    mLocalDirtyRect.set(0, 0, width, height);
                }
Loading