blob: cc7611f08cf290523bf2993c8316c3970a88c5a5 [file] [log] [blame]
joshualitta751c972015-11-20 13:37:32 -08001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/ops/GrAtlasTextOp.h"
Robert Phillipse4fda6c2018-02-21 12:10:41 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#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"
Robert Phillips3968fcb2019-12-05 16:40:31 -050022#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/text/GrAtlasManager.h"
Robert Phillips841c9a52020-03-27 12:41:31 -040024#include "src/gpu/text/GrDistanceFieldAdjustTable.h"
joshualitta751c972015-11-20 13:37:32 -080025
joshualitt60ce86d2015-11-23 13:08:22 -080026///////////////////////////////////////////////////////////////////////////////////////////////////
27
Herb Derby3c873af2020-04-29 15:56:07 -040028GrAtlasTextOp::GrAtlasTextOp(MaskType maskType,
29 GrPaint&& paint,
30 GrTextBlob::SubRun* subrun,
31 const SkMatrix& drawMatrix,
32 SkPoint drawOrigin,
33 const SkIRect& clipRect,
34 const SkPMColor4f& filteredColor,
35 SkColor luminanceColor,
36 bool useGammaCorrectDistanceTable,
37 uint32_t DFGPFlags)
38 : INHERITED(ClassID())
39 , fMaskType{maskType}
40 , fNeedsGlyphTransform{subrun->needsTransform()}
41 , fLuminanceColor{luminanceColor}
42 , fUseGammaCorrectDistanceTable{useGammaCorrectDistanceTable}
43 , fDFGPFlags{DFGPFlags}
44 , fGeoDataAllocSize{kMinGeometryAllocated}
45 , fProcessors{std::move(paint)}
Herb Derbyd5cbc1e2020-05-16 13:45:55 -040046 , fNumGlyphs{subrun->glyphCount()} {
Herb Derby3c873af2020-04-29 15:56:07 -040047 GrAtlasTextOp::Geometry& geometry = fGeoData[0];
48
49 // Unref handled in ~GrAtlasTextOp().
50 geometry.fBlob = SkRef(subrun->fBlob);
51 geometry.fSubRunPtr = subrun;
52 geometry.fDrawMatrix = drawMatrix;
53 geometry.fDrawOrigin = drawOrigin;
54 geometry.fClipRect = clipRect;
55 geometry.fColor = subrun->maskFormat() == kARGB_GrMaskFormat ? SK_PMColor4fWHITE
56 : filteredColor;
57 fGeoCount = 1;
58
59 SkRect bounds = subrun->deviceRect(drawMatrix, drawOrigin);
60 // We don't have tight bounds on the glyph paths in device space. For the purposes of bounds
61 // we treat this as a set of non-AA rects rendered with a texture.
62 this->setBounds(bounds, HasAABloat::kNo, IsHairline::kNo);
63}
64
Robert Phillipsb97da532019-02-12 15:24:12 -050065std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeBitmap(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040066 GrPaint&& paint,
Herb Derby3c873af2020-04-29 15:56:07 -040067 GrTextBlob::SubRun* subrun,
68 const SkMatrix& drawMatrix,
69 SkPoint drawOrigin,
70 const SkIRect& clipRect,
71 const SkPMColor4f& filteredColor) {
72 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040073
Herb Derby3c873af2020-04-29 15:56:07 -040074 MaskType maskType = [&]() {
75 switch (subrun->maskFormat()) {
76 case kA8_GrMaskFormat: return kGrayscaleCoverageMask_MaskType;
77 case kA565_GrMaskFormat: return kLCDCoverageMask_MaskType;
78 case kARGB_GrMaskFormat: return kColorBitmapMask_MaskType;
79 // Needed to placate some compilers.
80 default: return kGrayscaleCoverageMask_MaskType;
Robert Phillips7c525e62018-06-12 10:11:12 -040081 }
Herb Derby3c873af2020-04-29 15:56:07 -040082 }();
83
84 return pool->allocate<GrAtlasTextOp>(maskType,
85 std::move(paint),
86 subrun,
87 drawMatrix,
88 drawOrigin,
89 clipRect,
90 filteredColor,
91 0,
92 false,
93 0);
94}
Robert Phillips7c525e62018-06-12 10:11:12 -040095
96std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeDistanceField(
Robert Phillipsb97da532019-02-12 15:24:12 -050097 GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040098 GrPaint&& paint,
Herb Derby3c873af2020-04-29 15:56:07 -040099 GrTextBlob::SubRun* subrun,
100 const SkMatrix& drawMatrix,
101 SkPoint drawOrigin,
102 const SkIRect& clipRect,
103 const SkPMColor4f& filteredColor,
Robert Phillips7c525e62018-06-12 10:11:12 -0400104 bool useGammaCorrectDistanceTable,
105 SkColor luminanceColor,
Herb Derby3c873af2020-04-29 15:56:07 -0400106 const SkSurfaceProps& props) {
107 GrOpMemoryPool* pool = context->priv().opMemoryPool();
108 bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
109 bool isLCD = subrun->hasUseLCDText() && SkPixelGeometryIsH(props.pixelGeometry());
110 MaskType maskType = !subrun->isAntiAliased() ? kAliasedDistanceField_MaskType
111 : isLCD ? (isBGR ? kLCDBGRDistanceField_MaskType
112 : kLCDDistanceField_MaskType)
113 : kGrayscaleDistanceField_MaskType;
Robert Phillipsc994a932018-06-19 13:09:54 -0400114
Herb Derby3c873af2020-04-29 15:56:07 -0400115 uint32_t DFGPFlags = drawMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
116 DFGPFlags |= drawMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
117 DFGPFlags |= drawMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0;
118 DFGPFlags |= useGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0;
119 DFGPFlags |= kAliasedDistanceField_MaskType == maskType ? kAliased_DistanceFieldEffectFlag : 0;
Robert Phillips7c525e62018-06-12 10:11:12 -0400120
Herb Derby3c873af2020-04-29 15:56:07 -0400121 if (isLCD) {
122 DFGPFlags |= kUseLCD_DistanceFieldEffectFlag;
123 DFGPFlags |= kLCDBGRDistanceField_MaskType == maskType ? kBGR_DistanceFieldEffectFlag : 0;
Robert Phillips7c525e62018-06-12 10:11:12 -0400124 }
125
Herb Derby3c873af2020-04-29 15:56:07 -0400126 return pool->allocate<GrAtlasTextOp>(maskType,
127 std::move(paint),
128 subrun,
129 drawMatrix,
130 drawOrigin,
131 clipRect,
132 filteredColor,
133 luminanceColor,
134 useGammaCorrectDistanceTable,
135 DFGPFlags);
Brian Salomon5c6ac642017-12-19 11:09:32 -0500136}
137
Chris Dalton1706cbf2019-05-21 19:35:29 -0600138void GrAtlasTextOp::visitProxies(const VisitProxyFunc& func) const {
Robert Phillipse4fda6c2018-02-21 12:10:41 -0500139 fProcessors.visitProxies(func);
Robert Phillipse4fda6c2018-02-21 12:10:41 -0500140}
141
Brian Osman9a390ac2018-11-12 09:47:48 -0500142#ifdef SK_DEBUG
Brian Salomon344ec422016-12-15 10:58:41 -0500143SkString GrAtlasTextOp::dumpInfo() const {
joshualitta751c972015-11-20 13:37:32 -0800144 SkString str;
145
146 for (int i = 0; i < fGeoCount; ++i) {
Herb Derby1b8dcd12019-11-15 15:21:15 -0500147 str.appendf("%d: Color: 0x%08x Trans: %.2f,%.2f\n",
joshualitta751c972015-11-20 13:37:32 -0800148 i,
Brian Osmancf860852018-10-31 14:04:39 -0400149 fGeoData[i].fColor.toBytes_RGBA(),
Herb Derby5bf5b042019-12-12 16:37:03 -0500150 fGeoData[i].fDrawOrigin.x(),
151 fGeoData[i].fDrawOrigin.y());
joshualitta751c972015-11-20 13:37:32 -0800152 }
153
Brian Salomon44acb5b2017-07-18 19:59:24 -0400154 str += fProcessors.dumpProcessors();
155 str += INHERITED::dumpInfo();
joshualitta751c972015-11-20 13:37:32 -0800156 return str;
157}
Brian Osman9a390ac2018-11-12 09:47:48 -0500158#endif
joshualitta751c972015-11-20 13:37:32 -0800159
Brian Salomon44acb5b2017-07-18 19:59:24 -0400160GrDrawOp::FixedFunctionFlags GrAtlasTextOp::fixedFunctionFlags() const {
161 return FixedFunctionFlags::kNone;
162}
163
Chris Dalton6ce447a2019-06-23 18:07:38 -0600164GrProcessorSet::Analysis GrAtlasTextOp::finalize(
165 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
166 GrClampType clampType) {
Brian Salomon44acb5b2017-07-18 19:59:24 -0400167 GrProcessorAnalysisCoverage coverage;
168 GrProcessorAnalysisColor color;
joshualitta751c972015-11-20 13:37:32 -0800169 if (kColorBitmapMask_MaskType == fMaskType) {
Brian Salomon44acb5b2017-07-18 19:59:24 -0400170 color.setToUnknown();
joshualitta751c972015-11-20 13:37:32 -0800171 } else {
Brian Osman09068252018-01-03 09:57:29 -0500172 color.setToConstant(this->color());
joshualitta751c972015-11-20 13:37:32 -0800173 }
joshualitta751c972015-11-20 13:37:32 -0800174 switch (fMaskType) {
joshualitta751c972015-11-20 13:37:32 -0800175 case kGrayscaleCoverageMask_MaskType:
Jim Van Verth90e89b32017-07-06 16:36:55 -0400176 case kAliasedDistanceField_MaskType:
177 case kGrayscaleDistanceField_MaskType:
Brian Salomon44acb5b2017-07-18 19:59:24 -0400178 coverage = GrProcessorAnalysisCoverage::kSingleChannel;
joshualitta751c972015-11-20 13:37:32 -0800179 break;
180 case kLCDCoverageMask_MaskType:
181 case kLCDDistanceField_MaskType:
Jim Van Verth90e89b32017-07-06 16:36:55 -0400182 case kLCDBGRDistanceField_MaskType:
Brian Salomon44acb5b2017-07-18 19:59:24 -0400183 coverage = GrProcessorAnalysisCoverage::kLCD;
joshualitta751c972015-11-20 13:37:32 -0800184 break;
185 case kColorBitmapMask_MaskType:
Brian Salomon44acb5b2017-07-18 19:59:24 -0400186 coverage = GrProcessorAnalysisCoverage::kNone;
Brian Salomonc0b642c2017-03-27 13:09:36 -0400187 break;
joshualitta751c972015-11-20 13:37:32 -0800188 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700189 auto analysis = fProcessors.finalize(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600190 color, coverage, clip, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps,
191 clampType, &fGeoData[0].fColor);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400192 fUsesLocalCoords = analysis.usesLocalCoords();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700193 return analysis;
joshualitta751c972015-11-20 13:37:32 -0800194}
195
Brian Salomon18923f92017-11-06 16:26:02 -0500196static void clip_quads(const SkIRect& clipRect, char* currVertex, const char* blobVertices,
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400197 size_t vertexStride, int glyphCount) {
198 for (int i = 0; i < glyphCount; ++i) {
Brian Salomon18923f92017-11-06 16:26:02 -0500199 const SkPoint* blobPositionLT = reinterpret_cast<const SkPoint*>(blobVertices);
200 const SkPoint* blobPositionRB =
201 reinterpret_cast<const SkPoint*>(blobVertices + 3 * vertexStride);
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400202
Jim Van Verth328a33f2017-10-20 12:14:22 -0400203 // positions for bitmap glyphs are pixel boundary aligned
Brian Osman7ca90d22017-11-10 15:31:27 -0500204 SkIRect positionRect = SkIRect::MakeLTRB(SkScalarRoundToInt(blobPositionLT->fX),
205 SkScalarRoundToInt(blobPositionLT->fY),
206 SkScalarRoundToInt(blobPositionRB->fX),
207 SkScalarRoundToInt(blobPositionRB->fY));
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400208 if (clipRect.contains(positionRect)) {
209 memcpy(currVertex, blobVertices, 4 * vertexStride);
210 currVertex += 4 * vertexStride;
211 } else {
212 // Pull out some more data that we'll need.
213 // In the LCD case the color will be garbage, but we'll overwrite it with the texcoords
214 // and it avoids a lot of conditionals.
Brian Salomon18923f92017-11-06 16:26:02 -0500215 auto color = *reinterpret_cast<const SkColor*>(blobVertices + sizeof(SkPoint));
Jim Van Verth2f2c77a2020-01-24 15:48:23 +0000216 size_t coordOffset = vertexStride - 2*sizeof(uint16_t);
217 auto* blobCoordsLT = reinterpret_cast<const uint16_t*>(blobVertices + coordOffset);
218 auto* blobCoordsRB = reinterpret_cast<const uint16_t*>(blobVertices + 3 * vertexStride +
Brian Salomon18923f92017-11-06 16:26:02 -0500219 coordOffset);
Jim Van Verth328a33f2017-10-20 12:14:22 -0400220 // Pull out the texel coordinates and texture index bits
Jim Van Verthfb395102020-02-03 10:11:19 -0500221 uint16_t coordsRectL = blobCoordsLT[0];
222 uint16_t coordsRectT = blobCoordsLT[1];
223 uint16_t coordsRectR = blobCoordsRB[0];
224 uint16_t coordsRectB = blobCoordsRB[1];
225 int index0, index1;
226 std::tie(coordsRectL, coordsRectT, index0) =
227 GrDrawOpAtlas::UnpackIndexFromTexCoords(coordsRectL, coordsRectT);
228 std::tie(coordsRectR, coordsRectB, index1) =
229 GrDrawOpAtlas::UnpackIndexFromTexCoords(coordsRectR, coordsRectB);
230 SkASSERT(index0 == index1);
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400231
Jim Van Verth328a33f2017-10-20 12:14:22 -0400232 int positionRectWidth = positionRect.width();
233 int positionRectHeight = positionRect.height();
234 SkASSERT(positionRectWidth == (coordsRectR - coordsRectL));
235 SkASSERT(positionRectHeight == (coordsRectB - coordsRectT));
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400236
237 // Clip position and texCoords to the clipRect
Jim Van Verth328a33f2017-10-20 12:14:22 -0400238 unsigned int delta;
Brian Osman788b9162020-02-07 10:36:46 -0500239 delta = std::min(std::max(clipRect.fLeft - positionRect.fLeft, 0), positionRectWidth);
Jim Van Verth328a33f2017-10-20 12:14:22 -0400240 coordsRectL += delta;
241 positionRect.fLeft += delta;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400242
Brian Osman788b9162020-02-07 10:36:46 -0500243 delta = std::min(std::max(clipRect.fTop - positionRect.fTop, 0), positionRectHeight);
Jim Van Verth328a33f2017-10-20 12:14:22 -0400244 coordsRectT += delta;
245 positionRect.fTop += delta;
246
Brian Osman788b9162020-02-07 10:36:46 -0500247 delta = std::min(std::max(positionRect.fRight - clipRect.fRight, 0), positionRectWidth);
Jim Van Verth328a33f2017-10-20 12:14:22 -0400248 coordsRectR -= delta;
249 positionRect.fRight -= delta;
250
Brian Osman788b9162020-02-07 10:36:46 -0500251 delta = std::min(std::max(positionRect.fBottom - clipRect.fBottom, 0), positionRectHeight);
Jim Van Verth328a33f2017-10-20 12:14:22 -0400252 coordsRectB -= delta;
253 positionRect.fBottom -= delta;
254
255 // Repack texel coordinates and index
Jim Van Verthfb395102020-02-03 10:11:19 -0500256 std::tie(coordsRectL, coordsRectT) =
257 GrDrawOpAtlas::PackIndexInTexCoords(coordsRectL, coordsRectT, index0);
258 std::tie(coordsRectR, coordsRectB) =
259 GrDrawOpAtlas::PackIndexInTexCoords(coordsRectR, coordsRectB, index1);
Jim Van Verth328a33f2017-10-20 12:14:22 -0400260
261 // Set new positions and coords
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400262 SkPoint* currPosition = reinterpret_cast<SkPoint*>(currVertex);
263 currPosition->fX = positionRect.fLeft;
264 currPosition->fY = positionRect.fTop;
265 *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color;
Jim Van Verth328a33f2017-10-20 12:14:22 -0400266 uint16_t* currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset);
267 currCoords[0] = coordsRectL;
268 currCoords[1] = coordsRectT;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400269 currVertex += vertexStride;
270
271 currPosition = reinterpret_cast<SkPoint*>(currVertex);
272 currPosition->fX = positionRect.fLeft;
273 currPosition->fY = positionRect.fBottom;
274 *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color;
Jim Van Verth328a33f2017-10-20 12:14:22 -0400275 currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset);
276 currCoords[0] = coordsRectL;
277 currCoords[1] = coordsRectB;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400278 currVertex += vertexStride;
279
280 currPosition = reinterpret_cast<SkPoint*>(currVertex);
281 currPosition->fX = positionRect.fRight;
282 currPosition->fY = positionRect.fTop;
283 *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color;
Jim Van Verth328a33f2017-10-20 12:14:22 -0400284 currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset);
285 currCoords[0] = coordsRectR;
286 currCoords[1] = coordsRectT;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400287 currVertex += vertexStride;
288
289 currPosition = reinterpret_cast<SkPoint*>(currVertex);
290 currPosition->fX = positionRect.fRight;
291 currPosition->fY = positionRect.fBottom;
292 *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color;
Jim Van Verth328a33f2017-10-20 12:14:22 -0400293 currCoords = reinterpret_cast<uint16_t*>(currVertex + coordOffset);
294 currCoords[0] = coordsRectR;
295 currCoords[1] = coordsRectB;
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400296 currVertex += vertexStride;
297 }
298
299 blobVertices += 4 * vertexStride;
300 }
301}
302
Brian Salomon91326c32017-08-09 16:02:19 -0400303void GrAtlasTextOp::onPrepareDraws(Target* target) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500304 auto resourceProvider = target->resourceProvider();
305
joshualitta751c972015-11-20 13:37:32 -0800306 // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix.
307 // TODO actually only invert if we don't have RGBA
308 SkMatrix localMatrix;
Herb Derby1c5be7b2019-12-13 12:03:06 -0500309 if (this->usesLocalCoords() && !fGeoData[0].fDrawMatrix.invert(&localMatrix)) {
joshualitta751c972015-11-20 13:37:32 -0800310 return;
311 }
312
Robert Phillips5a66efb2018-03-07 15:13:18 -0500313 GrAtlasManager* atlasManager = target->atlasManager();
Mike Klein99e002f2020-01-16 16:45:03 +0000314
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400315 GrMaskFormat maskFormat = this->maskFormat();
316
Greg Daniel9715b6c2019-12-10 15:03:10 -0500317 unsigned int numActiveViews;
318 const GrSurfaceProxyView* views = atlasManager->getViews(maskFormat, &numActiveViews);
319 if (!views) {
joshualitta751c972015-11-20 13:37:32 -0800320 SkDebugf("Could not allocate backing texture for atlas\n");
321 return;
322 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500323 SkASSERT(views[0].proxy());
joshualitta751c972015-11-20 13:37:32 -0800324
Brian Salomon7eae3e02018-08-07 14:02:38 +0000325 static constexpr int kMaxTextures = GrBitmapTextGeoProc::kMaxTextures;
Brian Salomon4dea72a2019-12-18 10:43:10 -0500326 static_assert(GrDistanceFieldA8TextGeoProc::kMaxTextures == kMaxTextures);
327 static_assert(GrDistanceFieldLCDTextGeoProc::kMaxTextures == kMaxTextures);
Brian Salomon7eae3e02018-08-07 14:02:38 +0000328
Chris Dalton304e14d2020-03-17 14:29:06 -0600329 auto primProcProxies = target->allocPrimProcProxyPtrs(kMaxTextures);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500330 for (unsigned i = 0; i < numActiveViews; ++i) {
Chris Dalton304e14d2020-03-17 14:29:06 -0600331 primProcProxies[i] = views[i].proxy();
Greg Danielb20d7e52019-09-03 13:54:39 -0400332 // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the proxies
333 // don't get added during the visitProxies call. Thus we add them here.
Greg Daniel9715b6c2019-12-10 15:03:10 -0500334 target->sampledProxyArray()->push_back(views[i].proxy());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000335 }
Brian Salomon49348902018-06-26 09:12:38 -0400336
337 FlushInfo flushInfo;
Chris Dalton304e14d2020-03-17 14:29:06 -0600338 flushInfo.fPrimProcProxies = primProcProxies;
Brian Salomon49348902018-06-26 09:12:38 -0400339
Herb Derby1c5be7b2019-12-13 12:03:06 -0500340 bool vmPerspective = fGeoData[0].fDrawMatrix.hasPerspective();
joshualittd9d30f72015-12-08 10:47:55 -0800341 if (this->usesDistanceFields()) {
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500342 flushInfo.fGeometryProcessor = this->setupDfProcessor(target->allocator(),
343 *target->caps().shaderCaps(),
Greg Daniel9715b6c2019-12-10 15:03:10 -0500344 views, numActiveViews);
joshualitta751c972015-11-20 13:37:32 -0800345 } else {
Brian Salomonccb61422020-01-09 10:46:36 -0500346 auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kBilerp
347 : GrSamplerState::Filter::kNearest;
348 flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(
349 target->allocator(), *target->caps().shaderCaps(), this->color(), false, views,
350 numActiveViews, filter, maskFormat, localMatrix, vmPerspective);
joshualitta751c972015-11-20 13:37:32 -0800351 }
352
Herb Derby23f29762020-01-10 16:26:14 -0500353 int vertexStride = (int)flushInfo.fGeometryProcessor->vertexStride();
joshualitta751c972015-11-20 13:37:32 -0800354
Brian Salomon43cbd722020-01-03 22:09:12 -0500355 // Ensure we don't request an insanely large contiguous vertex allocation.
Herb Derby23f29762020-01-10 16:26:14 -0500356 static const int kMaxVertexBytes = GrBufferAllocPool::kDefaultBufferSize;
357 const int quadSize = vertexStride * kVerticesPerGlyph;
358 const int maxQuadsPerBuffer = kMaxVertexBytes / quadSize;
359
360 // Where the quad buffer begins and ends relative to totalGlyphsRegened.
361 int quadBufferBegin = 0;
362 int quadBufferEnd = std::min(this->numGlyphs(), maxQuadsPerBuffer);
363
Robert Phillipsee08d522019-10-28 16:34:44 -0400364 flushInfo.fIndexBuffer = resourceProvider->refNonAAQuadIndexBuffer();
Herb Derby23f29762020-01-10 16:26:14 -0500365 void* vertices = target->makeVertexSpace(
366 vertexStride,
367 kVerticesPerGlyph * (quadBufferEnd - quadBufferBegin),
368 &flushInfo.fVertexBuffer,
369 &flushInfo.fVertexOffset);
joshualitta751c972015-11-20 13:37:32 -0800370 if (!vertices || !flushInfo.fVertexBuffer) {
371 SkDebugf("Could not allocate vertices\n");
372 return;
373 }
374
Herb Derby23f29762020-01-10 16:26:14 -0500375 // totalGlyphsRegened is all the glyphs for the op [0, this->numGlyphs()). The subRun glyph and
376 // quad buffer indices are calculated from this.
377 int totalGlyphsRegened = 0;
joshualitta751c972015-11-20 13:37:32 -0800378 for (int i = 0; i < fGeoCount; i++) {
joshualitt144c3c82015-11-30 12:30:13 -0800379 const Geometry& args = fGeoData[i];
Herb Derby23f29762020-01-10 16:26:14 -0500380 auto subRun = args.fSubRunPtr;
381 SkASSERT((int)subRun->vertexStride() == vertexStride);
382
Robert Phillips207d24b2020-04-09 10:23:42 -0400383 subRun->prepareGrGlyphs(target->strikeCache());
Herb Derby62b12fe2020-01-14 17:57:24 -0500384 subRun->updateVerticesColorIfNeeded(args.fColor.toBytes_RGBA());
385 subRun->translateVerticesIfNeeded(args.fDrawMatrix, args.fDrawOrigin);
386
Brian Osman1be2b7c2018-10-29 16:07:15 -0400387 // TODO4F: Preserve float colors
Robert Phillips297a2192020-04-08 15:26:54 -0400388 GrTextBlob::VertexRegenerator regenerator(resourceProvider, subRun,
389 target->deferredUploadTarget(), atlasManager);
Herb Derby23f29762020-01-10 16:26:14 -0500390
391 // Where the subRun begins and ends relative to totalGlyphsRegened.
392 int subRunBegin = totalGlyphsRegened;
Herb Derbyd5cbc1e2020-05-16 13:45:55 -0400393 int subRunEnd = subRunBegin + subRun->glyphCount();
Herb Derby23f29762020-01-10 16:26:14 -0500394
395 // Draw all the glyphs in the subRun.
396 while (totalGlyphsRegened < subRunEnd) {
397 // drawBegin and drawEnd are indices for the subRun on the
398 // interval [0, subRun->fGlyphs.size()).
399 int drawBegin = totalGlyphsRegened - subRunBegin;
400 // drawEnd is either the end of the subRun or the end of the current quad buffer.
401 int drawEnd = std::min(subRunEnd, quadBufferEnd) - subRunBegin;
402 auto[ok, glyphsRegenerated] = regenerator.regenerate(drawBegin, drawEnd);
403
404 // There was a problem allocating the glyph in the atlas. Bail.
Robert Phillips1576e4e2020-04-01 12:49:45 -0400405 if (!ok) {
406 return;
407 }
Herb Derby23f29762020-01-10 16:26:14 -0500408
409 // Update all the vertices for glyphsRegenerate glyphs.
410 if (glyphsRegenerated > 0) {
411 int quadBufferIndex = totalGlyphsRegened - quadBufferBegin;
412 int subRunIndex = totalGlyphsRegened - subRunBegin;
413 auto regeneratedQuadBuffer =
414 SkTAddOffset<char>(vertices, subRun->quadOffset(quadBufferIndex));
Brian Salomon43cbd722020-01-03 22:09:12 -0500415 if (args.fClipRect.isEmpty()) {
Herb Derby23f29762020-01-10 16:26:14 -0500416 memcpy(regeneratedQuadBuffer,
417 subRun->quadStart(subRunIndex),
418 glyphsRegenerated * quadSize);
Brian Salomon43cbd722020-01-03 22:09:12 -0500419 } else {
420 SkASSERT(!vmPerspective);
Herb Derby23f29762020-01-10 16:26:14 -0500421 clip_quads(args.fClipRect,
422 regeneratedQuadBuffer,
423 subRun->quadStart(subRunIndex),
424 vertexStride,
425 glyphsRegenerated);
Brian Salomon43cbd722020-01-03 22:09:12 -0500426 }
427 if (fNeedsGlyphTransform && !args.fDrawMatrix.isIdentity()) {
428 // We always do the distance field view matrix transformation after copying
429 // rather than during blob vertex generation time in the blob as handling
430 // successive arbitrary transformations would be complicated and accumulate
431 // error.
432 if (args.fDrawMatrix.hasPerspective()) {
Herb Derby23f29762020-01-10 16:26:14 -0500433 auto* pos = reinterpret_cast<SkPoint3*>(regeneratedQuadBuffer);
434 SkMatrixPriv::MapHomogeneousPointsWithStride(
435 args.fDrawMatrix, pos,
436 vertexStride, pos,
437 vertexStride,
438 glyphsRegenerated * kVerticesPerGlyph);
Brian Salomon43cbd722020-01-03 22:09:12 -0500439 } else {
Herb Derby23f29762020-01-10 16:26:14 -0500440 auto* pos = reinterpret_cast<SkPoint*>(regeneratedQuadBuffer);
Brian Salomon43cbd722020-01-03 22:09:12 -0500441 SkMatrixPriv::MapPointsWithStride(args.fDrawMatrix, pos, vertexStride,
Herb Derby23f29762020-01-10 16:26:14 -0500442 glyphsRegenerated * kVerticesPerGlyph);
Brian Salomon43cbd722020-01-03 22:09:12 -0500443 }
444 }
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500445 }
Herb Derby23f29762020-01-10 16:26:14 -0500446
447 totalGlyphsRegened += glyphsRegenerated;
448 flushInfo.fGlyphsToFlush += glyphsRegenerated;
449
450 // regenerate() has stopped part way through a SubRun. This means that either the atlas
451 // or the quad buffer is full or both. There is a case were the flow through
452 // the loop is strange. If we run out of quad buffer space at the same time the
453 // SubRun ends, then this is not triggered which is the right result for the last
454 // SubRun. But, if this is not the last SubRun, then advance to the next SubRun which
455 // will process no glyphs, and return to this point where the quad buffer will be
456 // expanded.
457 if (totalGlyphsRegened != subRunEnd) {
458 // Flush if not all glyphs drawn because either the quad buffer is full or the
459 // atlas is out of space.
Herb Derby4513cdd2020-01-31 13:28:49 -0500460 this->createDrawForGeneratedGlyphs(target, &flushInfo);
Herb Derby23f29762020-01-10 16:26:14 -0500461 if (totalGlyphsRegened == quadBufferEnd) {
462 // Quad buffer is full. Get more buffer.
463 quadBufferBegin = totalGlyphsRegened;
464 int quadBufferSize =
465 std::min(maxQuadsPerBuffer, this->numGlyphs() - totalGlyphsRegened);
466 quadBufferEnd = quadBufferBegin + quadBufferSize;
467
468 vertices = target->makeVertexSpace(
469 vertexStride,
470 kVerticesPerGlyph * quadBufferSize,
471 &flushInfo.fVertexBuffer,
472 &flushInfo.fVertexOffset);
473 if (!vertices || !flushInfo.fVertexBuffer) {
474 SkDebugf("Could not allocate vertices\n");
475 return;
476 }
477 }
478 }
479 }
Herb Derby5f6f8512020-01-10 12:50:35 -0500480 } // for all geometries
Herb Derby4513cdd2020-01-31 13:28:49 -0500481 this->createDrawForGeneratedGlyphs(target, &flushInfo);
joshualitta751c972015-11-20 13:37:32 -0800482}
483
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700484void GrAtlasTextOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
Robert Phillips3968fcb2019-12-05 16:40:31 -0500485 auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState,
486 std::move(fProcessors),
487 GrPipeline::InputFlags::kNone);
488
489 flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline);
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700490}
491
Herb Derby4513cdd2020-01-31 13:28:49 -0500492void GrAtlasTextOp::createDrawForGeneratedGlyphs(
493 GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500494 if (!flushInfo->fGlyphsToFlush) {
495 return;
496 }
497
Robert Phillips5a66efb2018-03-07 15:13:18 -0500498 auto atlasManager = target->atlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500499
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500500 GrGeometryProcessor* gp = flushInfo->fGeometryProcessor;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400501 GrMaskFormat maskFormat = this->maskFormat();
Robert Phillipsf3690dd2018-02-20 15:18:59 -0500502
Greg Daniel9715b6c2019-12-10 15:03:10 -0500503 unsigned int numActiveViews;
504 const GrSurfaceProxyView* views = atlasManager->getViews(maskFormat, &numActiveViews);
505 SkASSERT(views);
Jim Van Verth9f2516f2019-11-22 14:58:37 -0500506 // Something has gone terribly wrong, bail
Greg Daniel9715b6c2019-12-10 15:03:10 -0500507 if (!views || 0 == numActiveViews) {
Jim Van Verth9f2516f2019-11-22 14:58:37 -0500508 return;
509 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500510 if (gp->numTextureSamplers() != (int) numActiveViews) {
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400511 // During preparation the number of atlas pages has increased.
512 // Update the proxies used in the GP to match.
Greg Daniel9715b6c2019-12-10 15:03:10 -0500513 for (unsigned i = gp->numTextureSamplers(); i < numActiveViews; ++i) {
Chris Dalton304e14d2020-03-17 14:29:06 -0600514 flushInfo->fPrimProcProxies[i] = views[i].proxy();
Greg Danielb20d7e52019-09-03 13:54:39 -0400515 // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the
516 // proxies don't get added during the visitProxies call. Thus we add them here.
Greg Daniel9715b6c2019-12-10 15:03:10 -0500517 target->sampledProxyArray()->push_back(views[i].proxy());
Brian Salomon43cbd722020-01-03 22:09:12 -0500518 // These will get unreffed when the previously recorded draws destruct.
519 for (int d = 0; d < flushInfo->fNumDraws; ++d) {
Chris Dalton304e14d2020-03-17 14:29:06 -0600520 flushInfo->fPrimProcProxies[i]->ref();
Brian Salomon43cbd722020-01-03 22:09:12 -0500521 }
Brian Salomon7eae3e02018-08-07 14:02:38 +0000522 }
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400523 if (this->usesDistanceFields()) {
524 if (this->isLCD()) {
Greg Daniel9715b6c2019-12-10 15:03:10 -0500525 reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewViews(
Brian Salomonccb61422020-01-09 10:46:36 -0500526 views, numActiveViews, GrSamplerState::Filter::kBilerp);
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400527 } else {
Greg Daniel9715b6c2019-12-10 15:03:10 -0500528 reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewViews(
Brian Salomonccb61422020-01-09 10:46:36 -0500529 views, numActiveViews, GrSamplerState::Filter::kBilerp);
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400530 }
531 } else {
Brian Salomonccb61422020-01-09 10:46:36 -0500532 auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kBilerp
533 : GrSamplerState::Filter::kNearest;
534 reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewViews(views, numActiveViews, filter);
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400535 }
536 }
Brian Salomondbf70722019-02-07 11:31:24 -0500537 int maxGlyphsPerDraw = static_cast<int>(flushInfo->fIndexBuffer->size() / sizeof(uint16_t) / 6);
Chris Daltoneb694b72020-03-16 09:25:50 -0600538 GrSimpleMesh* mesh = target->allocMesh();
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600539 mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerGlyph, flushInfo->fGlyphsToFlush,
540 maxGlyphsPerDraw, flushInfo->fVertexBuffer, kVerticesPerGlyph,
541 flushInfo->fVertexOffset);
Chris Dalton304e14d2020-03-17 14:29:06 -0600542 target->recordDraw(flushInfo->fGeometryProcessor, mesh, 1, flushInfo->fPrimProcProxies,
Chris Dalton3bf2f3a2020-03-17 11:48:23 -0600543 GrPrimitiveType::kTriangles);
joshualitta751c972015-11-20 13:37:32 -0800544 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
545 flushInfo->fGlyphsToFlush = 0;
Brian Salomon43cbd722020-01-03 22:09:12 -0500546 ++flushInfo->fNumDraws;
joshualitta751c972015-11-20 13:37:32 -0800547}
548
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500549GrOp::CombineResult GrAtlasTextOp::onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
550 const GrCaps& caps) {
Brian Salomon344ec422016-12-15 10:58:41 -0500551 GrAtlasTextOp* that = t->cast<GrAtlasTextOp>();
Brian Salomon44acb5b2017-07-18 19:59:24 -0400552 if (fProcessors != that->fProcessors) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000553 return CombineResult::kCannotCombine;
Brian Salomon44acb5b2017-07-18 19:59:24 -0400554 }
555
joshualitta751c972015-11-20 13:37:32 -0800556 if (fMaskType != that->fMaskType) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000557 return CombineResult::kCannotCombine;
joshualitta751c972015-11-20 13:37:32 -0800558 }
559
Herb Derby1c5be7b2019-12-13 12:03:06 -0500560 const SkMatrix& thisFirstMatrix = fGeoData[0].fDrawMatrix;
561 const SkMatrix& thatFirstMatrix = that->fGeoData[0].fDrawMatrix;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500562
Mike Reed2c383152019-12-18 16:47:47 -0500563 if (this->usesLocalCoords() && !SkMatrixPriv::CheapEqual(thisFirstMatrix, thatFirstMatrix)) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000564 return CombineResult::kCannotCombine;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500565 }
566
Jim Van Verthb515ae72018-05-23 16:44:55 -0400567 if (fNeedsGlyphTransform != that->fNeedsGlyphTransform) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000568 return CombineResult::kCannotCombine;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400569 }
570
571 if (fNeedsGlyphTransform &&
572 (thisFirstMatrix.hasPerspective() != thatFirstMatrix.hasPerspective())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000573 return CombineResult::kCannotCombine;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400574 }
575
Brian Salomon5c6ac642017-12-19 11:09:32 -0500576 if (this->usesDistanceFields()) {
577 if (fDFGPFlags != that->fDFGPFlags) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000578 return CombineResult::kCannotCombine;
joshualitta751c972015-11-20 13:37:32 -0800579 }
580
Jim Van Verthbc2cdd12017-06-08 11:14:35 -0400581 if (fLuminanceColor != that->fLuminanceColor) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000582 return CombineResult::kCannotCombine;
joshualitta751c972015-11-20 13:37:32 -0800583 }
Brian Salomon5c6ac642017-12-19 11:09:32 -0500584 } else {
585 if (kColorBitmapMask_MaskType == fMaskType && this->color() != that->color()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000586 return CombineResult::kCannotCombine;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500587 }
joshualitta751c972015-11-20 13:37:32 -0800588 }
589
Brian Salomon344ec422016-12-15 10:58:41 -0500590 fNumGlyphs += that->numGlyphs();
joshualitta751c972015-11-20 13:37:32 -0800591
Jim Van Verth56c37142017-10-31 14:44:25 -0400592 // Reallocate space for geo data if necessary and then import that geo's data.
joshualitta751c972015-11-20 13:37:32 -0800593 int newGeoCount = that->fGeoCount + fGeoCount;
joshualitta751c972015-11-20 13:37:32 -0800594
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400595 // We reallocate at a rate of 1.5x to try to get better total memory usage
596 if (newGeoCount > fGeoDataAllocSize) {
Jim Van Verth56c37142017-10-31 14:44:25 -0400597 int newAllocSize = fGeoDataAllocSize + fGeoDataAllocSize / 2;
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400598 while (newAllocSize < newGeoCount) {
599 newAllocSize += newAllocSize / 2;
600 }
joshualitta751c972015-11-20 13:37:32 -0800601 fGeoData.realloc(newAllocSize);
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400602 fGeoDataAllocSize = newAllocSize;
joshualitta751c972015-11-20 13:37:32 -0800603 }
604
Brian Salomon344ec422016-12-15 10:58:41 -0500605 // We steal the ref on the blobs from the other AtlasTextOp and set its count to 0 so that
joshualitta751c972015-11-20 13:37:32 -0800606 // it doesn't try to unref them.
Brian Salomon344ec422016-12-15 10:58:41 -0500607 memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry));
joshualitta751c972015-11-20 13:37:32 -0800608#ifdef SK_DEBUG
609 for (int i = 0; i < that->fGeoCount; ++i) {
Herb Derbyc514e7d2019-12-11 17:00:31 -0500610 that->fGeoData.get()[i].fBlob = (GrTextBlob*)0x1;
joshualitta751c972015-11-20 13:37:32 -0800611 }
612#endif
613 that->fGeoCount = 0;
614 fGeoCount = newGeoCount;
615
Brian Salomon7eae3e02018-08-07 14:02:38 +0000616 return CombineResult::kMerged;
joshualitta751c972015-11-20 13:37:32 -0800617}
618
Herb Derby3c873af2020-04-29 15:56:07 -0400619static const int kDistanceAdjustLumShift = 5;
620
joshualitta751c972015-11-20 13:37:32 -0800621// TODO trying to figure out why lcd is so whack
Herb Derby26cbe512018-05-24 14:39:01 -0400622// (see comments in GrTextContext::ComputeCanonicalColor)
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500623GrGeometryProcessor* GrAtlasTextOp::setupDfProcessor(SkArenaAlloc* arena,
624 const GrShaderCaps& caps,
Greg Daniel9715b6c2019-12-10 15:03:10 -0500625 const GrSurfaceProxyView* views,
626 unsigned int numActiveViews) const {
joshualitta751c972015-11-20 13:37:32 -0800627 bool isLCD = this->isLCD();
Brian Salomon5c6ac642017-12-19 11:09:32 -0500628
629 SkMatrix localMatrix = SkMatrix::I();
630 if (this->usesLocalCoords()) {
631 // If this fails we'll just use I().
Herb Derby1c5be7b2019-12-13 12:03:06 -0500632 bool result = fGeoData[0].fDrawMatrix.invert(&localMatrix);
Brian Salomon5c6ac642017-12-19 11:09:32 -0500633 (void)result;
634 }
joshualitta751c972015-11-20 13:37:32 -0800635
Robert Phillips841c9a52020-03-27 12:41:31 -0400636 auto dfAdjustTable = GrDistanceFieldAdjustTable::Get();
637
joshualitta751c972015-11-20 13:37:32 -0800638 // see if we need to create a new effect
639 if (isLCD) {
Robert Phillips841c9a52020-03-27 12:41:31 -0400640 float redCorrection = dfAdjustTable->getAdjustment(
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400641 SkColorGetR(fLuminanceColor) >> kDistanceAdjustLumShift,
Brian Salomon344ec422016-12-15 10:58:41 -0500642 fUseGammaCorrectDistanceTable);
Robert Phillips841c9a52020-03-27 12:41:31 -0400643 float greenCorrection = dfAdjustTable->getAdjustment(
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400644 SkColorGetG(fLuminanceColor) >> kDistanceAdjustLumShift,
Brian Salomon344ec422016-12-15 10:58:41 -0500645 fUseGammaCorrectDistanceTable);
Robert Phillips841c9a52020-03-27 12:41:31 -0400646 float blueCorrection = dfAdjustTable->getAdjustment(
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400647 SkColorGetB(fLuminanceColor) >> kDistanceAdjustLumShift,
Brian Salomon344ec422016-12-15 10:58:41 -0500648 fUseGammaCorrectDistanceTable);
joshualitta751c972015-11-20 13:37:32 -0800649 GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust =
Brian Salomon344ec422016-12-15 10:58:41 -0500650 GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(
651 redCorrection, greenCorrection, blueCorrection);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500652 return GrDistanceFieldLCDTextGeoProc::Make(arena, caps, views, numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -0500653 GrSamplerState::Filter::kBilerp, widthAdjust,
Brian Osman09068252018-01-03 09:57:29 -0500654 fDFGPFlags, localMatrix);
joshualitta751c972015-11-20 13:37:32 -0800655 } else {
joshualitta751c972015-11-20 13:37:32 -0800656#ifdef SK_GAMMA_APPLY_TO_A8
Jim Van Verth90e89b32017-07-06 16:36:55 -0400657 float correction = 0;
658 if (kAliasedDistanceField_MaskType != fMaskType) {
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400659 U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT,
660 fLuminanceColor);
Robert Phillips841c9a52020-03-27 12:41:31 -0400661 correction = dfAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift,
662 fUseGammaCorrectDistanceTable);
Jim Van Verth90e89b32017-07-06 16:36:55 -0400663 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500664 return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -0500665 GrSamplerState::Filter::kBilerp, correction,
666 fDFGPFlags, localMatrix);
joshualitta751c972015-11-20 13:37:32 -0800667#else
Greg Daniel9715b6c2019-12-10 15:03:10 -0500668 return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -0500669 GrSamplerState::Filter::kBilerp,
Brian Salomon5c6ac642017-12-19 11:09:32 -0500670 fDFGPFlags, localMatrix);
joshualitta751c972015-11-20 13:37:32 -0800671#endif
672 }
joshualitta751c972015-11-20 13:37:32 -0800673}
joshualittddd22d82016-02-16 06:47:52 -0800674