Support High Contrast Text for all canvas types

Change-Id: Iee324446798fe1a1cb32cb991f181a4af24aa93c
diff --git a/libs/hwui/Canvas.h b/libs/hwui/Canvas.h
index 116bc56..a0b87f9 100644
--- a/libs/hwui/Canvas.h
+++ b/libs/hwui/Canvas.h
@@ -62,6 +62,9 @@
     virtual int width() = 0;
     virtual int height() = 0;
 
+    virtual void setHighContrastText(bool highContrastText) = 0;
+    virtual bool isHighContrastText() = 0;
+
 // ----------------------------------------------------------------------------
 // Canvas state operations
 // ----------------------------------------------------------------------------
diff --git a/libs/hwui/DisplayListCanvas.cpp b/libs/hwui/DisplayListCanvas.cpp
index af18e03..cc69d55 100644
--- a/libs/hwui/DisplayListCanvas.cpp
+++ b/libs/hwui/DisplayListCanvas.cpp
@@ -437,16 +437,6 @@
     addDrawOp(op);
 }
 
-static void simplifyPaint(int color, SkPaint* paint) {
-    paint->setColor(color);
-    paint->setShader(nullptr);
-    paint->setColorFilter(nullptr);
-    paint->setLooper(nullptr);
-    paint->setStrokeWidth(4 + 0.04 * paint->getTextSize());
-    paint->setStrokeJoin(SkPaint::kRound_Join);
-    paint->setLooper(nullptr);
-}
-
 void DisplayListCanvas::drawText(const uint16_t* glyphs, const float* positions,
         int count, const SkPaint& paint, float x, float y,
         float boundsLeft, float boundsTop, float boundsRight, float boundsBottom,
@@ -459,31 +449,9 @@
     positions = refBuffer<float>(positions, count * 2);
     Rect bounds(boundsLeft, boundsTop, boundsRight, boundsBottom);
 
-    if (CC_UNLIKELY(mHighContrastText)) {
-        // high contrast draw path
-        int color = paint.getColor();
-        int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
-        bool darken = channelSum < (128 * 3);
-
-        // outline
-        SkPaint* outlinePaint = copyPaint(&paint);
-        simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, outlinePaint);
-        outlinePaint->setStyle(SkPaint::kStrokeAndFill_Style);
-        addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
-                x, y, positions, outlinePaint, totalAdvance, bounds)); // bounds?
-
-        // inner
-        SkPaint* innerPaint = copyPaint(&paint);
-        simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, innerPaint);
-        innerPaint->setStyle(SkPaint::kFill_Style);
-        addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
-                x, y, positions, innerPaint, totalAdvance, bounds));
-    } else {
-        // standard draw path
-        DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
-                x, y, positions, refPaint(&paint), totalAdvance, bounds);
-        addDrawOp(op);
-    }
+    DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
+            x, y, positions, refPaint(&paint), totalAdvance, bounds);
+    addDrawOp(op);
 }
 
 void DisplayListCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) {
diff --git a/libs/hwui/DisplayListCanvas.h b/libs/hwui/DisplayListCanvas.h
index 6f2e2b5..efdf9ed 100644
--- a/libs/hwui/DisplayListCanvas.h
+++ b/libs/hwui/DisplayListCanvas.h
@@ -101,10 +101,6 @@
     // TODO: rename for consistency
     void callDrawGLFunction(Functor* functor);
 
-    void setHighContrastText(bool highContrastText) {
-        mHighContrastText = highContrastText;
-    }
-
 // ----------------------------------------------------------------------------
 // CanvasStateClient interface
 // ----------------------------------------------------------------------------
@@ -125,6 +121,11 @@
     virtual int width() override { return mState.getWidth(); }
     virtual int height() override { return mState.getHeight(); }
 
+    virtual void setHighContrastText(bool highContrastText) override {
+        mHighContrastText = highContrastText;
+    }
+    virtual bool isHighContrastText() override { return mHighContrastText; }
+
 // ----------------------------------------------------------------------------
 // android/graphics/Canvas state operations
 // ----------------------------------------------------------------------------
@@ -304,16 +305,6 @@
         return cachedPaint;
     }
 
-    inline SkPaint* copyPaint(const SkPaint* paint) {
-        if (!paint) return nullptr;
-
-        SkPaint* returnPaint = new SkPaint(*paint);
-        std::unique_ptr<const SkPaint> copy(returnPaint);
-        mDisplayListData->paints.push_back(std::move(copy));
-
-        return returnPaint;
-    }
-
     inline const SkRegion* refRegion(const SkRegion* region) {
         if (!region) {
             return region;
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index 971b53a..77079b7 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -55,6 +55,11 @@
     virtual int width() override;
     virtual int height() override;
 
+    virtual void setHighContrastText(bool highContrastText) override {
+        mHighContrastText = highContrastText;
+    }
+    virtual bool isHighContrastText() override { return mHighContrastText; }
+
     virtual int getSaveCount() const override;
     virtual int save(SkCanvas::SaveFlags flags) override;
     virtual void restore() override;
@@ -135,6 +140,8 @@
         SkCanvas::SaveFlags saveFlags;
     };
 
+    bool mHighContrastText = false;
+
     void recordPartialSave(SkCanvas::SaveFlags flags);
     void saveClipsForFrame(SkTArray<SkClipStack::Element>& clips, int frameSaveCount);
     void applyClips(const SkTArray<SkClipStack::Element>& clips);