Loading libs/hwui/CanvasTransform.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -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); Loading libs/hwui/CanvasTransform.h +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading libs/hwui/DisplayList.h +2 −0 Original line number Diff line number Diff line Loading @@ -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); Loading libs/hwui/RecordingCanvas.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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; } Loading libs/hwui/RecordingCanvas.h +3 −1 Original line number Diff line number Diff line Loading @@ -110,7 +110,7 @@ class RecordingCanvas; class DisplayListData final { public: DisplayListData() : mHasText(false) {} DisplayListData() : mHasText(false), mHasFill(false) {} ~DisplayListData(); void draw(SkCanvas* canvas) const; Loading @@ -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; } Loading Loading @@ -192,6 +193,7 @@ private: size_t fReserved = 0; bool mHasText : 1; bool mHasFill : 1; }; class RecordingCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> { Loading Loading
libs/hwui/CanvasTransform.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
libs/hwui/CanvasTransform.h +3 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
libs/hwui/DisplayList.h +2 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
libs/hwui/RecordingCanvas.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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; } Loading
libs/hwui/RecordingCanvas.h +3 −1 Original line number Diff line number Diff line Loading @@ -110,7 +110,7 @@ class RecordingCanvas; class DisplayListData final { public: DisplayListData() : mHasText(false) {} DisplayListData() : mHasText(false), mHasFill(false) {} ~DisplayListData(); void draw(SkCanvas* canvas) const; Loading @@ -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; } Loading Loading @@ -192,6 +193,7 @@ private: size_t fReserved = 0; bool mHasText : 1; bool mHasFill : 1; }; class RecordingCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> { Loading