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

Commit 5d882534 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Revert "feat(force invert): also count areas of draw calls with ..."

Revert submission 30679429-forcedark-colorarea-detection

Reason for revert: Triggered a performance regression

Bug: 410295655

Reverted changes: /q/submissionid:30679429-forcedark-colorarea-detection

Change-Id: I955b628a8a4e1421decc0de1c5073de509f743b6
parent a546631b
Loading
Loading
Loading
Loading
+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;
}

BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) {
static BitmapPalette filterPalette(const SkPaint* paint, BitmapPalette palette) {
    if (palette == BitmapPalette::Unknown || !paint || !paint->getColorFilter()) {
        return palette;
    }
+0 −3
Original line number Diff line number Diff line
@@ -48,7 +48,4 @@ 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
+5 −27
Original line number Diff line number Diff line
@@ -16,27 +16,23 @@

#include "ColorArea.h"

#include "CanvasTransform.h"
#include "utils/MathUtils.h"

namespace android::uirenderer {

constexpr static int kMinimumAlphaToConsiderArea = 200;

inline uint64_t calculateArea(int32_t width, int32_t height) {
    // HWUI doesn't draw anything with negative width or height
    if (width <= 0 || height <= 0) return 0;

    return width * height;
}

void ColorArea::addArea(const SkRect& rect, const SkPaint* paint) {
    addArea(rect.width(), rect.height(), paint);
}

void ColorArea::addArea(int32_t width, int32_t height, const SkPaint* paint) {
    if (!paint) return;
    addArea(calculateArea(width, height), *paint);
    // HWUI doesn't draw anything with negative width or height
    if (width <= 0 || height <= 0) return;

    uint64_t area = width * height;
    addArea(area, *paint);
}

void ColorArea::addArea(uint64_t area, const SkPaint& paint) {
@@ -52,24 +48,6 @@ void ColorArea::addArea(uint64_t area, const SkPaint& paint) {
    addArea(area, paint.getColor());
}

void ColorArea::addArea(const SkRect& bounds, const SkPaint& paint,
                        android::BitmapPalette palette) {
    palette = filterPalette(&paint, palette);
    auto area = calculateArea(bounds.width(), bounds.height());
    switch (palette) {
        case android::BitmapPalette::Light:
            addArea(area, Light);
            break;
        case android::BitmapPalette::Dark:
            addArea(area, Dark);
            break;
        case android::BitmapPalette::Colorful:
        case android::BitmapPalette::Unknown:
            addArea(area, Unknown);
            break;
    }
}

void ColorArea::addArea(uint64_t area, SkColor color) {
    if (CC_UNLIKELY(SkColorGetA(color) < kMinimumAlphaToConsiderArea)) return;

+0 −6
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#include <SkCanvas.h>
#include <SkPaintFilterCanvas.h>

#include "hwui/Bitmap.h"
#include "utils/Color.h"
#include "utils/Macros.h"

@@ -69,11 +68,6 @@ public:
    /**
     * See [addArea(uint64_t, SkPaint&)]
     */
    void addArea(const SkRect& rect, const SkPaint& paint, android::BitmapPalette palette);

    /**
     * See [addArea(long, SkPaint&)]
     */
    void addArea(int32_t width, int32_t height, const SkPaint* paint);

    /**
+1 −12
Original line number Diff line number Diff line
@@ -828,18 +828,7 @@ constexpr bool has_bounds = std::experimental::is_detected_v<has_bounds_helper,

template <class T>
constexpr color_area_fn colorAreaForOp() {
    if constexpr (has_palette<T> && has_bounds<T>) {
        return [](const void* opRaw, ColorArea* accumulator) {
            const T* op = reinterpret_cast<const T*>(opRaw);
            const SkPaint* paint = &op->paint;
            if (!paint) return;

            auto rect = op->getConservativeBounds();
            if (!rect.has_value()) return;

            accumulator->addArea(*rect, *paint, op->palette);
        };
    } else if constexpr (has_paint<T> && has_bounds<T>) {
    if constexpr (has_paint<T> && has_bounds<T>) {
        return [](const void* opRaw, ColorArea* accumulator) {
            const T* op = reinterpret_cast<const T*>(opRaw);
            const SkPaint* paint = &op->paint;