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

Commit 0249eef3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "fix(edt): Ensure the NavBar background is always dark when EDT is on" into main

parents 2afe72dd aa42c5e6
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -25538,6 +25538,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        renderNode.setTranslationY(mScrollY);
    }
    /**
     * @see RenderNode#setUsageHint(int)
     *
     * @hide
     */
    public void setUsageHint(@RenderNode.UsageHint int usageHint) {
        if (mRenderNode != null) {
            mRenderNode.setUsageHint(usageHint);
        }
    }
    /**
     * Creates a new display list or updates the existing display list for the
     * specified Drawable.
+6 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.RenderNode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
@@ -1190,6 +1191,11 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
                    viewRoot.requestInvalidateRootRenderNode();
                }
            }
            if (android.view.accessibility.Flags.forceInvertColor()
                    && mNavigationColorViewState.view != null) {
                mNavigationColorViewState.view.setUsageHint(
                        RenderNode.USAGE_NAVIGATION_BAR_BACKGROUND);
            }

            boolean statusBarNeedsRightInset = navBarToRightEdge
                    && mNavigationColorViewState.present;
+14 −2
Original line number Diff line number Diff line
@@ -1053,8 +1053,13 @@ public final class RenderNode {
        return nSetHasOverlappingRendering(mNativeRenderNode, hasOverlappingRendering);
    }

    /** @hide */
    @IntDef({USAGE_BACKGROUND})
    /**
     * Note: Constant values should match CanvasTransform.h UsageHint.
     * @hide
     */
    // LINT.IfChange(UsageHint)
    @IntDef({USAGE_UNKNOWN, USAGE_BACKGROUND, USAGE_NAVIGATION_BAR_BACKGROUND})
    // LINT.ThenChange(/libs/hwui/CanvasTransform.h:UsageHint)
    @Retention(RetentionPolicy.SOURCE)
    public @interface UsageHint {
    }
@@ -1073,6 +1078,13 @@ public final class RenderNode {
     */
    public static final int USAGE_BACKGROUND = 1;

    /**
     * Usage is the navigation bar background
     *
     * @hide
     */
    public static final int USAGE_NAVIGATION_BAR_BACKGROUND = 4;

    /**
     * Provides a hint on what this RenderNode's display list content contains. This hint is used
     * for automatic content transforms to improve accessibility or similar.
+5 −1
Original line number Diff line number Diff line
@@ -25,13 +25,17 @@

namespace android::uirenderer {

// LINT.IfChange(UsageHint)
enum class UsageHint {
    // Note: Constant values should match RenderNode.java UsageHint.
    Unknown = 0,
    Background = 1,
    Foreground = 2,
    // Contains foreground (usually text), like a button or chip
    Container = 3
    Container = 3,
    NavigationBarBackground = 4
};
// LINT.ThenChange(/graphics/java/android/graphics/RenderNode.java:UsageHint)

enum class ColorTransform {
    None,
+17 −4
Original line number Diff line number Diff line
@@ -440,10 +440,23 @@ void RenderNode::gatherColorAreasForSubtree(ColorArea& target, bool isModeFull)

void RenderNode::handleForceDark(android::uirenderer::TreeInfo* info) {
    if (CC_UNLIKELY(info && isForceInvertDark(*info))) {
        // TODO(b/391959649): what about apps who have opted in to force dark, but only partially?
        //  will this mess them up? e.g. if they set disableForceDark but only on a few nodes.
        ColorTransform transform;
        if (usageHint() == UsageHint::NavigationBarBackground) {
            // The Navigation Bar background should always be dark, and not inverted to light by the
            // FORCE_INVERT_COLOR_DARK feature, since the Navigation Bar buttons are rendered by a
            // separate process and are always light.
            mDisplayList.updateChildren([&](RenderNode* child) {
                child->setUsageHint(UsageHint::NavigationBarBackground);
            });
            transform = ColorTransform::Dark;
        } else {
            // TODO(b/391959649): what about apps who have opted in to force dark, but only
            //  partially? will this mess them up? e.g. if they set disableForceDark but only
            //  on a few nodes.
            // The app is too bright, captain! Reverse the polarity!
        mDisplayList.applyColorTransform(ColorTransform::Invert);
            transform = ColorTransform::Invert;
        }
        mDisplayList.applyColorTransform(transform);
        return;
    }