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

Commit d6cd572d authored by Romain Guy's avatar Romain Guy
Browse files

Improve hardware layers rendering speed when setting a View's alpha.

Change-Id: Ib1275677f531c60d9919978c5538c663fdb823b5
parent 73fddbae
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -7905,7 +7905,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
                    + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE");
        }
        
        if (layerType == mLayerType) return;
        if (layerType == mLayerType) {
            if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) {
                mLayerPaint = paint == null ? new Paint() : paint;
                if (mParent instanceof ViewGroup) {
                    ((ViewGroup) mParent).invalidate();
                }
                invalidate();
            }
            return;
        }

        // Destroy any previous software drawing cache if needed
        switch (mLayerType) {
@@ -7931,9 +7940,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
        }

        mLayerType = layerType;
        mLayerPaint = mLayerType == LAYER_TYPE_NONE ? null : paint;
        mLayerPaint = mLayerType == LAYER_TYPE_NONE ? null : (paint == null ? new Paint() : paint);

        // TODO: Make sure we invalidate the parent's display list
        if (mParent instanceof ViewGroup) {
            ((ViewGroup) mParent).invalidate();
        }
        invalidate();
    }

+5 −8
Original line number Diff line number Diff line
@@ -2398,16 +2398,15 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                                layerType != LAYER_TYPE_NONE) {
                            layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG;
                        }
                        if (layerType != LAYER_TYPE_NONE && child.mLayerPaint != null) {
                        if (layerType != LAYER_TYPE_NONE) {
                            child.mLayerPaint.setAlpha(multipliedAlpha);
                        } else {
                            canvas.saveLayerAlpha(sx, sy, sx + cr - cl, sy + cb - ct,
                                    multipliedAlpha, layerFlags);
                            layerSaved = true;
                        }
                    } else {
                        // Alpha is handled by the child directly, clobber the layer's alpha
                        if (layerType != LAYER_TYPE_NONE && child.mLayerPaint != null) {
                        if (layerType != LAYER_TYPE_NONE) {
                            child.mLayerPaint.setAlpha(255);
                        }
                        child.mPrivateFlags |= ALPHA_SET;
@@ -2433,7 +2432,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

        if (hasNoCache) {
            boolean layerRendered = false;
            if (!layerSaved && layerType == LAYER_TYPE_HARDWARE) {
            if (layerType == LAYER_TYPE_HARDWARE) {
                final HardwareLayer layer = child.getHardwareLayer(canvas);
                if (layer != null && layer.isValid()) {
                    ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, child.mLayerPaint);
@@ -2465,7 +2464,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            child.mPrivateFlags &= ~DIRTY_MASK;
            Paint cachePaint;

            if (layerType == LAYER_TYPE_NONE || child.mLayerPaint == null) {
            if (layerType == LAYER_TYPE_NONE) {
                cachePaint = mCachePaint;
                if (alpha < 1.0f) {
                    cachePaint.setAlpha((int) (alpha * 255));
@@ -2476,10 +2475,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                }
            } else {
                cachePaint = child.mLayerPaint;
                if (alpha < 1.0f) {
                cachePaint.setAlpha((int) (alpha * 255));
            }
            }
            canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint);
        }

+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ public class ViewLayersActivity2 extends Activity {
        setupList(R.id.list1);
        setupList(R.id.list2);
        setupList(R.id.list3);
        
        findViewById(R.id.list1).setAlpha(0.7f);
    }

    private void setupList(int listId) {