Revert of Fix color emoji. (patchset #11 id:320001 of https://codereview.chromium...
authorjvanverth <jvanverth@google.com>
Fri, 10 Oct 2014 15:52:03 +0000 (08:52 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 10 Oct 2014 15:52:03 +0000 (08:52 -0700)
Reason for revert:
Crashing the Windows bots.

Original issue's description:
> Fix color emoji.
>
> Removes the GrMaskFormat and single atlas in GrTextStrike.
> Replaces it by storing the GrMaskFormat in each GrGlyph, and
> doing a lookup for the correct atlas based on that.
>
> Disables color glyph rendering in GrDistanceFieldTextContext
> for now.
>
> BUG=skia:2887
>
> Committed: https://skia.googlesource.com/skia/+/bc92163ddfe957ad6ffbb02ac40e0ba75ff82216

TBR=robertphillips@google.com,bungeman@google.com,reed@google.com,bsalomon@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:2887

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

expectations/gm/ignored-tests.txt
include/gpu/GrFontScaler.h
include/gpu/GrGlyph.h
src/gpu/GrBitmapTextContext.cpp
src/gpu/GrBitmapTextContext.h
src/gpu/GrDistanceFieldTextContext.cpp
src/gpu/GrFontScaler.cpp
src/gpu/GrTextStrike.cpp
src/gpu/GrTextStrike.h

index 27182c9..5793ba2 100644 (file)
 ## epoger will rebaseline by 25 Dec 2013
 #gradtext
 
-# jvanverth
-# color emoji fix
-coloremoji
-
 # rileya - https://codereview.chromium.org/516463005/ will rebaseline after bots cycle
 yuv_to_rgb_effect
 
index 54d1e3f..0376038 100644 (file)
@@ -66,8 +66,7 @@ public:
     virtual ~GrFontScaler();
     
     const GrFontDescKey* getKey();
-    GrMaskFormat getMaskFormat() const;
-    GrMaskFormat getPackedGlyphMaskFormat(GrGlyph::PackedID) const;
+    GrMaskFormat getMaskFormat();
     bool getPackedGlyphBounds(GrGlyph::PackedID, SkIRect* bounds);
     bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
                                      int rowBytes, void* image);
index 0e534d6..a379144 100644 (file)
@@ -9,10 +9,8 @@
 #define GrGlyph_DEFINED
 
 #include "GrRect.h"
-#include "GrTypes.h"
-
-#include "SkChecksum.h"
 #include "SkPath.h"
+#include "SkChecksum.h"
 
 class GrPlot;
 
@@ -25,19 +23,17 @@ class GrPlot;
 struct GrGlyph {
     typedef uint32_t PackedID;
 
-    GrPlot*      fPlot;
-    SkPath*      fPath;
-    PackedID     fPackedID;
-    GrMaskFormat fMaskFormat;
-    GrIRect16    fBounds;
-    SkIPoint16   fAtlasLocation;
+    GrPlot*     fPlot;
+    SkPath*     fPath;
+    PackedID    fPackedID;
+    GrIRect16   fBounds;
+    SkIPoint16  fAtlasLocation;
 
-    void init(GrGlyph::PackedID packed, const SkIRect& bounds, GrMaskFormat format) {
+    void init(GrGlyph::PackedID packed, const SkIRect& bounds) {
         fPlot = NULL;
         fPath = NULL;
         fPackedID = packed;
         fBounds.set(bounds);
-        fMaskFormat = format;
         fAtlasLocation.set(0, 0);
     }
 
index 7cfe917..9478d04 100755 (executable)
@@ -370,7 +370,7 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed,
             }
 
             // try to clear out an unused plot before we flush
-            if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+            if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
                 fStrike->addGlyphToAtlas(glyph, scaler)) {
                 goto HAS_ATLAS;
             }
@@ -386,7 +386,7 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed,
             fContext->flush();
 
             // we should have an unused plot now
-            if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+            if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
                 fStrike->addGlyphToAtlas(glyph, scaler)) {
                 goto HAS_ATLAS;
             }
