aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrAtlasTextBlob.cpp
blob: 21f297580534efc22d46043bdb0cfe7b38611532 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrAtlasTextBlob.h"

void GrAtlasTextBlob::appendGlyph(Run* run,
                                  Run::SubRunInfo* subRun,
                                  const SkRect& positions, GrColor color,
                                  size_t vertexStride, bool useVertexColor,
                                  GrGlyph* glyph) {
    run->fVertexBounds.joinNonEmptyArg(positions);
    run->fColor = color;

    intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex());

    if (useVertexColor) {
        // V0
        SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fLeft, positions.fTop);
        SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
        *colorPtr = color;
        vertex += vertexStride;

        // V1
        position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fLeft, positions.fBottom);
        colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
        *colorPtr = color;
        vertex += vertexStride;

        // V2
        position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fRight, positions.fBottom);
        colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
        *colorPtr = color;
        vertex += vertexStride;

        // V3
        position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fRight, positions.fTop);
        colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
        *colorPtr = color;
    } else {
        // V0
        SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fLeft, positions.fTop);
        vertex += vertexStride;

        // V1
        position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fLeft, positions.fBottom);
        vertex += vertexStride;

        // V2
        position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fRight, positions.fBottom);
        vertex += vertexStride;

        // V3
        position = reinterpret_cast<SkPoint*>(vertex);
        position->set(positions.fRight, positions.fTop);
    }
    subRun->appendVertices(vertexStride);
    fGlyphs[subRun->glyphEndIndex()] = glyph;
    subRun->glyphAppended();
}

// TODO get this code building again
#ifdef CACHE_SANITY_CHECK
void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) {
    SkASSERT(l.fSize == r.fSize);
    SkASSERT(l.fPool == r.fPool);

    SkASSERT(l.fBlurRec.fSigma == r.fBlurRec.fSigma);
    SkASSERT(l.fBlurRec.fStyle == r.fBlurRec.fStyle);
    SkASSERT(l.fBlurRec.fQuality == r.fBlurRec.fQuality);

    SkASSERT(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth);
    SkASSERT(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit);
    SkASSERT(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin);

    SkASSERT(l.fBigGlyphs.count() == r.fBigGlyphs.count());
    for (int i = 0; i < l.fBigGlyphs.count(); i++) {
        const BigGlyph& lBigGlyph = l.fBigGlyphs[i];
        const BigGlyph& rBigGlyph = r.fBigGlyphs[i];

        SkASSERT(lBigGlyph.fPath == rBigGlyph.fPath);
        // We can't assert that these have the same translations
    }

    SkASSERT(l.fKey == r.fKey);
    SkASSERT(l.fViewMatrix.cheapEqualTo(r.fViewMatrix));
    SkASSERT(l.fPaintColor == r.fPaintColor);
    SkASSERT(l.fMaxMinScale == r.fMaxMinScale);
    SkASSERT(l.fMinMaxScale == r.fMinMaxScale);
    SkASSERT(l.fTextType == r.fTextType);

    SkASSERT(l.fRunCount == r.fRunCount);
    for (int i = 0; i < l.fRunCount; i++) {
        const Run& lRun = l.fRuns[i];
        const Run& rRun = r.fRuns[i];

        if (lRun.fStrike.get()) {
            SkASSERT(rRun.fStrike.get());
            SkASSERT(GrBatchTextStrike::GetKey(*lRun.fStrike) ==
                     GrBatchTextStrike::GetKey(*rRun.fStrike));

        } else {
            SkASSERT(!rRun.fStrike.get());
        }

        if (lRun.fTypeface.get()) {
            SkASSERT(rRun.fTypeface.get());
            SkASSERT(SkTypeface::Equal(lRun.fTypeface, rRun.fTypeface));
        } else {
            SkASSERT(!rRun.fTypeface.get());
        }

        // We offset bounds right before flush time so they will not be correct here
        //SkASSERT(lRun.fVertexBounds == rRun.fVertexBounds);

        SkASSERT(lRun.fDescriptor.getDesc());
        SkASSERT(rRun.fDescriptor.getDesc());
        SkASSERT(lRun.fDescriptor.getDesc()->equals(*rRun.fDescriptor.getDesc()));

        if (lRun.fOverrideDescriptor.get()) {
            SkASSERT(lRun.fOverrideDescriptor->getDesc());
            SkASSERT(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());;
            SkASSERT(lRun.fOverrideDescriptor->getDesc()->equals(
                    *rRun.fOverrideDescriptor->getDesc()));
        } else {
            SkASSERT(!rRun.fOverrideDescriptor.get());
        }

        // color can be changed
        //SkASSERT(lRun.fColor == rRun.fColor);
        SkASSERT(lRun.fInitialized == rRun.fInitialized);
        SkASSERT(lRun.fDrawAsPaths == rRun.fDrawAsPaths);

        SkASSERT(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count());
        for(int j = 0; j < lRun.fSubRunInfo.count(); j++) {
            const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j];
            const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j];

            SkASSERT(lSubRun.fVertexStartIndex == rSubRun.fVertexStartIndex);
            SkASSERT(lSubRun.fVertexEndIndex == rSubRun.fVertexEndIndex);
            SkASSERT(lSubRun.fGlyphStartIndex == rSubRun.fGlyphStartIndex);
            SkASSERT(lSubRun.fGlyphEndIndex == rSubRun.fGlyphEndIndex);
            SkASSERT(lSubRun.fTextRatio == rSubRun.fTextRatio);
            SkASSERT(lSubRun.fMaskFormat == rSubRun.fMaskFormat);
            SkASSERT(lSubRun.fDrawAsDistanceFields == rSubRun.fDrawAsDistanceFields);
            SkASSERT(lSubRun.fUseLCDText == rSubRun.fUseLCDText);

            //We can't compare the bulk use tokens with this method
            /*
            SkASSERT(lSubRun.fBulkUseToken.fPlotsToUpdate.count() ==
                     rSubRun.fBulkUseToken.fPlotsToUpdate.count());
            SkASSERT(lSubRun.fBulkUseToken.fPlotAlreadyUpdated ==
                     rSubRun.fBulkUseToken.fPlotAlreadyUpdated);
            for (int k = 0; k < lSubRun.fBulkUseToken.fPlotsToUpdate.count(); k++) {
                SkASSERT(lSubRun.fBulkUseToken.fPlotsToUpdate[k] ==
                         rSubRun.fBulkUseToken.fPlotsToUpdate[k]);
            }*/
        }
    }
}

#endif