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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/GrTextStrike.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +
    1.14 +#ifndef GrTextStrike_DEFINED
    1.15 +#define GrTextStrike_DEFINED
    1.16 +
    1.17 +#include "GrAllocPool.h"
    1.18 +#include "GrFontScaler.h"
    1.19 +#include "GrTHashTable.h"
    1.20 +#include "GrPoint.h"
    1.21 +#include "GrGlyph.h"
    1.22 +#include "GrDrawTarget.h"
    1.23 +#include "GrAtlas.h"
    1.24 +
    1.25 +class GrFontCache;
    1.26 +class GrGpu;
    1.27 +class GrFontPurgeListener;
    1.28 +
    1.29 +/**
    1.30 + *  The textcache maps a hostfontscaler instance to a dictionary of
    1.31 + *  glyphid->strike
    1.32 + */
    1.33 +class GrTextStrike {
    1.34 +public:
    1.35 +    GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat, GrAtlasMgr*);
    1.36 +    ~GrTextStrike();
    1.37 +
    1.38 +    const GrKey* getFontScalerKey() const { return fFontScalerKey; }
    1.39 +    GrFontCache* getFontCache() const { return fFontCache; }
    1.40 +    GrMaskFormat getMaskFormat() const { return fMaskFormat; }
    1.41 +
    1.42 +    inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
    1.43 +    bool addGlyphToAtlas(GrGlyph*, GrFontScaler*);
    1.44 +
    1.45 +    SkISize getAtlasSize() const { return fAtlas.getSize(); }
    1.46 +
    1.47 +    // testing
    1.48 +    int countGlyphs() const { return fCache.getArray().count(); }
    1.49 +    const GrGlyph* glyphAt(int index) const {
    1.50 +        return fCache.getArray()[index];
    1.51 +    }
    1.52 +
    1.53 +    // remove any references to this plot
    1.54 +    void removePlot(const GrPlot* plot);
    1.55 +
    1.56 +public:
    1.57 +    // for easy removal from list
    1.58 +    GrTextStrike*   fPrev;
    1.59 +    GrTextStrike*   fNext;
    1.60 +
    1.61 +private:
    1.62 +    class Key;
    1.63 +    GrTHashTable<GrGlyph, Key, 7> fCache;
    1.64 +    const GrKey* fFontScalerKey;
    1.65 +    GrTAllocPool<GrGlyph> fPool;
    1.66 +
    1.67 +    GrFontCache*    fFontCache;
    1.68 +    GrAtlasMgr*     fAtlasMgr;
    1.69 +    GrMaskFormat    fMaskFormat;
    1.70 +    bool            fUseDistanceField;
    1.71 +
    1.72 +    GrAtlas         fAtlas;
    1.73 +
    1.74 +    GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
    1.75 +
    1.76 +    friend class GrFontCache;
    1.77 +};
    1.78 +
    1.79 +class GrFontCache {
    1.80 +public:
    1.81 +    GrFontCache(GrGpu*);
    1.82 +    ~GrFontCache();
    1.83 +
    1.84 +    inline GrTextStrike* getStrike(GrFontScaler*, bool useDistanceField);
    1.85 +
    1.86 +    void freeAll();
    1.87 +
    1.88 +    // make an unused plot available
    1.89 +    bool freeUnusedPlot(GrTextStrike* preserveStrike);
    1.90 +
    1.91 +    // testing
    1.92 +    int countStrikes() const { return fCache.getArray().count(); }
    1.93 +    const GrTextStrike* strikeAt(int index) const {
    1.94 +        return fCache.getArray()[index];
    1.95 +    }
    1.96 +    GrTextStrike* getHeadStrike() const { return fHead; }
    1.97 +
    1.98 +#ifdef SK_DEBUG
    1.99 +    void validate() const;
   1.100 +#else
   1.101 +    void validate() const {}
   1.102 +#endif
   1.103 +
   1.104 +#ifdef SK_DEVELOPER
   1.105 +    void dump() const;
   1.106 +#endif
   1.107 +
   1.108 +    enum AtlasType {
   1.109 +        kA8_AtlasType,   //!< 1-byte per pixel
   1.110 +        k565_AtlasType,  //!< 2-bytes per pixel
   1.111 +        k8888_AtlasType, //!< 4-bytes per pixel
   1.112 +
   1.113 +        kLast_AtlasType = k8888_AtlasType
   1.114 +    };
   1.115 +    static const int kAtlasCount = kLast_AtlasType + 1;
   1.116 +
   1.117 +private:
   1.118 +    friend class GrFontPurgeListener;
   1.119 +
   1.120 +    class Key;
   1.121 +    GrTHashTable<GrTextStrike, Key, 8> fCache;
   1.122 +    // for LRU
   1.123 +    GrTextStrike* fHead;
   1.124 +    GrTextStrike* fTail;
   1.125 +
   1.126 +    GrGpu*      fGpu;
   1.127 +    GrAtlasMgr* fAtlasMgr[kAtlasCount];
   1.128 +
   1.129 +    GrTextStrike* generateStrike(GrFontScaler*, const Key&);
   1.130 +    inline void detachStrikeFromList(GrTextStrike*);
   1.131 +    void purgeStrike(GrTextStrike* strike);
   1.132 +};
   1.133 +
   1.134 +#endif

mercurial