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