Index: gm/pictureimagefilter.cpp |
diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp |
index 8e5f1ef2a675b4776b6f6211a455ca0647bfd538..30586b3dbe796d51dc3733824d4f91cc26c8c12a 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; |
}; |