aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/pictureimagefilter.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-04-13 10:55:07 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-13 10:55:07 -0700
commit54ef1a7c95bcc8e507f7d6ccd9a49bd9a110ba90 (patch)
tree1f88c2c52ad60ca8c61f8ca11d38a16e8d421b43 /gm/pictureimagefilter.cpp
parent2892668f1b36de25c63a70858dfab5ff0f5caf72 (diff)
Add GM to prevent mis-drawing of LCD text in SkPictureImageFilters
Diffstat (limited to 'gm/pictureimagefilter.cpp')
-rw-r--r--gm/pictureimagefilter.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp
index 8e5f1ef2a6..30586b3dbe 100644
--- a/gm/pictureimagefilter.cpp
+++ b/gm/pictureimagefilter.cpp
@@ -37,6 +37,23 @@ static sk_sp<SkPicture> make_picture() {
return recorder.finishRecordingAsPicture();
}
+// Create a picture that will draw LCD text
+static sk_sp<SkPicture> make_LCD_picture() {
+ SkPictureRecorder recorder;
+ SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0);
+ canvas->clear(SK_ColorTRANSPARENT);
+ SkPaint paint;
+ paint.setLCDRenderText(true); // want LCD
+ paint.setAntiAlias(true); // need AA for LCD
+ sk_tool_utils::set_portable_typeface(&paint);
+ paint.setColor(0xFFFFFFFF);
+ // this has to be small enough that it doesn't become a path
+ paint.setTextSize(SkIntToScalar(36));
+ const char* str = "e";
+ canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
+ return recorder.finishRecordingAsPicture();
+}
+
class PictureImageFilterGM : public skiagm::GM {
public:
PictureImageFilterGM() { }
@@ -50,10 +67,11 @@ protected:
void onOnceBeforeDraw() override {
fPicture = make_picture();
+ fLCDPicture = make_LCD_picture();
}
void onDraw(SkCanvas* canvas) override {
- canvas->clear(SK_ColorBLACK);
+ canvas->clear(SK_ColorGRAY);
{
SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
@@ -85,6 +103,26 @@ protected:
fill_rect_filtered(canvas, bounds, pictureSourceEmptyRect);
canvas->translate(SkIntToScalar(100), 0);
+ // Draw the LCD picture to a layer
+ {
+ SkPaint stroke;
+ stroke.setStyle(SkPaint::kStroke_Style);
+
+ canvas->drawRect(bounds, stroke);
+
+ SkPaint paint;
+ paint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace(
+ fLCDPicture,
+ fPicture->cullRect(),
+ kNone_SkFilterQuality));
+
+ canvas->scale(4, 4);
+ canvas->translate(-0.9f*srcRect.fLeft, -2.45f*srcRect.fTop);
+
+ canvas->saveLayerPreserveLCDTextRequests(&bounds, &paint);
+ canvas->restore();
+ }
+
canvas->restore();
// Draw the picture scaled
@@ -105,6 +143,7 @@ protected:
private:
sk_sp<SkPicture> fPicture;
+ sk_sp<SkPicture> fLCDPicture;
typedef GM INHERITED;
};