diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-02-25 14:11:58 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-25 14:11:58 +0000 |
commit | ed0887138241cd35f96902c7e0969573f9d93348 (patch) | |
tree | 75efc9a3835d19905e0c098f8eb0a9c5913b7b6e | |
parent | 45f58ae93037ee20b6d7c600361b27f318bde50d (diff) | |
parent | 1c5eb597fd0f13034740bff7888a0caecec7d84d (diff) |
Merge "Fix bug on High Contrast Text : where DarkTheme is enabled && ForceDarkAllowed is true."
-rw-r--r-- | libs/hwui/RecordingCanvas.cpp | 21 | ||||
-rw-r--r-- | libs/hwui/hwui/Canvas.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/hwui/Canvas.h | 8 |
3 files changed, 32 insertions, 1 deletions
diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp index dc467c41baed..41ecd5e49acd 100644 --- a/libs/hwui/RecordingCanvas.cpp +++ b/libs/hwui/RecordingCanvas.cpp @@ -401,10 +401,11 @@ struct DrawImageLattice final : Op { struct DrawTextBlob final : Op { static const auto kType = Type::DrawTextBlob; DrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) - : blob(sk_ref_sp(blob)), x(x), y(y), paint(paint) {} + : blob(sk_ref_sp(blob)), x(x), y(y), paint(paint), drawTextBlobMode(gDrawTextBlobMode) {} sk_sp<const SkTextBlob> blob; SkScalar x, y; SkPaint paint; + DrawTextBlobMode drawTextBlobMode; void draw(SkCanvas* c, const SkMatrix&) const { c->drawTextBlob(blob.get(), x, y, paint); } }; @@ -791,6 +792,24 @@ constexpr color_transform_fn colorTransformForOp() { } } +template<> +constexpr color_transform_fn colorTransformForOp<DrawTextBlob>() { + return [](const void *opRaw, ColorTransform transform) { + const DrawTextBlob *op = reinterpret_cast<const DrawTextBlob*>(opRaw); + switch (op->drawTextBlobMode) { + case DrawTextBlobMode::HctOutline: + const_cast<SkPaint&>(op->paint).setColor(SK_ColorBLACK); + break; + case DrawTextBlobMode::HctInner: + const_cast<SkPaint&>(op->paint).setColor(SK_ColorWHITE); + break; + default: + transformPaint(transform, const_cast<SkPaint*>(&(op->paint))); + break; + } + }; +} + #define X(T) colorTransformForOp<T>(), static const color_transform_fn color_transform_fns[] = { #include "DisplayListOps.in" diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp index c138a32eacc2..14906d5c1166 100644 --- a/libs/hwui/hwui/Canvas.cpp +++ b/libs/hwui/hwui/Canvas.cpp @@ -111,6 +111,7 @@ public: bool darken = channelSum < (128 * 3); // outline + gDrawTextBlobMode = DrawTextBlobMode::HctOutline; Paint outlinePaint(paint); simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, &outlinePaint); outlinePaint.setStyle(SkPaint::kStrokeAndFill_Style); @@ -118,11 +119,14 @@ public: bounds.mRight, bounds.mBottom, totalAdvance); // inner + gDrawTextBlobMode = DrawTextBlobMode::HctInner; Paint innerPaint(paint); simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, &innerPaint); innerPaint.setStyle(SkPaint::kFill_Style); canvas->drawGlyphs(glyphFunc, glyphCount, innerPaint, x, y, bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance); + + gDrawTextBlobMode = DrawTextBlobMode::Normal; } else { // standard draw path canvas->drawGlyphs(glyphFunc, glyphCount, paint, x, y, bounds.mLeft, bounds.mTop, diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h index 27dfed305a94..d9928059ed30 100644 --- a/libs/hwui/hwui/Canvas.h +++ b/libs/hwui/hwui/Canvas.h @@ -87,6 +87,14 @@ class Bitmap; class Paint; struct Typeface; +enum class DrawTextBlobMode { + Normal, + HctOutline, + HctInner, +}; + +inline DrawTextBlobMode gDrawTextBlobMode = DrawTextBlobMode::Normal; + class ANDROID_API Canvas { public: virtual ~Canvas(){}; |