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

Commit 5b6bc36c authored by Shawn Lin's avatar Shawn Lin
Browse files

Reland - Fix flicker when swiching resolution change

After the "Local Layout"[1] is enabled, the client can compute its
layout on its own. If we update cutout in the Display callback(server
side), it would have a timing issue that we draw the cutout(latest from
server) in the old layout(not being updated yet in client) which would
cause flicker.

We should only update cutout in client side callback like configuration
change to make sure it syncs with the current layout attributes in
client side.

For rounded corner part, we don't need to reload drawable everytime the
config is changed. Only size update is needed.

For face unlock animation placed in wrong position, update the rotation
whenever the config is changed.

[1]:If9488ffc84dc5e2af106acfae425a854fb7407a2

Bug: 228284551
Bug: 244693677
Test: 1. Go Settings-> Display-> Screen resolution
      2. Switch between FHD <-> QHD and no flickering
Test: atest ScreenDecorationsTest RoundedCornerResDelegateTest
      DisplayCutoutBaseViewTest
Change-Id: Ia601d126ff7f5de01f4e5e659c62009233a66eb8
parent 26ed84b7
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -86,30 +86,38 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView {
        onUpdate()
    }

    fun onDisplayChanged(newDisplayUniqueId: String?) {
    fun updateConfiguration(newDisplayUniqueId: String?) {
        val info = DisplayInfo()
        context.display?.getDisplayInfo(info)
        val oldMode: Display.Mode? = displayMode
        val display: Display? = context.display
        displayMode = display?.mode
        displayMode = info.mode

        if (displayUniqueId != display?.uniqueId) {
            displayUniqueId = display?.uniqueId
            shouldDrawCutout = DisplayCutout.getFillBuiltInDisplayCutout(
                context.resources, displayUniqueId
            )
        }
        updateDisplayUniqueId(info.uniqueId)

        // Skip if display mode or cutout hasn't changed.
        if (!displayModeChanged(oldMode, displayMode) &&
                display?.cutout == displayInfo.displayCutout) {
                displayInfo.displayCutout == info.displayCutout &&
                displayRotation == info.rotation) {
            return
        }
        if (newDisplayUniqueId == display?.uniqueId) {
        if (newDisplayUniqueId == info.uniqueId) {
            displayRotation = info.rotation
            updateCutout()
            updateProtectionBoundingPath()
            onUpdate()
        }
    }

    open fun updateDisplayUniqueId(newDisplayUniqueId: String?) {
        if (displayUniqueId != newDisplayUniqueId) {
            displayUniqueId = newDisplayUniqueId
            shouldDrawCutout = DisplayCutout.getFillBuiltInDisplayCutout(
                    context.resources, displayUniqueId
            )
            invalidate()
        }
    }

    open fun updateRotation(rotation: Int) {
        displayRotation = rotation
        updateCutout()
+5 −34
Original line number Diff line number Diff line
@@ -455,7 +455,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
                    }
                }

                boolean needToUpdateProviderViews = false;
                final String newUniqueId = mDisplayInfo.uniqueId;
                if (!Objects.equals(newUniqueId, mDisplayUniqueId)) {
                    mDisplayUniqueId = newUniqueId;
@@ -473,37 +472,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
                        setupDecorations();
                        return;
                    }

                    if (mScreenDecorHwcLayer != null) {
                        updateHwLayerRoundedCornerDrawable();
                        updateHwLayerRoundedCornerExistAndSize();
                    }
                    needToUpdateProviderViews = true;
                }

                final float newRatio = getPhysicalPixelDisplaySizeRatio();
                if (mRoundedCornerResDelegate.getPhysicalPixelDisplaySizeRatio() != newRatio) {
                    mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio(newRatio);
                    if (mScreenDecorHwcLayer != null) {
                        updateHwLayerRoundedCornerExistAndSize();
                    }
                    needToUpdateProviderViews = true;
                }

                if (needToUpdateProviderViews) {
                    updateOverlayProviderViews(null);
                } else {
                    updateOverlayProviderViews(new Integer[] {
                            mFaceScanningViewId,
                            R.id.display_cutout,
                            R.id.display_cutout_left,
                            R.id.display_cutout_right,
                            R.id.display_cutout_bottom,
                    });
                }

                if (mScreenDecorHwcLayer != null) {
                    mScreenDecorHwcLayer.onDisplayChanged(newUniqueId);
                }
            }
        };
@@ -1069,9 +1037,11 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
                && (newRotation != mRotation || displayModeChanged(mDisplayMode, newMod))) {
            mRotation = newRotation;
            mDisplayMode = newMod;
            mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio(
                    getPhysicalPixelDisplaySizeRatio());
            if (mScreenDecorHwcLayer != null) {
                mScreenDecorHwcLayer.pendingConfigChange = false;
                mScreenDecorHwcLayer.updateRotation(mRotation);
                mScreenDecorHwcLayer.updateConfiguration(mDisplayUniqueId);
                updateHwLayerRoundedCornerExistAndSize();
                updateHwLayerRoundedCornerDrawable();
            }
@@ -1110,7 +1080,8 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
                context.getResources(), context.getDisplay().getUniqueId());
    }

    private void updateOverlayProviderViews(@Nullable Integer[] filterIds) {
    @VisibleForTesting
    void updateOverlayProviderViews(@Nullable Integer[] filterIds) {
        if (mOverlays == null) {
            return;
        }
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ class CutoutDecorProviderImpl(
        (view as? DisplayCutoutView)?.let { cutoutView ->
            cutoutView.setColor(tintColor)
            cutoutView.updateRotation(rotation)
            cutoutView.onDisplayChanged(displayUniqueId)
            cutoutView.updateConfiguration(displayUniqueId)
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ class FaceScanningOverlayProviderImpl(
            view.layoutParams = it
            (view as? FaceScanningOverlay)?.let { overlay ->
                overlay.setColor(tintColor)
                overlay.onDisplayChanged(displayUniqueId)
                overlay.updateConfiguration(displayUniqueId)
            }
        }
    }
+6 −11
Original line number Diff line number Diff line
@@ -78,23 +78,18 @@ class RoundedCornerResDelegate(
        reloadMeasures()
    }

    private fun reloadAll(newReloadToken: Int) {
        if (reloadToken == newReloadToken) {
            return
        }
        reloadToken = newReloadToken
        reloadRes()
        reloadMeasures()
    }

    fun updateDisplayUniqueId(newDisplayUniqueId: String?, newReloadToken: Int?) {
        if (displayUniqueId != newDisplayUniqueId) {
            displayUniqueId = newDisplayUniqueId
            newReloadToken ?.let { reloadToken = it }
            reloadRes()
            reloadMeasures()
        } else {
            newReloadToken?.let { reloadAll(it) }
        } else if (newReloadToken != null) {
            if (reloadToken == newReloadToken) {
                return
            }
            reloadToken = newReloadToken
            reloadMeasures()
        }
    }

Loading