summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/hwui/Canvas.cpp34
-rw-r--r--libs/hwui/hwui/Paint.h9
-rw-r--r--libs/hwui/renderthread/EglManager.cpp2
-rw-r--r--libs/hwui/tests/unit/SkiaBehaviorTests.cpp2
4 files changed, 31 insertions, 16 deletions
diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp
index 679cb5021e27..4507c5018c26 100644
--- a/libs/hwui/hwui/Canvas.cpp
+++ b/libs/hwui/hwui/Canvas.cpp
@@ -46,23 +46,31 @@ void Canvas::drawTextDecorations(float x, float y, float length, const SkPaint&
flags = paint.getFlags();
}
if (flags & (SkPaint::kUnderlineText_ReserveFlag | SkPaint::kStrikeThruText_ReserveFlag)) {
- // Same values used by Skia
- const float kStdStrikeThru_Offset = (-6.0f / 21.0f);
- const float kStdUnderline_Offset = (1.0f / 9.0f);
- const float kStdUnderline_Thickness = (1.0f / 18.0f);
-
- SkScalar left = x;
- SkScalar right = x + length;
- float textSize = paint.getTextSize();
- float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
+
+ const SkScalar left = x;
+ const SkScalar right = x + length;
if (flags & SkPaint::kUnderlineText_ReserveFlag) {
- SkScalar top = y + textSize * kStdUnderline_Offset - 0.5f * strokeWidth;
- SkScalar bottom = y + textSize * kStdUnderline_Offset + 0.5f * strokeWidth;
+ Paint::FontMetrics metrics;
+ paint.getFontMetrics(&metrics);
+ SkScalar position;
+ if (!metrics.hasUnderlinePosition(&position)) {
+ position = paint.getTextSize() * Paint::kStdUnderline_Top;
+ }
+ SkScalar thickness;
+ if (!metrics.hasUnderlineThickness(&thickness)) {
+ thickness = paint.getTextSize() * Paint::kStdUnderline_Thickness;
+ }
+ const float strokeWidth = fmax(thickness, 1.0f);
+ const SkScalar top = y + position;
+ const SkScalar bottom = top + strokeWidth;
drawRect(left, top, right, bottom, paint);
}
if (flags & SkPaint::kStrikeThruText_ReserveFlag) {
- SkScalar top = y + textSize * kStdStrikeThru_Offset - 0.5f * strokeWidth;
- SkScalar bottom = y + textSize * kStdStrikeThru_Offset + 0.5f * strokeWidth;
+ const float textSize = paint.getTextSize();
+ const float position = textSize * Paint::kStdStrikeThru_Offset;
+ const float strokeWidth = fmax(textSize * Paint::kStdUnderline_Thickness, 1.0f);
+ const SkScalar top = y + position - 0.5f * strokeWidth;
+ const SkScalar bottom = y + position + 0.5f * strokeWidth;
drawRect(left, top, right, bottom, paint);
}
}
diff --git a/libs/hwui/hwui/Paint.h b/libs/hwui/hwui/Paint.h
index c9b5f0031a7b..4305025272b2 100644
--- a/libs/hwui/hwui/Paint.h
+++ b/libs/hwui/hwui/Paint.h
@@ -28,6 +28,15 @@ namespace android {
class ANDROID_API Paint : public SkPaint {
public:
+ // Default values for underlined and strikethrough text,
+ // as defined by Skia in SkTextFormatParams.h.
+ constexpr static float kStdStrikeThru_Offset = (-6.0f / 21.0f);
+ constexpr static float kStdUnderline_Offset = (1.0f / 9.0f);
+ constexpr static float kStdUnderline_Thickness = (1.0f / 18.0f);
+
+ constexpr static float kStdUnderline_Top =
+ kStdUnderline_Offset - 0.5f * kStdUnderline_Thickness;
+
Paint();
Paint(const Paint& paint);
Paint(const SkPaint& paint); // NOLINT(implicit)
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp
index d6240e7064cf..cc791f6171a9 100644
--- a/libs/hwui/renderthread/EglManager.cpp
+++ b/libs/hwui/renderthread/EglManager.cpp
@@ -113,7 +113,7 @@ void EglManager::initialize() {
// An Adreno driver bug is causing rendering problems for SkiaGL with
// buffer age swap behavior (b/31957043). To temporarily workaround,
// we will use preserved swap behavior.
- if (Properties::useBufferAge && EglExtensions.bufferAge && !Properties::isSkiaEnabled()) {
+ if (Properties::useBufferAge && EglExtensions.bufferAge) {
mSwapBehavior = SwapBehavior::BufferAge;
} else {
mSwapBehavior = SwapBehavior::Preserved;
diff --git a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
index a3d5079c6ce9..85b12ba79a8c 100644
--- a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
+++ b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
@@ -51,8 +51,6 @@ TEST(SkiaBehavior, CreateBitmapShader1x1) {
SkShader::TileMode xy[2];
ASSERT_TRUE(s->isABitmap(&bitmap, nullptr, xy))
<< "1x1 bitmap shader must query as bitmap shader";
- EXPECT_EQ(SkShader::kClamp_TileMode, xy[0]);
- EXPECT_EQ(SkShader::kRepeat_TileMode, xy[1]);
EXPECT_EQ(origBitmap.pixelRef(), bitmap.pixelRef());
}