joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [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 | |
Brian Salomon | 09e019e | 2016-12-15 10:20:35 -0500 | [diff] [blame] | 8 | #include "GrAtlasTextOp.h" |
Robert Phillips | e4fda6c | 2018-02-21 12:10:41 -0500 | [diff] [blame] | 9 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 10 | #include "GrContext.h" |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 11 | #include "GrContextPriv.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 12 | #include "GrMemoryPool.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 13 | #include "GrOpFlushState.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 14 | #include "GrResourceProvider.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 15 | #include "SkMathPriv.h" |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 16 | #include "SkMatrixPriv.h" |
| 17 | #include "SkPoint3.h" |
Herb Derby | dce19a7 | 2018-04-18 16:02:17 -0400 | [diff] [blame] | 18 | #include "SkStrikeCache.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 19 | #include "effects/GrBitmapTextGeoProc.h" |
| 20 | #include "effects/GrDistanceFieldGeoProc.h" |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 21 | #include "text/GrAtlasManager.h" |
| 22 | #include "text/GrGlyphCache.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 23 | |
joshualitt | 60ce86d | 2015-11-23 13:08:22 -0800 | [diff] [blame] | 24 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 25 | |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 26 | std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeBitmap(GrContext* context, |
| 27 | GrPaint&& paint, |
| 28 | GrMaskFormat maskFormat, |
| 29 | int glyphCount, |
| 30 | bool needsTransform) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 31 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 32 | |
| 33 | std::unique_ptr<GrAtlasTextOp> op = pool->allocate<GrAtlasTextOp>(std::move(paint)); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 34 | |
| 35 | switch (maskFormat) { |
| 36 | case kA8_GrMaskFormat: |
| 37 | op->fMaskType = kGrayscaleCoverageMask_MaskType; |
| 38 | break; |
| 39 | case kA565_GrMaskFormat: |
| 40 | op->fMaskType = kLCDCoverageMask_MaskType; |
| 41 | break; |
| 42 | case kARGB_GrMaskFormat: |
| 43 | op->fMaskType = kColorBitmapMask_MaskType; |
| 44 | break; |
| 45 | } |
| 46 | op->fNumGlyphs = glyphCount; |
| 47 | op->fGeoCount = 1; |
| 48 | op->fLuminanceColor = 0; |
| 49 | op->fNeedsGlyphTransform = needsTransform; |
| 50 | return op; |
| 51 | } |
| 52 | |
| 53 | std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeDistanceField( |
| 54 | GrContext* context, |
| 55 | GrPaint&& paint, |
| 56 | int glyphCount, |
| 57 | const GrDistanceFieldAdjustTable* distanceAdjustTable, |
| 58 | bool useGammaCorrectDistanceTable, |
| 59 | SkColor luminanceColor, |
| 60 | const SkSurfaceProps& props, |
| 61 | bool isAntiAliased, |
| 62 | bool useLCD) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 63 | GrOpMemoryPool* pool = context->contextPriv().opMemoryPool(); |
| 64 | |
| 65 | std::unique_ptr<GrAtlasTextOp> op = pool->allocate<GrAtlasTextOp>(std::move(paint)); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 66 | |
| 67 | bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); |
| 68 | bool isLCD = useLCD && SkPixelGeometryIsH(props.pixelGeometry()); |
| 69 | op->fMaskType = !isAntiAliased ? kAliasedDistanceField_MaskType |
| 70 | : isLCD ? (isBGR ? kLCDBGRDistanceField_MaskType |
| 71 | : kLCDDistanceField_MaskType) |
| 72 | : kGrayscaleDistanceField_MaskType; |
| 73 | op->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); |
| 74 | op->fUseGammaCorrectDistanceTable = useGammaCorrectDistanceTable; |
| 75 | op->fLuminanceColor = luminanceColor; |
| 76 | op->fNumGlyphs = glyphCount; |
| 77 | op->fGeoCount = 1; |
| 78 | return op; |
| 79 | } |
| 80 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 81 | static const int kDistanceAdjustLumShift = 5; |
| 82 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 83 | void GrAtlasTextOp::init() { |
| 84 | const Geometry& geo = fGeoData[0]; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 85 | if (this->usesDistanceFields()) { |
| 86 | bool isLCD = this->isLCD(); |
| 87 | |
| 88 | const SkMatrix& viewMatrix = geo.fViewMatrix; |
| 89 | |
| 90 | fDFGPFlags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 91 | fDFGPFlags |= viewMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0; |
| 92 | fDFGPFlags |= viewMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0; |
| 93 | fDFGPFlags |= fUseGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0; |
| 94 | fDFGPFlags |= (kAliasedDistanceField_MaskType == fMaskType) |
| 95 | ? kAliased_DistanceFieldEffectFlag |
| 96 | : 0; |
| 97 | |
| 98 | if (isLCD) { |
| 99 | fDFGPFlags |= kUseLCD_DistanceFieldEffectFlag; |
| 100 | fDFGPFlags |= |
| 101 | (kLCDBGRDistanceField_MaskType == fMaskType) ? kBGR_DistanceFieldEffectFlag : 0; |
| 102 | } |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 103 | |
| 104 | fNeedsGlyphTransform = true; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 105 | } |
Jim Van Verth | 7027691 | 2018-06-01 13:46:46 -0400 | [diff] [blame] | 106 | |
| 107 | SkRect bounds; |
| 108 | geo.fBlob->computeSubRunBounds(&bounds, geo.fRun, geo.fSubRun, geo.fViewMatrix, geo.fX, geo.fY, |
| 109 | fNeedsGlyphTransform); |
| 110 | // We don't have tight bounds on the glyph paths in device space. For the purposes of bounds |
| 111 | // we treat this as a set of non-AA rects rendered with a texture. |
| 112 | this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 113 | } |
| 114 | |
Robert Phillips | e4fda6c | 2018-02-21 12:10:41 -0500 | [diff] [blame] | 115 | void GrAtlasTextOp::visitProxies(const VisitProxyFunc& func) const { |
| 116 | fProcessors.visitProxies(func); |
Robert Phillips | e4fda6c | 2018-02-21 12:10:41 -0500 | [diff] [blame] | 117 | } |
| 118 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 119 | SkString GrAtlasTextOp::dumpInfo() const { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 120 | SkString str; |
| 121 | |
| 122 | for (int i = 0; i < fGeoCount; ++i) { |
| 123 | str.appendf("%d: Color: 0x%08x Trans: %.2f,%.2f Runs: %d\n", |
| 124 | i, |
| 125 | fGeoData[i].fColor, |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 126 | fGeoData[i].fX, |
| 127 | fGeoData[i].fY, |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 128 | fGeoData[i].fBlob->runCount()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 131 | str += fProcessors.dumpProcessors(); |
| 132 | str += INHERITED::dumpInfo(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 133 | return str; |
| 134 | } |
| 135 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 136 | GrDrawOp::FixedFunctionFlags GrAtlasTextOp::fixedFunctionFlags() const { |
| 137 | return FixedFunctionFlags::kNone; |
| 138 | } |
| 139 | |
| 140 | GrDrawOp::RequiresDstTexture GrAtlasTextOp::finalize(const GrCaps& caps, |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 141 | const GrAppliedClip* clip) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 142 | GrProcessorAnalysisCoverage coverage; |
| 143 | GrProcessorAnalysisColor color; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 144 | if (kColorBitmapMask_MaskType == fMaskType) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 145 | color.setToUnknown(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 146 | } else { |
Brian Osman | 0906825 | 2018-01-03 09:57:29 -0500 | [diff] [blame] | 147 | color.setToConstant(this->color()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 148 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 149 | switch (fMaskType) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 150 | case kGrayscaleCoverageMask_MaskType: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 151 | case kAliasedDistanceField_MaskType: |
| 152 | case kGrayscaleDistanceField_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 153 | coverage = GrProcessorAnalysisCoverage::kSingleChannel; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 154 | break; |
| 155 | case kLCDCoverageMask_MaskType: |
| 156 | case kLCDDistanceField_MaskType: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 157 | case kLCDBGRDistanceField_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 158 | coverage = GrProcessorAnalysisCoverage::kLCD; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 159 | break; |
| 160 | case kColorBitmapMask_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 161 | coverage = GrProcessorAnalysisCoverage::kNone; |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 162 | break; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 163 | } |
Brian Osman | 532b3f9 | 2018-07-11 10:02:07 -0400 | [diff] [blame] | 164 | auto analysis = fProcessors.finalize(color, coverage, clip, false, caps, &fGeoData[0].fColor); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 165 | fUsesLocalCoords = analysis.usesLocalCoords(); |
| 166 | fCanCombineOnTouchOrOverlap = |
| 167 | !analysis.requiresDstTexture() && |
| 168 | !(fProcessors.xferProcessor() && fProcessors.xferProcessor()->xferBarrierType(caps)); |
| 169 | return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 172 | static void clip_quads(const SkIRect& clipRect, char* currVertex, const char* blobVertices, |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 173 | size_t vertexStride, int glyphCount) { |
| 174 | for (int i = 0; i < glyphCount; ++i) { |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 175 | const SkPoint* blobPositionLT = reinterpret_cast<const SkPoint*>(blobVertices); |
| 176 | const SkPoint* blobPositionRB = |
| 177 | reinterpret_cast<const SkPoint*>(blobVertices + 3 * vertexStride); |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 178 | |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 179 | // positions for bitmap glyphs are pixel boundary aligned |
Brian Osman | 7ca90d2 | 2017-11-10 15:31:27 -0500 | [diff] [blame] | 180 | SkIRect positionRect = SkIRect::MakeLTRB(SkScalarRoundToInt(blobPositionLT->fX), |
| 181 | SkScalarRoundToInt(blobPositionLT->fY), |
| 182 | SkScalarRoundToInt(blobPositionRB->fX), |
| 183 | SkScalarRoundToInt(blobPositionRB->fY)); |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 184 | if (clipRect.contains(positionRect)) { |
| 185 | memcpy(currVertex, blobVertices, 4 * vertexStride); |
| 186 | currVertex += 4 * vertexStride; |
| 187 | } else { |
| 188 | // Pull out some more data that we'll need. |
| 189 | // In the LCD case the color will be garbage, but we'll overwrite it with the texcoords |
| 190 | // and it avoids a lot of conditionals. |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 191 | auto color = *reinterpret_cast<const SkColor*>(blobVertices + sizeof(SkPoint)); |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 192 | size_t coordOffset = vertexStride - 2*sizeof(uint16_t); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 193 | auto* blobCoordsLT = reinterpret_cast<const uint16_t*>(blobVertices + coordOffset); |
| 194 | auto* blobCoordsRB = reinterpret_cast<const uint16_t*>(blobVertices + 3 * vertexStride + |
| 195 | coordOffset); |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 196 | // Pull out the texel coordinates and texture index bits |
| 197 | uint16_t coordsRectL = blobCoordsLT[0] >> 1; |
| 198 | uint16_t coordsRectT = blobCoordsLT[1] >> 1; |
| 199 | uint16_t coordsRectR = blobCoordsRB[0] >> 1; |
| 200 | uint16_t coordsRectB = blobCoordsRB[1] >> 1; |
| 201 | uint16_t pageIndexX = blobCoordsLT[0] & 0x1; |
| 202 | uint16_t pageIndexY = blobCoordsLT[1] & 0x1; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 203 | |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 204 | int positionRectWidth = positionRect.width(); |
| 205 | int positionRectHeight = positionRect.height(); |
| 206 | SkASSERT(positionRectWidth == (coordsRectR - coordsRectL)); |
| 207 | SkASSERT(positionRectHeight == (coordsRectB - coordsRectT)); |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 208 | |
| 209 | // Clip position and texCoords to the clipRect |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 210 | unsigned int delta; |
| 211 | delta = SkTMin(SkTMax(clipRect.fLeft - positionRect.fLeft, 0), positionRectWidth); |
| 212 | coordsRectL += delta; |
| 213 | positionRect.fLeft += delta; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 214 | |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 215 | delta = SkTMin(SkTMax(clipRect.fTop - positionRect.fTop, 0), positionRectHeight); |
| 216 | coordsRectT += delta; |
| 217 | positionRect.fTop += delta; |
| 218 | |
| 219 | delta = SkTMin(SkTMax(positionRect.fRight - clipRect.fRight, 0), positionRectWidth); |
| 220 | coordsRectR -= delta; |
| 221 | positionRect.fRight -= delta; |
| 222 | |
| 223 | delta = SkTMin(SkTMax(positionRect.fBottom - clipRect.fBottom, 0), positionRectHeight); |
| 224 | coordsRectB -= delta; |
| 225 | positionRect.fBottom -= delta; |
| 226 | |
| 227 | // Repack texel coordinates and index |
| 228 | coordsRectL = coordsRectL << 1 | pageIndexX; |
| 229 | coordsRectT = coordsRectT << 1 | pageIndexY; |
| 230 | coordsRectR = coordsRectR << 1 | pageIndexX; |
| 231 | coordsRectB = coordsRectB << 1 | pageIndexY; |
| 232 | |
| 233 | // Set new positions and coords |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 234 | SkPoint* currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 235 | currPosition->fX = positionRect.fLeft; |
| 236 | currPosition->fY = positionRect.fTop; |
| 237 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 238 | uint16_t* currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset); |
| 239 | currCoords[0] = coordsRectL; |
| 240 | currCoords[1] = coordsRectT; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 241 | currVertex += vertexStride; |
| 242 | |
| 243 | currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 244 | currPosition->fX = positionRect.fLeft; |
| 245 | currPosition->fY = positionRect.fBottom; |
| 246 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 247 | currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset); |
| 248 | currCoords[0] = coordsRectL; |
| 249 | currCoords[1] = coordsRectB; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 250 | currVertex += vertexStride; |
| 251 | |
| 252 | currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 253 | currPosition->fX = positionRect.fRight; |
| 254 | currPosition->fY = positionRect.fTop; |
| 255 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 256 | currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset); |
| 257 | currCoords[0] = coordsRectR; |
| 258 | currCoords[1] = coordsRectT; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 259 | currVertex += vertexStride; |
| 260 | |
| 261 | currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 262 | currPosition->fX = positionRect.fRight; |
| 263 | currPosition->fY = positionRect.fBottom; |
| 264 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
Jim Van Verth | 328a33f | 2017-10-20 12:14:22 -0400 | [diff] [blame] | 265 | currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset); |
| 266 | currCoords[0] = coordsRectR; |
| 267 | currCoords[1] = coordsRectB; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 268 | currVertex += vertexStride; |
| 269 | } |
| 270 | |
| 271 | blobVertices += 4 * vertexStride; |
| 272 | } |
| 273 | } |
| 274 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 275 | void GrAtlasTextOp::onPrepareDraws(Target* target) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 276 | auto resourceProvider = target->resourceProvider(); |
| 277 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 278 | // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix. |
| 279 | // TODO actually only invert if we don't have RGBA |
| 280 | SkMatrix localMatrix; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 281 | if (this->usesLocalCoords() && !fGeoData[0].fViewMatrix.invert(&localMatrix)) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 285 | GrAtlasManager* atlasManager = target->atlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 286 | GrGlyphCache* glyphCache = target->glyphCache(); |
| 287 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 288 | GrMaskFormat maskFormat = this->maskFormat(); |
| 289 | |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 290 | unsigned int numActiveProxies; |
| 291 | const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &numActiveProxies); |
| 292 | if (!proxies) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 293 | SkDebugf("Could not allocate backing texture for atlas\n"); |
| 294 | return; |
| 295 | } |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 296 | SkASSERT(proxies[0]); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 297 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 298 | static constexpr int kMaxTextures = GrBitmapTextGeoProc::kMaxTextures; |
| 299 | GR_STATIC_ASSERT(GrDistanceFieldA8TextGeoProc::kMaxTextures == kMaxTextures); |
| 300 | GR_STATIC_ASSERT(GrDistanceFieldLCDTextGeoProc::kMaxTextures == kMaxTextures); |
| 301 | |
Brian Osman | 9aa30c6 | 2018-07-02 15:21:46 -0400 | [diff] [blame] | 302 | static const uint32_t kPipelineFlags = 0; |
| 303 | auto pipe = target->makePipeline(kPipelineFlags, std::move(fProcessors), |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 304 | target->detachAppliedClip(), kMaxTextures); |
| 305 | for (unsigned i = 0; i < numActiveProxies; ++i) { |
| 306 | pipe.fFixedDynamicState->fPrimitiveProcessorTextures[i] = proxies[i].get(); |
| 307 | } |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 308 | |
| 309 | FlushInfo flushInfo; |
| 310 | flushInfo.fPipeline = pipe.fPipeline; |
| 311 | flushInfo.fFixedDynamicState = pipe.fFixedDynamicState; |
| 312 | |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 313 | bool vmPerspective = fGeoData[0].fViewMatrix.hasPerspective(); |
joshualitt | d9d30f7 | 2015-12-08 10:47:55 -0800 | [diff] [blame] | 314 | if (this->usesDistanceFields()) { |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 315 | flushInfo.fGeometryProcessor = this->setupDfProcessor(proxies, numActiveProxies); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 316 | } else { |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 317 | GrSamplerState samplerState = fNeedsGlyphTransform ? GrSamplerState::ClampBilerp() |
| 318 | : GrSamplerState::ClampNearest(); |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 319 | flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 320 | this->color(), proxies, numActiveProxies, samplerState, maskFormat, |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 321 | localMatrix, vmPerspective); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 322 | } |
| 323 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 324 | flushInfo.fGlyphsToFlush = 0; |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 325 | size_t vertexStride = GrTextBlob::GetVertexStride(maskFormat, vmPerspective); |
| 326 | SkASSERT(vertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 327 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 328 | int glyphCount = this->numGlyphs(); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 329 | const GrBuffer* vertexBuffer; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 330 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 331 | void* vertices = target->makeVertexSpace( |
| 332 | vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 333 | flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 334 | flushInfo.fIndexBuffer = target->resourceProvider()->refQuadIndexBuffer(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 335 | if (!vertices || !flushInfo.fVertexBuffer) { |
| 336 | SkDebugf("Could not allocate vertices\n"); |
| 337 | return; |
| 338 | } |
| 339 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 340 | char* currVertex = reinterpret_cast<char*>(vertices); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 341 | |
Herb Derby | 7956b59 | 2018-03-22 16:10:30 -0400 | [diff] [blame] | 342 | SkExclusiveStrikePtr autoGlyphCache; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 343 | // each of these is a SubRun |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 344 | for (int i = 0; i < fGeoCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 345 | const Geometry& args = fGeoData[i]; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 346 | Blob* blob = args.fBlob; |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 347 | GrTextBlob::VertexRegenerator regenerator( |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 348 | resourceProvider, blob, args.fRun, args.fSubRun, args.fViewMatrix, args.fX, args.fY, |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 349 | args.fColor, target->deferredUploadTarget(), glyphCache, atlasManager, |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 350 | &autoGlyphCache); |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 351 | bool done = false; |
| 352 | while (!done) { |
Herb Derby | 8624059 | 2018-05-24 16:12:31 -0400 | [diff] [blame] | 353 | GrTextBlob::VertexRegenerator::Result result; |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 354 | if (!regenerator.regenerate(&result)) { |
| 355 | break; |
| 356 | } |
| 357 | done = result.fFinished; |
| 358 | |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 359 | // Copy regenerated vertices from the blob to our vertex buffer. |
| 360 | size_t vertexBytes = result.fGlyphsRegenerated * kVerticesPerGlyph * vertexStride; |
| 361 | if (args.fClipRect.isEmpty()) { |
| 362 | memcpy(currVertex, result.fFirstVertex, vertexBytes); |
| 363 | } else { |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 364 | SkASSERT(!vmPerspective); |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 365 | clip_quads(args.fClipRect, currVertex, result.fFirstVertex, vertexStride, |
| 366 | result.fGlyphsRegenerated); |
| 367 | } |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 368 | if (fNeedsGlyphTransform && !args.fViewMatrix.isIdentity()) { |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 369 | // We always do the distance field view matrix transformation after copying rather |
| 370 | // than during blob vertex generation time in the blob as handling successive |
| 371 | // arbitrary transformations would be complicated and accumulate error. |
| 372 | if (args.fViewMatrix.hasPerspective()) { |
| 373 | auto* pos = reinterpret_cast<SkPoint3*>(currVertex); |
Brian Salomon | 7c2192b | 2018-01-08 09:47:57 -0500 | [diff] [blame] | 374 | SkMatrixPriv::MapHomogeneousPointsWithStride( |
| 375 | args.fViewMatrix, pos, vertexStride, pos, vertexStride, |
| 376 | result.fGlyphsRegenerated * kVerticesPerGlyph); |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 377 | } else { |
| 378 | auto* pos = reinterpret_cast<SkPoint*>(currVertex); |
Brian Salomon | fa3783f | 2018-01-05 13:49:07 -0500 | [diff] [blame] | 379 | SkMatrixPriv::MapPointsWithStride( |
| 380 | args.fViewMatrix, pos, vertexStride, |
| 381 | result.fGlyphsRegenerated * kVerticesPerGlyph); |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 382 | } |
| 383 | } |
Brian Salomon | 18923f9 | 2017-11-06 16:26:02 -0500 | [diff] [blame] | 384 | flushInfo.fGlyphsToFlush += result.fGlyphsRegenerated; |
| 385 | if (!result.fFinished) { |
| 386 | this->flush(target, &flushInfo); |
| 387 | } |
| 388 | currVertex += vertexBytes; |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 389 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 390 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 391 | this->flush(target, &flushInfo); |
| 392 | } |
| 393 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 394 | void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 395 | if (!flushInfo->fGlyphsToFlush) { |
| 396 | return; |
| 397 | } |
| 398 | |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 399 | auto atlasManager = target->atlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 400 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 401 | GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get(); |
| 402 | GrMaskFormat maskFormat = this->maskFormat(); |
Robert Phillips | f3690dd | 2018-02-20 15:18:59 -0500 | [diff] [blame] | 403 | |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 404 | unsigned int numActiveProxies; |
| 405 | const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &numActiveProxies); |
| 406 | SkASSERT(proxies); |
| 407 | if (gp->numTextureSamplers() != (int) numActiveProxies) { |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 408 | // During preparation the number of atlas pages has increased. |
| 409 | // Update the proxies used in the GP to match. |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 410 | for (unsigned i = gp->numTextureSamplers(); i < numActiveProxies; ++i) { |
| 411 | flushInfo->fFixedDynamicState->fPrimitiveProcessorTextures[i] = proxies[i].get(); |
| 412 | } |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 413 | if (this->usesDistanceFields()) { |
| 414 | if (this->isLCD()) { |
| 415 | reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewProxies( |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 416 | proxies, numActiveProxies, GrSamplerState::ClampBilerp()); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 417 | } else { |
| 418 | reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewProxies( |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 419 | proxies, numActiveProxies, GrSamplerState::ClampBilerp()); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 420 | } |
| 421 | } else { |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 422 | GrSamplerState samplerState = fNeedsGlyphTransform ? GrSamplerState::ClampBilerp() |
| 423 | : GrSamplerState::ClampNearest(); |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 424 | reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewProxies(proxies, numActiveProxies, |
Jim Van Verth | cf838c7 | 2018-03-05 14:40:36 -0500 | [diff] [blame] | 425 | samplerState); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 426 | } |
| 427 | } |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 428 | int maxGlyphsPerDraw = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 429 | static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 430 | GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles); |
| 431 | mesh->setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph, |
| 432 | flushInfo->fGlyphsToFlush, maxGlyphsPerDraw); |
| 433 | mesh->setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset); |
| 434 | target->draw(flushInfo->fGeometryProcessor, flushInfo->fPipeline, flushInfo->fFixedDynamicState, |
| 435 | mesh); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 436 | flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
| 437 | flushInfo->fGlyphsToFlush = 0; |
| 438 | } |
| 439 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 440 | GrOp::CombineResult GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 441 | GrAtlasTextOp* that = t->cast<GrAtlasTextOp>(); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 442 | if (fProcessors != that->fProcessors) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 443 | return CombineResult::kCannotCombine; |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | if (!fCanCombineOnTouchOrOverlap && GrRectsTouchOrOverlap(this->bounds(), that->bounds())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 447 | return CombineResult::kCannotCombine; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | if (fMaskType != that->fMaskType) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 451 | return CombineResult::kCannotCombine; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 454 | const SkMatrix& thisFirstMatrix = fGeoData[0].fViewMatrix; |
| 455 | const SkMatrix& thatFirstMatrix = that->fGeoData[0].fViewMatrix; |
| 456 | |
| 457 | if (this->usesLocalCoords() && !thisFirstMatrix.cheapEqualTo(thatFirstMatrix)) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 458 | return CombineResult::kCannotCombine; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 459 | } |
| 460 | |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 461 | if (fNeedsGlyphTransform != that->fNeedsGlyphTransform) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 462 | return CombineResult::kCannotCombine; |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | if (fNeedsGlyphTransform && |
| 466 | (thisFirstMatrix.hasPerspective() != thatFirstMatrix.hasPerspective())) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 467 | return CombineResult::kCannotCombine; |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 468 | } |
| 469 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 470 | if (this->usesDistanceFields()) { |
| 471 | if (fDFGPFlags != that->fDFGPFlags) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 472 | return CombineResult::kCannotCombine; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 475 | if (fLuminanceColor != that->fLuminanceColor) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 476 | return CombineResult::kCannotCombine; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 477 | } |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 478 | } else { |
| 479 | if (kColorBitmapMask_MaskType == fMaskType && this->color() != that->color()) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 480 | return CombineResult::kCannotCombine; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 481 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 484 | // Keep the batch vertex buffer size below 32K so we don't have to create a special one |
| 485 | // We use the largest possible vertex size for this |
| 486 | static const int kVertexSize = sizeof(SkPoint) + sizeof(SkColor) + 2 * sizeof(uint16_t); |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 487 | static const int kMaxGlyphs = 32768 / (kVerticesPerGlyph * kVertexSize); |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 488 | if (this->fNumGlyphs + that->fNumGlyphs > kMaxGlyphs) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 489 | return CombineResult::kCannotCombine; |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 490 | } |
| 491 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 492 | fNumGlyphs += that->numGlyphs(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 493 | |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 494 | // Reallocate space for geo data if necessary and then import that geo's data. |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 495 | int newGeoCount = that->fGeoCount + fGeoCount; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 496 | |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 497 | // We reallocate at a rate of 1.5x to try to get better total memory usage |
| 498 | if (newGeoCount > fGeoDataAllocSize) { |
Jim Van Verth | 56c3714 | 2017-10-31 14:44:25 -0400 | [diff] [blame] | 499 | int newAllocSize = fGeoDataAllocSize + fGeoDataAllocSize / 2; |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 500 | while (newAllocSize < newGeoCount) { |
| 501 | newAllocSize += newAllocSize / 2; |
| 502 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 503 | fGeoData.realloc(newAllocSize); |
Jim Van Verth | c8a65e3 | 2017-10-25 14:25:27 -0400 | [diff] [blame] | 504 | fGeoDataAllocSize = newAllocSize; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 507 | // We steal the ref on the blobs from the other AtlasTextOp and set its count to 0 so that |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 508 | // it doesn't try to unref them. |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 509 | memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry)); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 510 | #ifdef SK_DEBUG |
| 511 | for (int i = 0; i < that->fGeoCount; ++i) { |
| 512 | that->fGeoData.get()[i].fBlob = (Blob*)0x1; |
| 513 | } |
| 514 | #endif |
| 515 | that->fGeoCount = 0; |
| 516 | fGeoCount = newGeoCount; |
| 517 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 518 | this->joinBounds(*that); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 519 | return CombineResult::kMerged; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 520 | } |
| 521 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 522 | // TODO trying to figure out why lcd is so whack |
Herb Derby | 26cbe51 | 2018-05-24 14:39:01 -0400 | [diff] [blame] | 523 | // (see comments in GrTextContext::ComputeCanonicalColor) |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 524 | sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(const sk_sp<GrTextureProxy>* proxies, |
| 525 | unsigned int numActiveProxies) const { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 526 | bool isLCD = this->isLCD(); |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 527 | |
| 528 | SkMatrix localMatrix = SkMatrix::I(); |
| 529 | if (this->usesLocalCoords()) { |
| 530 | // If this fails we'll just use I(). |
| 531 | bool result = fGeoData[0].fViewMatrix.invert(&localMatrix); |
| 532 | (void)result; |
| 533 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 534 | |
| 535 | // see if we need to create a new effect |
| 536 | if (isLCD) { |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 537 | float redCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 538 | SkColorGetR(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 539 | fUseGammaCorrectDistanceTable); |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 540 | float greenCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 541 | SkColorGetG(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 542 | fUseGammaCorrectDistanceTable); |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 543 | float blueCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 544 | SkColorGetB(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 545 | fUseGammaCorrectDistanceTable); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 546 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 547 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make( |
| 548 | redCorrection, greenCorrection, blueCorrection); |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 549 | return GrDistanceFieldLCDTextGeoProc::Make(proxies, numActiveProxies, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 550 | GrSamplerState::ClampBilerp(), widthAdjust, |
Brian Osman | 0906825 | 2018-01-03 09:57:29 -0500 | [diff] [blame] | 551 | fDFGPFlags, localMatrix); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 552 | } else { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 553 | #ifdef SK_GAMMA_APPLY_TO_A8 |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 554 | float correction = 0; |
| 555 | if (kAliasedDistanceField_MaskType != fMaskType) { |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 556 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, |
| 557 | fLuminanceColor); |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 558 | correction = fDistanceAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift, |
| 559 | fUseGammaCorrectDistanceTable); |
| 560 | } |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 561 | return GrDistanceFieldA8TextGeoProc::Make(proxies, numActiveProxies, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 562 | GrSamplerState::ClampBilerp(), |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 563 | correction, fDFGPFlags, localMatrix); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 564 | #else |
Jim Van Verth | cbeae03 | 2018-05-16 14:54:41 -0400 | [diff] [blame] | 565 | return GrDistanceFieldA8TextGeoProc::Make(proxies, numActiveProxies, |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 566 | GrSamplerState::ClampBilerp(), |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 567 | fDFGPFlags, localMatrix); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 568 | #endif |
| 569 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 570 | } |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 571 | |