gfx/skia/trunk/src/gpu/GrTextStrike.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     2 /*
     3  * Copyright 2010 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
    11 #ifndef GrTextStrike_DEFINED
    12 #define GrTextStrike_DEFINED
    14 #include "GrAllocPool.h"
    15 #include "GrFontScaler.h"
    16 #include "GrTHashTable.h"
    17 #include "GrPoint.h"
    18 #include "GrGlyph.h"
    19 #include "GrDrawTarget.h"
    20 #include "GrAtlas.h"
    22 class GrFontCache;
    23 class GrGpu;
    24 class GrFontPurgeListener;
    26 /**
    27  *  The textcache maps a hostfontscaler instance to a dictionary of
    28  *  glyphid->strike
    29  */
    30 class GrTextStrike {
    31 public:
    32     GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
    33     ~GrTextStrike();
    35     const GrKey* getFontScalerKey() const { return fFontScalerKey; }
    36     GrFontCache* getFontCache() const { return fFontCache; }
    37     GrMaskFormat getMaskFormat() const { return fMaskFormat; }
    39     inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
    40     bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
    42     SkISize getAtlasSize() const { return fAtlas.getSize(); }
    44     // testing
    45     int countGlyphs() const { return fCache.getArray().count(); }
    46     const GrGlyph* glyphAt(int index) const {
    47         return fCache.getArray()[index];
    48     }
    50     // remove any references to this plot
    51     void removePlot(const GrPlot* plot);
    53 public:
    54     // for easy removal from list
    55     GrTextStrike*   fPrev;
    56     GrTextStrike*   fNext;
    58 private:
    59     class Key;
    60     GrTHashTable<GrGlyph, Key, 7> fCache;
    61     const GrKey* fFontScalerKey;
    62     GrTAllocPool<GrGlyph> fPool;
    64     GrFontCache*    fFontCache;
    65     GrAtlasMgr*     fAtlasMgr;
    66     GrMaskFormat    fMaskFormat;
    67     bool            fUseDistanceField;
    69     GrAtlas         fAtlas;
    71     GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
    73     friend class GrFontCache;
    74 };
    76 class GrFontCache {
    77 public:
    78     GrFontCache(GrGpu*);
    79     ~GrFontCache();
    81     inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
    83     void freeAll();
    85     // make an unused plot available
    86     bool freeUnusedPlot(GrTextStrike* preserveStrike);
    88     // testing
    89     int countStrikes() const { return fCache.getArray().count(); }
    90     const GrTextStrike* strikeAt(int index) const {
    91         return fCache.getArray()[index];
    92     }
    93     GrTextStrike* getHeadStrike() const { return fHead; }
    95 #ifdef SK_DEBUG
    96     void validate() const;
    97 #else
    98     void validate() const {}
    99 #endif
   101 #ifdef SK_DEVELOPER
   102     void dump() const;
   103 #endif
   105     enum AtlasType {
   106         kA8_AtlasType,   //!< 1-byte per pixel
   107         k565_AtlasType,  //!< 2-bytes per pixel
   108         k8888_AtlasType, //!< 4-bytes per pixel
   110         kLast_AtlasType = k8888_AtlasType
   111     };
   112     static const int kAtlasCount = kLast_AtlasType + 1;
   114 private:
   115     friend class GrFontPurgeListener;
   117     class Key;
   118     GrTHashTable<GrTextStrike, Key, 8> fCache;
   119     // for LRU
   120     GrTextStrike* fHead;
   121     GrTextStrike* fTail;
   123     GrGpu*      fGpu;
   124     GrAtlasMgr* fAtlasMgr[kAtlasCount];
   126     GrTextStrike* generateStrike(GrFontScaler*, const Key&);
   127     inline void detachStrikeFromList(GrTextStrike*);
   128     void purgeStrike(GrTextStrike* strike);
   129 };
   131 #endif

mercurial