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

Commit 5387341d authored by Saurabh Shah's avatar Saurabh Shah Committed by Steve Kondik
Browse files

frameworks/base: Add support for fully transparent layers

Allow apps to specify a window to be fully transparent. This hint
can be used later by the compositor to drop the layer.

Change-Id: Ib58f1026e74ca39e7160d2adcb34ebf50ec28a9a
parent 06f2cac3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -199,6 +199,11 @@ public class SurfaceControl {
     */
    private static final int SURFACE_OPAQUE = 0x02;

    /**
     * Surface flag: Fully transparent, drop in composition if possible
     * @hide
     */
    private static final int SURFACE_TRANSPARENT = 0x80;

    /* built-in physical display ids (keep in sync with ISurfaceComposer.h)
     * these are different from the logical display ids used elsewhere in the framework */
@@ -388,6 +393,16 @@ public class SurfaceControl {
        nativeSetFlags(mNativeObject, 0, SURFACE_HIDDEN);
    }

    public void setTransparent(boolean isTransparent) {
        checkNotReleased();
        if(isTransparent) {
            nativeSetFlags(mNativeObject, SURFACE_TRANSPARENT,
                    SURFACE_TRANSPARENT);
        } else {
            nativeSetFlags(mNativeObject, 0, SURFACE_TRANSPARENT);
        }
    }

    public void setTransparentRegionHint(Region region) {
        checkNotReleased();
        nativeSetTransparentRegionHint(mNativeObject, region);
+5 −0
Original line number Diff line number Diff line
@@ -779,6 +779,11 @@ public abstract class Window {
        setFlags(0, flags);
    }

    /** @hide */
    public void clearPrivateFlags(int flags) {
        setPrivateFlags(0, flags);
    }

    /**
     * Set the flags of the window, as per the
     * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
+4 −0
Original line number Diff line number Diff line
@@ -1115,6 +1115,10 @@ public interface WindowManager extends ViewManager {
         */
        public static final int PRIVATE_FLAG_KEYGUARD = 0x00000400;

        /** Window flag: mark layer as fully transparent
         * {@hide} */
        public static final int PRIVATE_FLAG_FULLY_TRANSPARENT = 0x10000000;

        /**
         * Control flags that are private to the platform.
         * @hide
+8 −0
Original line number Diff line number Diff line
@@ -9430,6 +9430,12 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    private void handlePrivateFlagFullyTransparent(WindowState w) {
        final WindowManager.LayoutParams attrs = w.mAttrs;
        final WindowStateAnimator winAnimator = w.mWinAnimator;
        winAnimator.updateFullyTransparent(attrs);
    }

    private void updateAllDrawnLocked(DisplayContent displayContent) {
        // See if any windows have been drawn, so they (and others
        // associated with them) can now be shown.
@@ -9631,6 +9637,8 @@ public class WindowManagerService extends IWindowManager.Stub
                        handleFlagDimBehind(w);
                    }

                    handlePrivateFlagFullyTransparent(w);

                    if (isDefaultDisplay && obscuredChanged && (mWallpaperTarget == w)
                            && w.isVisibleLw()) {
                        // This is the wallpaper target and its obscured state
+17 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ class WindowStateAnimator {
    boolean mWasAnimating;      // Were we animating going into the most recent animation step?
    int mAnimLayer;
    int mLastLayer;
    boolean mFullyTransparent; //Last value of transparency setting

    SurfaceControl mSurfaceControl;
    SurfaceControl mPendingDestroySurface;
@@ -1901,4 +1902,20 @@ class WindowStateAnimator {
        sb.append('}');
        return sb.toString();
    }

    void updateFullyTransparent(WindowManager.LayoutParams attrs) {
        final boolean fullyTransparent = (attrs.privateFlags &
                WindowManager.LayoutParams.PRIVATE_FLAG_FULLY_TRANSPARENT) != 0;
        if (fullyTransparent == mFullyTransparent) return;
        if (mSurfaceControl == null) return;
        SurfaceControl.openTransaction();
        try {
            mSurfaceControl.setTransparent(fullyTransparent);
        } catch (RuntimeException e) {
            Slog.w(TAG, "Error toggling transparency. ", e);
        } finally {
            SurfaceControl.closeTransaction();
            mFullyTransparent = fullyTransparent;
        }
    }
}