summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Derek Sollenberger <djsollen@google.com> 2015-07-13 13:24:29 -0400
committer Derek Sollenberger <djsollen@google.com> 2015-07-13 15:13:15 -0400
commit876d56612ab8ec7032f702905d694670e6c4febd (patch)
treebc085c681cdb03d7a8c8bba19edfb54f90b298ff /libs
parent1f4fb3c4684965156aa5cd3e9bca71a188056447 (diff)
Support High Contrast Text for all canvas types
Change-Id: Ib46ba3d7c67e081872e6a4b11d294fe9a61f5bbd
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/Canvas.h3
-rw-r--r--libs/hwui/DisplayListCanvas.cpp38
-rw-r--r--libs/hwui/DisplayListCanvas.h19
-rw-r--r--libs/hwui/SkiaCanvas.cpp3
4 files changed, 14 insertions, 49 deletions
diff --git a/libs/hwui/Canvas.h b/libs/hwui/Canvas.h
index 116bc56bfe4d..a0b87f9cadb6 100644
--- a/libs/hwui/Canvas.h
+++ b/libs/hwui/Canvas.h
@@ -62,6 +62,9 @@ public:
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 af18e03c60a9..cc69d55cbfac 100644
--- a/libs/hwui/DisplayListCanvas.cpp
+++ b/libs/hwui/DisplayListCanvas.cpp
@@ -437,16 +437,6 @@ void DisplayListCanvas::drawPosText(const uint16_t* text, const float* positions
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 @@ void DisplayListCanvas::drawText(const uint16_t* glyphs, const float* positions,
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 6f2e2b50967e..efdf9ed336d9 100644
--- a/libs/hwui/DisplayListCanvas.h
+++ b/libs/hwui/DisplayListCanvas.h
@@ -101,10 +101,6 @@ public:
// TODO: rename for consistency
void callDrawGLFunction(Functor* functor);
- void setHighContrastText(bool highContrastText) {
- mHighContrastText = highContrastText;
- }
-
// ----------------------------------------------------------------------------
// CanvasStateClient interface
// ----------------------------------------------------------------------------
@@ -125,6 +121,11 @@ public:
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 @@ private:
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 971b53aaf198..c98e2f47001e 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -55,6 +55,9 @@ public:
virtual int width() override;
virtual int height() override;
+ virtual void setHighContrastText(bool highContrastText) override {}
+ virtual bool isHighContrastText() override { return false; }
+
virtual int getSaveCount() const override;
virtual int save(SkCanvas::SaveFlags flags) override;
virtual void restore() override;