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

Commit dcd164c2 authored by Tyler Freeman's avatar Tyler Freeman
Browse files

fix(high contrast text): fix grey text sometimes getting lighter when it...

fix(high contrast text): fix grey text sometimes getting lighter when it should get darker and vice-versa

Use perceptual luminance instead of RGB heuristic to decide to lighten
or darken.

Bug: 186567103
Test: manual
1. adb shell setenforce 0 && adb shell setprop persist.device_config.aconfig_flags.accessibility.com.android.graphics.hwui.flags.high_contrast_text_luminance true && adb shell stop && adb shell start

Change-Id: Ief7ae6c10e1043694ffc10b1d827ebeaada61131
parent 6b061bbd
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ aconfig_declarations {

cc_aconfig_library {
    name: "hwui_flags_cc_lib",
    host_supported: true,
    aconfig_declarations: "hwui_flags",
}

@@ -117,12 +118,15 @@ cc_defaults {
        "libbase",
        "libharfbuzz_ng",
        "libminikin",
        "server_configurable_flags",
    ],

    static_libs: [
        "libui-types",
    ],

    whole_static_libs: ["hwui_flags_cc_lib"],

    target: {
        android: {
            shared_libs: [
@@ -154,7 +158,6 @@ cc_defaults {
                "libstatspull_lazy",
                "libstatssocket_lazy",
                "libtonemap",
                "hwui_flags_cc_lib",
            ],
        },
        host: {
+7 −0
Original line number Diff line number Diff line
@@ -14,6 +14,13 @@ flag {
  bug: "234181960"
}

flag {
  name: "high_contrast_text_luminance"
  namespace: "accessibility"
  description: "Use luminance to determine how to make text more high contrast, instead of RGB heuristic"
  bug: "186567103"
}

flag {
  name: "hdr_10bit_plus"
  namespace: "core_graphics"
+12 −2
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

#include <SkFontMetrics.h>
#include <SkRRect.h>
#include <com_android_graphics_hwui_flags.h>

#include "../utils/Color.h"
#include "Canvas.h"
#include "FeatureFlags.h"
#include "MinikinUtils.h"
@@ -27,6 +29,8 @@
#include "hwui/PaintFilter.h"
#include "pipeline/skia/SkiaRecordingCanvas.h"

namespace flags = com::android::graphics::hwui::flags;

namespace android {

static inline void drawStroke(SkScalar left, SkScalar right, SkScalar top, SkScalar thickness,
@@ -73,8 +77,14 @@ public:
        if (CC_UNLIKELY(canvas->isHighContrastText() && paint.getAlpha() != 0)) {
            // high contrast draw path
            int color = paint.getColor();
            bool darken;
            if (flags::high_contrast_text_luminance()) {
                uirenderer::Lab lab = uirenderer::sRGBToLab(color);
                darken = lab.L <= 50;
            } else {
                int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
            bool darken = channelSum < (128 * 3);
                darken = channelSum < (128 * 3);
            }

            // outline
            gDrawTextBlobMode = DrawTextBlobMode::HctOutline;