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

Commit 27ff9ce6 authored by Tyler Freeman's avatar Tyler Freeman Committed by Android (Google) Code Review
Browse files

Merge "fix(force invert): fix white-on-white text when text is drawn against a...

Merge "fix(force invert): fix white-on-white text when text is drawn against a fill rect in the same RenderNode" into main
parents 9d7fb5e7 e0faa69a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -80,6 +80,19 @@ SkColor transformColorInverse(ColorTransform transform, SkColor color) {
static void applyColorTransform(ColorTransform transform, SkPaint& paint) {
    if (transform == ColorTransform::None) return;

    if (transform == ColorTransform::Invert) {
        auto filter = SkHighContrastFilter::Make(
                {/* grayscale= */ false, SkHighContrastConfig::InvertStyle::kInvertLightness,
                 /* contrast= */ 0.0f});

        if (paint.getColorFilter()) {
            paint.setColorFilter(SkColorFilters::Compose(filter, paint.refColorFilter()));
        } else {
            paint.setColorFilter(filter);
        }
        return;
    }

    SkColor newColor = transformColor(transform, paint.getColor());
    paint.setColor(newColor);

+3 −0
Original line number Diff line number Diff line
@@ -29,12 +29,15 @@ enum class UsageHint {
    Unknown = 0,
    Background = 1,
    Foreground = 2,
    // Contains foreground (usually text), like a button or chip
    Container = 3
};

enum class ColorTransform {
    None,
    Light,
    Dark,
    Invert
};

// True if the paint was modified, false otherwise
+2 −0
Original line number Diff line number Diff line
@@ -145,6 +145,8 @@ public:
        return mImpl && mImpl->hasText();
    }

    [[nodiscard]] bool hasFill() const { return mImpl && mImpl->hasFill(); }

    void applyColorTransform(ColorTransform transform) {
        if (mImpl) {
            mImpl->applyColorTransform(transform);
+29 −0
Original line number Diff line number Diff line
@@ -718,6 +718,27 @@ static constexpr inline bool is_power_of_two(int value) {
    return (value & (value - 1)) == 0;
}

template <typename T>
constexpr bool doesPaintHaveFill(T& paint) {
    using T1 = std::remove_cv_t<T>;
    if constexpr (std::is_same_v<T1, SkPaint>) {
        return paint.getStyle() != SkPaint::Style::kStroke_Style;
    } else if constexpr (std::is_same_v<T1, SkPaint&>) {
        return paint.getStyle() != SkPaint::Style::kStroke_Style;
    } else if constexpr (std::is_same_v<T1, SkPaint*>) {
        return paint && paint->getStyle() != SkPaint::Style::kStroke_Style;
    } else if constexpr (std::is_same_v<T1, const SkPaint*>) {
        return paint && paint->getStyle() != SkPaint::Style::kStroke_Style;
    }

    return false;
}

template <typename... Args>
constexpr bool hasPaintWithFill(Args&&... args) {
    return (... || doesPaintHaveFill(args));
}

template <typename T, typename... Args>
void* DisplayListData::push(size_t pod, Args&&... args) {
    size_t skip = SkAlignPtr(sizeof(T) + pod);
@@ -736,6 +757,14 @@ void* DisplayListData::push(size_t pod, Args&&... args) {
    new (op) T{std::forward<Args>(args)...};
    op->type = (uint32_t)T::kType;
    op->skip = skip;

    // check if this is a fill op or not, in case we need to avoid messing with it with force invert
    if constexpr (!std::is_same_v<T, DrawTextBlob>) {
        if (hasPaintWithFill(args...)) {
            mHasFill = true;
        }
    }

    return op + 1;
}

+3 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ class RecordingCanvas;

class DisplayListData final {
public:
    DisplayListData() : mHasText(false) {}
    DisplayListData() : mHasText(false), mHasFill(false) {}
    ~DisplayListData();

    void draw(SkCanvas* canvas) const;
@@ -121,6 +121,7 @@ public:
    void applyColorTransform(ColorTransform transform);

    bool hasText() const { return mHasText; }
    bool hasFill() const { return mHasFill; }
    size_t usedSize() const { return fUsed; }
    size_t allocatedSize() const { return fReserved; }

@@ -192,6 +193,7 @@ private:
    size_t fReserved = 0;

    bool mHasText : 1;
    bool mHasFill : 1;
};

class RecordingCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
Loading