Restore SkCanvas::kPreserveLCDText_SaveLayerFlag
Will use this in Chrome to support LCDText in saveLayer/restore with
opacity.
This partly reverts https://skia-review.googlesource.com/c/skia/+/181841.
Bug: 1076019
Change-Id: Id870fb1dcc95c9b319797e936725b4447a97d1d5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/285956
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Auto-Submit: Xianzhu Wang <wangxianzhu@chromium.org>
diff --git a/gm/lcdtext.cpp b/gm/lcdtext.cpp
index 5ca7bdd..1779942 100644
--- a/gm/lcdtext.cpp
+++ b/gm/lcdtext.cpp
@@ -103,5 +103,37 @@
}
}
};
-DEF_GM( return new LcdTextGM; )
-DEF_GM( return new LcdTextSizeGM; )
+
+class SaveLayerPreserveLCDTextGM : public skiagm::GM {
+ static constexpr SkScalar kTextHeight = 36;
+
+ SkString onShortName() override { return SkString("savelayerpreservelcdtext"); }
+
+ SkISize onISize() override { return {620, 300}; }
+
+ void onDraw(SkCanvas* canvas) override {
+ drawText(canvas, SkString("SaveLayer PreserveLCDText"), 50,
+ SkCanvas::kPreserveLCDText_SaveLayerFlag);
+ drawText(canvas, SkString("SaveLayer Default (LCDText not preserved)"), 150, 0);
+ }
+
+ void drawText(SkCanvas* canvas,
+ const SkString& string,
+ int y,
+ SkCanvas::SaveLayerFlags saveLayerFlags) {
+ SkCanvas::SaveLayerRec rec(nullptr, nullptr, saveLayerFlags);
+ canvas->saveLayer(rec);
+ SkPaint paint;
+ paint.setColor(SK_ColorWHITE);
+ canvas->drawRect(SkRect::MakeXYWH(0, y - 10, 640, kTextHeight + 20), paint);
+ paint.setColor(SK_ColorBLACK);
+ SkFont font(nullptr, kTextHeight);
+ font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+ canvas->drawString(string, 10, y, font, paint);
+ canvas->restore();
+ }
+};
+
+DEF_GM(return new LcdTextGM;)
+DEF_GM(return new LcdTextSizeGM;)
+DEF_GM(return new SaveLayerPreserveLCDTextGM;)