Add BW masks to random scaler context
authorjoshualitt <joshualitt@chromium.org>
Sat, 1 Aug 2015 17:33:40 +0000 (10:33 -0700)
committerCommit bot <commit-bot@chromium.org>
Sat, 1 Aug 2015 17:33:40 +0000 (10:33 -0700)
TBR=bsalomon@google.com
BUG=skia:

Committed: https://skia.googlesource.com/skia/+/a4a530614e9ba856aac3f16c29683e6a2a9153d9

Review URL: https://codereview.chromium.org/1270793003

gm/textblobrandomfont.cpp
src/fonts/SkRandomScalerContext.cpp
tests/TextBlobCacheTest.cpp

index f7d3b5c..c1e754c 100644 (file)
@@ -49,14 +49,36 @@ protected:
 
         SkRect bounds;
         paint.measureText(text, strlen(text), &bounds);
-
-        SkScalar yOffset = bounds.height();
         sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
 
         // A8
+        const char* bigtext1 = "The quick brown fox";
+        const char* bigtext2 = "jumps over the lazy dog.";
+        paint.setTextSize(160);
         paint.setSubpixelText(false);
         paint.setLCDRenderText(false);
-        sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 32);
+        paint.measureText(bigtext1, strlen(bigtext1), &bounds);
+        SkScalar offset = bounds.height();
+        sk_tool_utils::add_to_text_blob(&builder, bigtext1, paint, 0, offset);
+
+        paint.measureText(bigtext2, strlen(bigtext2), &bounds);
+        offset += bounds.height();
+        sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset);
+
+        // color emoji
+        SkAutoTUnref<SkTypeface> origEmoji;
+        sk_tool_utils::emoji_typeface(&origEmoji);
+        const char* osName = sk_tool_utils::platform_os_name();
+        // The mac emoji string will break us
+        if (origEmoji && (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu"))) {
+            const char* emojiText = sk_tool_utils::emoji_sample_text();
+            paint.measureText(emojiText, strlen(emojiText), &bounds);
+            offset += bounds.height();
+            SkAutoTUnref<SkTypeface> randomEmoji(SkNEW_ARGS(SkRandomTypeface, (orig, paint,
+                                                                               false)));
+            paint.setTypeface(randomEmoji);
+            sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offset);
+        }
 
         // build
         fBlob.reset(builder.build());
@@ -88,9 +110,9 @@ protected:
 
             SkCanvas* c = surface->getCanvas();
 
-            int stride = SkScalarCeilToInt(fBlob->bounds().height() / 2) + 10;
-            int yOffset = stride;
-            for (int i = 0; i < 10; i++) {
+            int stride = SkScalarCeilToInt(fBlob->bounds().height());
+            int yOffset = stride / 8;
+            for (int i = 0; i < 1; i++) {
                 // fiddle the canvas to force regen of textblobs
                 canvas->rotate(i % 2 ? 0.0f : -0.05f);
                 canvas->drawTextBlob(fBlob, 10.0f, SkIntToScalar(yOffset), paint);
@@ -119,8 +141,8 @@ protected:
 private:
     SkAutoTUnref<const SkTextBlob> fBlob;
 
-    static const int kWidth = 1000;
-    static const int kHeight = 1000;
+    static const int kWidth = 2000;
+    static const int kHeight = 1600;
 
     typedef GM INHERITED;
 };
index 0693682..799e51d 100644 (file)
@@ -63,7 +63,7 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
     // Here we will change the mask format of the glyph
     // NOTE this is being overridden by the base class
     SkMask::Format format;
-    switch (glyph->getGlyphID() % 3) {
+    switch (glyph->getGlyphID() % 4) {
         case 0:
             format = SkMask::kLCD16_Format;
             break;
@@ -73,6 +73,9 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
         case 2:
             format = SkMask::kARGB32_Format;
             break;
+        case 3:
+            format = SkMask::kBW_Format;
+            break;
     }
 
     fProxy->getMetrics(glyph);
@@ -132,7 +135,7 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
 
 void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
     SkMask::Format format = (SkMask::Format)glyph.fMaskFormat;
-    switch (glyph.getGlyphID() % 3) {
+    switch (glyph.getGlyphID() % 4) {
         case 0:
             format = SkMask::kLCD16_Format;
             break;
@@ -142,6 +145,9 @@ void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
         case 2:
             format = SkMask::kARGB32_Format;
             break;
+        case 3:
+            format = SkMask::kBW_Format;
+            break;
     }
     const_cast<SkGlyph&>(glyph).fMaskFormat = format;
 
index 60a6a8a..c063040 100644 (file)
@@ -156,9 +156,9 @@ DEF_GPUTEST(TextBlobCache, reporter, factory) {
 
 DEF_GPUTEST(TextBlobAbnormal, reporter, factory) {
 #ifdef SK_BUILD_FOR_ANDROID
-    text_blob_cache_inner(reporter, factory, 32, 32, 1, false);
+    text_blob_cache_inner(reporter, factory, 256, 256, 30, false);
 #else
-    text_blob_cache_inner(reporter, factory, 256, 256, 1, false);
+    text_blob_cache_inner(reporter, factory, 512, 256, 30, false);
 #endif
 }
 #endif