joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrAtlasTextBlob.h" |
| 9 | |
joshualitt | 18b072d | 2015-12-07 12:26:12 -0800 | [diff] [blame^] | 10 | void GrAtlasTextBlob::appendGlyph(Run* run, |
| 11 | Run::SubRunInfo* subRun, |
| 12 | const SkRect& positions, GrColor color, |
| 13 | size_t vertexStride, bool useVertexColor, |
| 14 | GrGlyph* glyph) { |
| 15 | run->fVertexBounds.joinNonEmptyArg(positions); |
| 16 | run->fColor = color; |
| 17 | |
| 18 | intptr_t vertex = reinterpret_cast<intptr_t>(this->fVertices + subRun->vertexEndIndex()); |
| 19 | |
| 20 | if (useVertexColor) { |
| 21 | // V0 |
| 22 | SkPoint* position = reinterpret_cast<SkPoint*>(vertex); |
| 23 | position->set(positions.fLeft, positions.fTop); |
| 24 | SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 25 | *colorPtr = color; |
| 26 | vertex += vertexStride; |
| 27 | |
| 28 | // V1 |
| 29 | position = reinterpret_cast<SkPoint*>(vertex); |
| 30 | position->set(positions.fLeft, positions.fBottom); |
| 31 | colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 32 | *colorPtr = color; |
| 33 | vertex += vertexStride; |
| 34 | |
| 35 | // V2 |
| 36 | position = reinterpret_cast<SkPoint*>(vertex); |
| 37 | position->set(positions.fRight, positions.fBottom); |
| 38 | colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 39 | *colorPtr = color; |
| 40 | vertex += vertexStride; |
| 41 | |
| 42 | // V3 |
| 43 | position = reinterpret_cast<SkPoint*>(vertex); |
| 44 | position->set(positions.fRight, positions.fTop); |
| 45 | colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)); |
| 46 | *colorPtr = color; |
| 47 | } else { |
| 48 | // V0 |
| 49 | SkPoint* position = reinterpret_cast<SkPoint*>(vertex); |
| 50 | position->set(positions.fLeft, positions.fTop); |
| 51 | vertex += vertexStride; |
| 52 | |
| 53 | // V1 |
| 54 | position = reinterpret_cast<SkPoint*>(vertex); |
| 55 | position->set(positions.fLeft, positions.fBottom); |
| 56 | vertex += vertexStride; |
| 57 | |
| 58 | // V2 |
| 59 | position = reinterpret_cast<SkPoint*>(vertex); |
| 60 | position->set(positions.fRight, positions.fBottom); |
| 61 | vertex += vertexStride; |
| 62 | |
| 63 | // V3 |
| 64 | position = reinterpret_cast<SkPoint*>(vertex); |
| 65 | position->set(positions.fRight, positions.fTop); |
| 66 | } |
| 67 | subRun->appendVertices(vertexStride); |
| 68 | fGlyphs[subRun->glyphEndIndex()] = glyph; |
| 69 | subRun->glyphAppended(); |
| 70 | } |
| 71 | |
| 72 | // TODO get this code building again |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 73 | #ifdef CACHE_SANITY_CHECK |
| 74 | void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) { |
| 75 | SkASSERT(l.fSize == r.fSize); |
| 76 | SkASSERT(l.fPool == r.fPool); |
| 77 | |
| 78 | SkASSERT(l.fBlurRec.fSigma == r.fBlurRec.fSigma); |
| 79 | SkASSERT(l.fBlurRec.fStyle == r.fBlurRec.fStyle); |
| 80 | SkASSERT(l.fBlurRec.fQuality == r.fBlurRec.fQuality); |
| 81 | |
| 82 | SkASSERT(l.fStrokeInfo.fFrameWidth == r.fStrokeInfo.fFrameWidth); |
| 83 | SkASSERT(l.fStrokeInfo.fMiterLimit == r.fStrokeInfo.fMiterLimit); |
| 84 | SkASSERT(l.fStrokeInfo.fJoin == r.fStrokeInfo.fJoin); |
| 85 | |
| 86 | SkASSERT(l.fBigGlyphs.count() == r.fBigGlyphs.count()); |
| 87 | for (int i = 0; i < l.fBigGlyphs.count(); i++) { |
| 88 | const BigGlyph& lBigGlyph = l.fBigGlyphs[i]; |
| 89 | const BigGlyph& rBigGlyph = r.fBigGlyphs[i]; |
| 90 | |
| 91 | SkASSERT(lBigGlyph.fPath == rBigGlyph.fPath); |
| 92 | // We can't assert that these have the same translations |
| 93 | } |
| 94 | |
| 95 | SkASSERT(l.fKey == r.fKey); |
| 96 | SkASSERT(l.fViewMatrix.cheapEqualTo(r.fViewMatrix)); |
| 97 | SkASSERT(l.fPaintColor == r.fPaintColor); |
| 98 | SkASSERT(l.fMaxMinScale == r.fMaxMinScale); |
| 99 | SkASSERT(l.fMinMaxScale == r.fMinMaxScale); |
| 100 | SkASSERT(l.fTextType == r.fTextType); |
| 101 | |
| 102 | SkASSERT(l.fRunCount == r.fRunCount); |
| 103 | for (int i = 0; i < l.fRunCount; i++) { |
| 104 | const Run& lRun = l.fRuns[i]; |
| 105 | const Run& rRun = r.fRuns[i]; |
| 106 | |
| 107 | if (lRun.fStrike.get()) { |
| 108 | SkASSERT(rRun.fStrike.get()); |
| 109 | SkASSERT(GrBatchTextStrike::GetKey(*lRun.fStrike) == |
| 110 | GrBatchTextStrike::GetKey(*rRun.fStrike)); |
| 111 | |
| 112 | } else { |
| 113 | SkASSERT(!rRun.fStrike.get()); |
| 114 | } |
| 115 | |
| 116 | if (lRun.fTypeface.get()) { |
| 117 | SkASSERT(rRun.fTypeface.get()); |
| 118 | SkASSERT(SkTypeface::Equal(lRun.fTypeface, rRun.fTypeface)); |
| 119 | } else { |
| 120 | SkASSERT(!rRun.fTypeface.get()); |
| 121 | } |
| 122 | |
joshualitt | 7e7b5c5 | 2015-07-21 12:56:56 -0700 | [diff] [blame] | 123 | // We offset bounds right before flush time so they will not be correct here |
joshualitt | 259fbf1 | 2015-07-21 11:39:34 -0700 | [diff] [blame] | 124 | //SkASSERT(lRun.fVertexBounds == rRun.fVertexBounds); |
| 125 | |
| 126 | SkASSERT(lRun.fDescriptor.getDesc()); |
| 127 | SkASSERT(rRun.fDescriptor.getDesc()); |
| 128 | SkASSERT(lRun.fDescriptor.getDesc()->equals(*rRun.fDescriptor.getDesc())); |
| 129 | |
| 130 | if (lRun.fOverrideDescriptor.get()) { |
| 131 | SkASSERT(lRun.fOverrideDescriptor->getDesc()); |
| 132 | SkASSERT(rRun.fOverrideDescriptor.get() && rRun.fOverrideDescriptor->getDesc());; |
| 133 | SkASSERT(lRun.fOverrideDescriptor->getDesc()->equals( |
| 134 | *rRun.fOverrideDescriptor->getDesc())); |
| 135 | } else { |
| 136 | SkASSERT(!rRun.fOverrideDescriptor.get()); |
| 137 | } |
| 138 | |
| 139 | // color can be changed |
| 140 | //SkASSERT(lRun.fColor == rRun.fColor); |
| 141 | SkASSERT(lRun.fInitialized == rRun.fInitialized); |
| 142 | SkASSERT(lRun.fDrawAsPaths == rRun.fDrawAsPaths); |
| 143 | |
| 144 | SkASSERT(lRun.fSubRunInfo.count() == rRun.fSubRunInfo.count()); |
| 145 | for(int j = 0; j < lRun.fSubRunInfo.count(); j++) { |
| 146 | const Run::SubRunInfo& lSubRun = lRun.fSubRunInfo[j]; |
| 147 | const Run::SubRunInfo& rSubRun = rRun.fSubRunInfo[j]; |
| 148 | |
| 149 | SkASSERT(lSubRun.fVertexStartIndex == rSubRun.fVertexStartIndex); |
| 150 | SkASSERT(lSubRun.fVertexEndIndex == rSubRun.fVertexEndIndex); |
| 151 | SkASSERT(lSubRun.fGlyphStartIndex == rSubRun.fGlyphStartIndex); |
| 152 | SkASSERT(lSubRun.fGlyphEndIndex == rSubRun.fGlyphEndIndex); |
| 153 | SkASSERT(lSubRun.fTextRatio == rSubRun.fTextRatio); |
| 154 | SkASSERT(lSubRun.fMaskFormat == rSubRun.fMaskFormat); |
| 155 | SkASSERT(lSubRun.fDrawAsDistanceFields == rSubRun.fDrawAsDistanceFields); |
| 156 | SkASSERT(lSubRun.fUseLCDText == rSubRun.fUseLCDText); |
| 157 | |
| 158 | //We can't compare the bulk use tokens with this method |
| 159 | /* |
| 160 | SkASSERT(lSubRun.fBulkUseToken.fPlotsToUpdate.count() == |
| 161 | rSubRun.fBulkUseToken.fPlotsToUpdate.count()); |
| 162 | SkASSERT(lSubRun.fBulkUseToken.fPlotAlreadyUpdated == |
| 163 | rSubRun.fBulkUseToken.fPlotAlreadyUpdated); |
| 164 | for (int k = 0; k < lSubRun.fBulkUseToken.fPlotsToUpdate.count(); k++) { |
| 165 | SkASSERT(lSubRun.fBulkUseToken.fPlotsToUpdate[k] == |
| 166 | rSubRun.fBulkUseToken.fPlotsToUpdate[k]); |
| 167 | }*/ |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | #endif |