@@ -422,7 +422,6 @@ HAS_ATLAS:
     width = SkIntToFixed(width);
     height = SkIntToFixed(height);
 
-    // the current texture/maskformat must match what the glyph needs
     GrTexture* texture = glyph->fPlot->texture();
     SkASSERT(texture);
 
@@ -430,10 +429,9 @@ HAS_ATLAS:
         this->flush();
         fCurrTexture = texture;
         fCurrTexture->ref();
-        fCurrMaskFormat = glyph->fMaskFormat;
     }
 
-    bool useColorVerts = kA8_GrMaskFormat == fCurrMaskFormat;
+    bool useColorVerts = kA8_GrMaskFormat == fStrike->getMaskFormat();
 
     if (NULL == fVertices) {
        // If we need to reserve vertices allow the draw target to suggest
@@ -551,12 +549,12 @@ void GrBitmapTextContext::flush() {
         // This effect could be stored with one of the cache objects (atlas?)
         drawState->setGeometryProcessor(fCachedGeometryProcessor.get());
         SkASSERT(fStrike);
-        switch (fCurrMaskFormat) {
+        switch (fStrike->getMaskFormat()) {
                 // Color bitmap text
             case kARGB_GrMaskFormat:
                 SkASSERT(!drawState->hasColorVertexAttribute());
                 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlendCoeff());
-                drawState->setAlpha(fSkPaint.getAlpha());
+                drawState->setColor(0xffffffff);
                 break;
                 // LCD text
             case kA888_GrMaskFormat:
@@ -587,7 +585,7 @@ void GrBitmapTextContext::flush() {
                 SkASSERT(drawState->hasColorVertexAttribute());
                 break;
             default:
-                SkFAIL("Unexpected mask format.");
+                SkFAIL("Unexepected mask format.");
         }
         int nGlyphs = fCurrVertex / 4;
         fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
index a9805cb..4bff399 100644 (file)
@@ -40,14 +40,13 @@ private:
 
     GrTextStrike*                     fStrike;
     void*                             fVertices;
-    int                               fCurrVertex;
-    int                               fMaxVertices;
-    SkRect                            fVertexBounds;
+    int32_t                           fMaxVertices;
     GrTexture*                        fCurrTexture;
-    GrMaskFormat                      fCurrMaskFormat;
     SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
     // Used to check whether fCachedEffect is still valid.
     uint32_t                          fEffectTextureUniqueID;
+    int                               fCurrVertex;
+    SkRect                            fVertexBounds;
 
     void init(const GrPaint&, const SkPaint&);
     void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*);
index a1f5ce6..baba10d 100755 (executable)
@@ -412,11 +412,6 @@ void GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
         return;
     }
 
-    // TODO: support color glyphs
-    if (kA8_GrMaskFormat != glyph->fMaskFormat) {
-        return;
-    }
-
     SkScalar sx = SkFixedToScalar(vx);
     SkScalar sy = SkFixedToScalar(vy);
 /*
@@ -445,7 +440,7 @@ void GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
             }
 
             // try to clear out an unused plot before we flush
-            if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+            if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
                 fStrike->addGlyphToAtlas(glyph, scaler)) {
                 goto HAS_ATLAS;
             }
@@ -461,7 +456,7 @@ void GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
             fContext->flush();
 
             // we should have an unused plot now
-            if (fContext->getFontCache()->freeUnusedPlot(fStrike, glyph) &&
+            if (fContext->getFontCache()->freeUnusedPlot(fStrike) &&
                 fStrike->addGlyphToAtlas(glyph, scaler)) {
                 goto HAS_ATLAS;
             }
index b16b498..164768f 100644 (file)
@@ -59,7 +59,7 @@ GrFontScaler::~GrFontScaler() {
     SkSafeUnref(fKey);
 }
 
-GrMaskFormat GrFontScaler::getMaskFormat() const {
+GrMaskFormat GrFontScaler::getMaskFormat() {
     SkMask::Format format = fStrike->getMaskFormat();
     switch (format) {
         case SkMask::kBW_Format:
@@ -85,28 +85,6 @@ const GrFontDescKey* GrFontScaler::getKey() {
     return fKey;
 }
 
-GrMaskFormat GrFontScaler::getPackedGlyphMaskFormat(GrGlyph::PackedID packed) const {
-    const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
-                                                      GrGlyph::UnpackFixedX(packed),
-                                                      GrGlyph::UnpackFixedY(packed));
-    SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);
-    switch (format) {
-        case SkMask::kBW_Format:
-            // fall through to kA8 -- we store BW glyphs in our 8-bit cache
-        case SkMask::kA8_Format:
-            return kA8_GrMaskFormat;
-        case SkMask::kLCD16_Format:
-            return kA565_GrMaskFormat;
-        case SkMask::kLCD32_Format:
-            return kA888_GrMaskFormat;
-        case SkMask::kARGB32_Format:
-            return kARGB_GrMaskFormat;
-        default:
-            SkDEBUGFAIL("unsupported SkMask::Format");
-            return kA8_GrMaskFormat;
-    }
-}
-
 bool GrFontScaler::getPackedGlyphBounds(GrGlyph::PackedID packed, SkIRect* bounds) {
     const SkGlyph& glyph = fStrike->getGlyphIDMetrics(GrGlyph::UnpackID(packed),
                                                       GrGlyph::UnpackFixedX(packed),
index 81be341..8ae10cc 100644 (file)
@@ -80,7 +80,20 @@ static int mask_format_to_atlas_index(GrMaskFormat format) {
 }
 
 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler) {
-    GrTextStrike* strike = SkNEW_ARGS(GrTextStrike, (this, scaler->getKey()));
+    GrMaskFormat format = scaler->getMaskFormat();
+    GrPixelConfig config = mask_format_to_pixel_config(format);
+    int atlasIndex = mask_format_to_atlas_index(format);
+    if (NULL == fAtlases[atlasIndex]) {
+        SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH,
+                                            GR_ATLAS_TEXTURE_HEIGHT);
+        fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrTextureFlags,
+                                                    textureSize,
+                                                    GR_NUM_PLOTS_X,
+                                                    GR_NUM_PLOTS_Y,
+                                                    true));
+    }
+    GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
+                                      (this, scaler->getKey(), format, fAtlases[atlasIndex]));
     fCache.add(strike);
 
     if (fHead) {
@@ -117,30 +130,10 @@ void GrFontCache::purgeStrike(GrTextStrike* strike) {
     delete strike;
 }
 
-
-GrPlot* GrFontCache::addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage,
-                                int width, int height, const void* image,
-                                SkIPoint16* loc) {
-    GrPixelConfig config = mask_format_to_pixel_config(format);
-    int atlasIndex = mask_format_to_atlas_index(format);
-    if (NULL == fAtlases[atlasIndex]) {
-        SkISize textureSize = SkISize::Make(GR_ATLAS_TEXTURE_WIDTH,
-                                            GR_ATLAS_TEXTURE_HEIGHT);
-        fAtlases[atlasIndex] = SkNEW_ARGS(GrAtlas, (fGpu, config, kNone_GrTextureFlags,
-                                                    textureSize,
-                                                    GR_NUM_PLOTS_X,
-                                                    GR_NUM_PLOTS_Y,
-                                                    true));
-    }
-    return fAtlases[atlasIndex]->addToAtlas(usage, width, height, image, loc);
-}
-
-
-bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph) {
+bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike) {
     SkASSERT(preserveStrike);
 
-    int index = mask_format_to_atlas_index(glyph->fMaskFormat);
-    GrAtlas* atlas = fAtlases[index];
+    GrAtlas* atlas = preserveStrike->fAtlas;
     GrPlot* plot = atlas->getUnusedPlot();
     if (NULL == plot) {
         return false;
@@ -148,7 +141,13 @@ bool GrFontCache::freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* gl
     plot->resetRects();
 
     GrTextStrike* strike = fHead;
+    GrMaskFormat maskFormat = preserveStrike->fMaskFormat;
     while (strike) {
+        if (maskFormat != strike->fMaskFormat) {
+            strike = strike->fNext;
+            continue;
+        }
+
         GrTextStrike* strikeToPurge = strike;
         strike = strikeToPurge->fNext;
         strikeToPurge->removePlot(plot);
@@ -229,11 +228,16 @@ void GrFontCache::dump() const {
     atlas and a position within that texture.
  */
 
-GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key) : fPool(64) {
+GrTextStrike::GrTextStrike(GrFontCache* cache, const GrFontDescKey* key,
+                           GrMaskFormat format,
+                           GrAtlas* atlas) : fPool(64) {
     fFontScalerKey = key;
     fFontScalerKey->ref();
 
     fFontCache = cache;     // no need to ref, it won't go away before we do
+    fAtlas = atlas;         // no need to ref, it won't go away before we do
+
+    fMaskFormat = format;
 
 #ifdef SK_DEBUG
 //    GrPrintf(" GrTextStrike %p %d\n", this, gCounter);
@@ -267,10 +271,9 @@ GrGlyph* GrTextStrike::generateGlyph(GrGlyph::PackedID packed,
             return NULL;
         }
     }
-    GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed);
-    
+
     GrGlyph* glyph = fPool.alloc();
