diff options
author | reed <reed@google.com> | 2014-10-01 13:59:33 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-01 13:59:34 -0700 |
commit | 4942e7550ec80796132ab1ce2cc935a5dd1b464c (patch) | |
tree | e59c47831777715e0564b83fe12b95df09b8b146 | |
parent | 5817f21e0b79d88ec420000ae8e1b79eb7facce0 (diff) |
fix prev change to tooBigForLCD, and add test
BUG=skia:
Review URL: https://codereview.chromium.org/617353003
-rw-r--r-- | gm/lcdtext.cpp | 89 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 11 |
2 files changed, 79 insertions, 21 deletions
diff --git a/gm/lcdtext.cpp b/gm/lcdtext.cpp index b4db0ff12a..0b5739c7ab 100644 --- a/gm/lcdtext.cpp +++ b/gm/lcdtext.cpp @@ -13,25 +13,23 @@ #include "gm.h" #include "SkCanvas.h" -namespace skiagm { - -class LcdTextGM : public GM { +class LcdTextGM : public skiagm::GM { public: LcdTextGM() { const int pointSize = 36; textHeight = SkIntToScalar(pointSize); } - + protected: - + SkString onShortName() { return SkString("lcdtext"); } - + SkISize onISize() { return SkISize::Make(640, 480); } - + virtual void onDraw(SkCanvas* canvas) { - + y = textHeight; drawText(canvas, SkString("TEXT: SubpixelTrue LCDRenderTrue"), true, true); @@ -42,7 +40,7 @@ protected: drawText(canvas, SkString("TEXT: SubpixelFalse LCDRenderFalse"), false, false); } - + void drawText(SkCanvas* canvas, const SkString& string, bool subpixelTextEnabled, bool lcdRenderTextEnabled) { SkPaint paint; @@ -53,19 +51,78 @@ protected: paint.setSubpixelText(subpixelTextEnabled); paint.setLCDRenderText(lcdRenderTextEnabled); paint.setTextSize(textHeight); - + canvas->drawText(string.c_str(), string.size(), 0, y, paint); y += textHeight; } - + private: - typedef GM INHERITED; + typedef skiagm::GM INHERITED; SkScalar y, textHeight; }; -/////////////////////////////////////////////////////////////////////////////// +/* + * Skia will automatically disable LCD requests if the total size exceeds some limit + * (hard coded in this test for now, as it is now avaiable as an API) + * + * Test this both by changing "textsize" and by changing the computed size (textsize * CTM) + */ +class LcdTextSizeGM : public skiagm::GM { + enum { + kLCDTextSizeLimit = 48 + }; + + static void ScaleAbout(SkCanvas* canvas, SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) { + SkMatrix m; + m.setScale(sx, sy, px, py); + canvas->concat(m); + } -static GM* MyFactory(void*) { return new LcdTextGM; } -static GMRegistry reg(MyFactory); +public: + LcdTextSizeGM() {} + +protected: + SkString onShortName() { + return SkString("lcdtextsize"); + } + + SkISize onISize() { return SkISize::Make(320, 120); } + + virtual void onDraw(SkCanvas* canvas) { + const char* lcd_text = "LCD"; + const char* gray_text = "GRAY"; + + SkPaint paint; + paint.setAntiAlias(true); + paint.setLCDRenderText(true); + + const struct { + SkPoint fLoc; + SkScalar fTextSize; + SkScalar fScale; + const char* fText; + } rec[] = { + { { 10, 50 }, kLCDTextSizeLimit - 1, 1, lcd_text }, + { { 160, 50 }, kLCDTextSizeLimit + 1, 1, gray_text }, + { { 10, 100 }, kLCDTextSizeLimit / 2, 1.99f, lcd_text }, + { { 160, 100 }, kLCDTextSizeLimit / 2, 2.01f, gray_text }, + }; + + for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { + const SkPoint loc = rec[i].fLoc; + SkAutoCanvasRestore acr(canvas, true); + + paint.setTextSize(rec[i].fTextSize); + ScaleAbout(canvas, rec[i].fScale, rec[i].fScale, loc.x(), loc.y()); + canvas->drawText(rec[i].fText, strlen(rec[i].fText), loc.x(), loc.y(), paint); + } + } + +private: + typedef skiagm::GM INHERITED; +}; + +/////////////////////////////////////////////////////////////////////////////// -} +DEF_GM( return new LcdTextGM; ) +DEF_GM( return new LcdTextSizeGM; ) diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 7a23566fec..67b630e850 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1481,14 +1481,15 @@ static SkColor computeLuminanceColor(const SkPaint& paint) { const SkScalar gMaxSize2ForLCDText = SK_MAX_SIZE_FOR_LCDTEXT * SK_MAX_SIZE_FOR_LCDTEXT; -static bool tooBigForLCD(const SkScalerContext::Rec& rec, bool checkPost2x2) { - SkScalar size = rec.fTextSize; +static bool too_big_for_lcd(const SkScalerContext::Rec& rec, bool checkPost2x2) { if (checkPost2x2) { SkScalar area = rec.fPost2x2[0][0] * rec.fPost2x2[1][1] - rec.fPost2x2[1][0] * rec.fPost2x2[0][1]; - size *= SkScalarAbs(area); + area *= rec.fTextSize * rec.fTextSize; + return area > gMaxSize2ForLCDText; + } else { + return rec.fTextSize > SK_MAX_SIZE_FOR_LCDTEXT; } - return size > gMaxSize2ForLCDText; } /* @@ -1584,7 +1585,7 @@ void SkScalerContext::MakeRec(const SkPaint& paint, rec->fMaskFormat = SkToU8(computeMaskFormat(paint)); if (SkMask::kLCD16_Format == rec->fMaskFormat || SkMask::kLCD32_Format == rec->fMaskFormat) { - if (tooBigForLCD(*rec, checkPost2x2)) { + if (too_big_for_lcd(*rec, checkPost2x2)) { rec->fMaskFormat = SkMask::kA8_Format; flags |= SkScalerContext::kGenA8FromLCD_Flag; } else { |