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

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

Merge changes from topic "forcedark-colorarea-detection" into main

* changes:
  feat(force invert): also count areas of draw calls with Bitmap palettes
  feat(force invert): force invert the entire app if its polarity is light
  feat(force invert): detect the polarity of an app to decide if we should force invert it
parents a4922536 a546631b
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -136,10 +136,10 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK
import static com.android.text.flags.Flags.disableHandwritingInitiatorForIme;
import static com.android.window.flags.Flags.enableBufferTransformHintFromDisplay;
import static com.android.window.flags.Flags.enableWindowContextResourcesUpdateOnConfigChange;
import static com.android.window.flags.Flags.fixViewRootCallTrace;
import static com.android.window.flags.Flags.predictiveBackSwipeEdgeNoneApi;
import static com.android.window.flags.Flags.reduceChangedExclusionRectsMsgs;
import static com.android.window.flags.Flags.setScPropertiesInClient;
import static com.android.window.flags.Flags.fixViewRootCallTrace;
import android.Manifest;
import android.accessibilityservice.AccessibilityService;
@@ -191,7 +191,6 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.RenderNode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.hardware.SyncFence;
@@ -295,7 +294,6 @@ import com.android.internal.os.SomeArgs;
import com.android.internal.policy.DecorView;
import com.android.internal.policy.PhoneFallbackEventHandler;
import com.android.internal.protolog.ProtoLog;
import com.android.internal.util.ContrastColorUtil;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.view.BaseSurfaceHolder;
import com.android.internal.view.RootViewSurfaceTaker;
@@ -2089,21 +2087,12 @@ public final class ViewRootImpl implements ViewParent,
                // preference for dark mode in configuration.uiMode. Instead, we assume that both
                // force invert and the system's dark theme are enabled.
                if (shouldApplyForceInvertDark()) {
                    // TODO: b/368725782 - Use hwui color area detection instead of / in
                    //  addition to these heuristics.
                    // We will use HWUI color area detection to determine if it should actually be
                    // inverted. Checking light theme simply gives the developer a way to "opt-out"
                    // of force invert.
                    final boolean isLightTheme =
                            a.getBoolean(R.styleable.Theme_isLightTheme, false);
                    final boolean isBackgroundColorLight;
                    if (mView != null && mView.getBackground()
                            instanceof ColorDrawable colorDrawable) {
                        isBackgroundColorLight =
                                !ContrastColorUtil.isColorDarkLab(colorDrawable.getColor());
                    } else {
                        // Treat unknown as light, so that only isLightTheme is used to determine
                        // force dark treatment.
                        isBackgroundColorLight = true;
                    }
                    if (isLightTheme && isBackgroundColorLight) {
                    if (isLightTheme) {
                        return ForceDarkType.FORCE_INVERT_COLOR_DARK;
                    } else {
                        return ForceDarkType.NONE;
+3 −2
Original line number Diff line number Diff line
@@ -1548,7 +1548,7 @@ public class ViewRootImplTest {

    @Test
    @EnableFlags(FLAG_FORCE_INVERT_COLOR)
    public void determineForceDarkType_isLightThemeAndNotLightBackground_returnsNone()
    public void determineForceDarkType_isLightThemeAndNotLightBackground_returnsForceInvertColorDark()
            throws Exception {
        // Set up configurations for force invert color
        waitForSystemNightModeActivated(true);
@@ -1557,7 +1557,8 @@ public class ViewRootImplTest {
        setUpViewAttributes(/* isLightTheme= */ true, /* isLightBackground = */ false);

        TestUtils.waitUntil("Waiting for ForceDarkType to be ready",
                () -> (mViewRootImpl.determineForceDarkType() == ForceDarkType.NONE));
                () -> (mViewRootImpl.determineForceDarkType()
                        == ForceDarkType.FORCE_INVERT_COLOR_DARK));
    }

    @Test
+1 −0
Original line number Diff line number Diff line
@@ -616,6 +616,7 @@ cc_defaults {
        "Animator.cpp",
        "AnimatorManager.cpp",
        "CanvasTransform.cpp",
        "ColorArea.cpp",
        "DamageAccumulator.cpp",
        "DeviceInfo.cpp",
        "FrameInfo.cpp",
+1 −1
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ static BitmapPalette paletteForColorHSV(SkColor color) {
    return hsv[2] >= .5f ? BitmapPalette::Light : BitmapPalette::Dark;
}

static BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) {
BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) {
    if (palette == BitmapPalette::Unknown || !paint || !paint->getColorFilter()) {
        return palette;
    }
+3 −0
Original line number Diff line number Diff line
@@ -48,4 +48,7 @@ bool transformPaint(ColorTransform transform, SkPaint* paint, BitmapPalette pale
SkColor transformColor(ColorTransform transform, SkColor color);
SkColor transformColorInverse(ColorTransform transform, SkColor color);

/** Returns a palette corrected in case it is tinted by the given paint's filter */
BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette);

}  // namespace android::uirenderer
Loading