-    glyph->init(packed, bounds, format);
+    glyph->init(packed, bounds);
     fCache.add(glyph);
     return glyph;
 }
@@ -314,7 +317,7 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
 
     SkAutoUnref ar(SkSafeRef(scaler));
 
-    int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat);
+    int bytesPerPixel = GrMaskFormatBytesPerPixel(fMaskFormat);
 
     size_t size = glyph->fBounds.area() * bytesPerPixel;
     GrAutoMalloc<1024> storage(size);
@@ -334,9 +337,9 @@ bool GrTextStrike::addGlyphToAtlas(GrGlyph* glyph, GrFontScaler* scaler) {
         }
     }
 
-    GrPlot* plot = fFontCache->addToAtlas(glyph->fMaskFormat, &fPlotUsage,
-                                          glyph->width(), glyph->height(),
-                                          storage.get(), &glyph->fAtlasLocation);
+    GrPlot* plot  = fAtlas->addToAtlas(&fPlotUsage, glyph->width(),
+                                       glyph->height(), storage.get(),
+                                       &glyph->fAtlasLocation);
 
     if (NULL == plot) {
         return false;
index 779d676..401bd73 100644 (file)
@@ -23,16 +23,18 @@ class GrGpu;
 class GrFontPurgeListener;
 
 /**
- *  The textstrike maps a hostfontscaler instance to a dictionary of
+ *  The textcache maps a hostfontscaler instance to a dictionary of
  *  glyphid->strike
  */
 class GrTextStrike {
 public:
-    GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey);
+    GrTextStrike(GrFontCache*, const GrFontDescKey* fontScalerKey, GrMaskFormat, GrAtlas*);
     ~GrTextStrike();
 
     const GrFontDescKey* getFontScalerKey() const { return fFontScalerKey; }
     GrFontCache* getFontCache() const { return fFontCache; }
+    GrMaskFormat getMaskFormat() const { return fMaskFormat; }
+    GrTexture*   getTexture() const { return fAtlas->getTexture(); }
 
     inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
     // returns true if glyph (or glyph+padding for distance field)
@@ -65,6 +67,8 @@ private:
     GrTAllocPool<GrGlyph> fPool;
 
     GrFontCache*    fFontCache;
+    GrAtlas*        fAtlas;
+    GrMaskFormat    fMaskFormat;
     bool            fUseDistanceField;
 
     GrAtlas::ClientPlotUsage fPlotUsage;
@@ -81,15 +85,10 @@ public:
 
     inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
 
-    // add to texture atlas that matches this format
-    GrPlot* addToAtlas(GrMaskFormat format, GrAtlas::ClientPlotUsage* usage,
-                       int width, int height, const void* image,
-                       SkIPoint16* loc);
-
     void freeAll();
 
-    // make an unused plot available for this glyph
-    bool freeUnusedPlot(GrTextStrike* preserveStrike, const GrGlyph* glyph);
+    // make an unused plot available
+    bool freeUnusedPlot(GrTextStrike* preserveStrike);
 
     // testing
     int countStrikes() const { return fCache.count(); }