1
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 */
8
9
10
11#ifndef GrTextStrike_impl_DEFINED
12#define GrTextStrike_impl_DEFINED
13
14void GrFontCache::detachStrikeFromList(GrTextStrike* strike) {
15    if (strike->fPrev) {
16        SkASSERT(fHead != strike);
17        strike->fPrev->fNext = strike->fNext;
18    } else {
19        SkASSERT(fHead == strike);
20        fHead = strike->fNext;
21    }
22
23    if (strike->fNext) {
24        SkASSERT(fTail != strike);
25        strike->fNext->fPrev = strike->fPrev;
26    } else {
27        SkASSERT(fTail == strike);
28        fTail = strike->fPrev;
29    }
30}
31
32GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler, bool useDistanceField) {
33    this->validate();
34
35    GrTextStrike* strike = fCache.find(*(scaler->getKey()));
36    if (NULL == strike) {
37        strike = this->generateStrike(scaler);
38    } else if (strike->fPrev) {
39        // Need to put the strike at the head of its dllist, since that is how
40        // we age the strikes for purging (we purge from the back of the list)
41        this->detachStrikeFromList(strike);
42        // attach at the head
43        fHead->fPrev = strike;
44        strike->fNext = fHead;
45        strike->fPrev = NULL;
46        fHead = strike;
47    }
48    strike->fUseDistanceField = useDistanceField;
49    this->validate();
50    return strike;
51}
52
53///////////////////////////////////////////////////////////////////////////////
54
55GrGlyph* GrTextStrike::getGlyph(GrGlyph::PackedID packed,
56                                GrFontScaler* scaler) {
57    GrGlyph* glyph = fCache.find(packed);
58    if (NULL == glyph) {
59        glyph = this->generateGlyph(packed, scaler);
60    }
61    return glyph;
62}
63
64#endif
65