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" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrRecordingContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/core/SkMathPriv.h" |
| 13 | #include "src/core/SkMatrixPriv.h" |
Herb Derby | 7a1d942 | 2020-07-06 14:18:01 -0400 | [diff] [blame] | 14 | #include "src/core/SkMatrixProvider.h" |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 15 | #include "src/core/SkSpan.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "src/core/SkStrikeCache.h" |
| 17 | #include "src/gpu/GrCaps.h" |
| 18 | #include "src/gpu/GrMemoryPool.h" |
| 19 | #include "src/gpu/GrOpFlushState.h" |
| 20 | #include "src/gpu/GrRecordingContextPriv.h" |
| 21 | #include "src/gpu/GrResourceProvider.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrSurfaceDrawContext.h" |
Herb Derby | 7a1d942 | 2020-07-06 14:18:01 -0400 | [diff] [blame] | 23 | #include "src/gpu/SkGr.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/effects/GrBitmapTextGeoProc.h" |
| 25 | #include "src/gpu/effects/GrDistanceFieldGeoProc.h" |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 26 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/text/GrAtlasManager.h" |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 28 | #include "src/gpu/text/GrDistanceFieldAdjustTable.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 29 | |
Herb Derby | a08bde6 | 2020-06-12 15:46:06 -0400 | [diff] [blame] | 30 | #if GR_TEST_UTILS |
| 31 | #include "src/gpu/GrDrawOpTest.h" |
| 32 | #endif |
| 33 | |
joshualitt | 60ce86d | 2015-11-23 13:08:22 -0800 | [diff] [blame] | 34 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 35 | |
Herb Derby | 3c873af | 2020-04-29 15:56:07 -0400 | [diff] [blame] | 36 | GrAtlasTextOp::GrAtlasTextOp(MaskType maskType, |
Herb Derby | 268e48b | 2020-07-16 12:56:58 -0400 | [diff] [blame] | 37 | bool needsTransform, |
| 38 | int glyphCount, |
| 39 | SkRect deviceRect, |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 40 | Geometry* geo, |
Herb Derby | 1d17e49 | 2020-07-21 11:45:04 -0400 | [diff] [blame] | 41 | GrPaint&& paint) |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 42 | : INHERITED{ClassID()} |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 43 | , fProcessors(std::move(paint)) |
| 44 | , fNumGlyphs(glyphCount) |
| 45 | , fDFGPFlags(0) |
| 46 | , fMaskType(static_cast<uint32_t>(maskType)) |
| 47 | , fUsesLocalCoords(false) |
| 48 | , fNeedsGlyphTransform(needsTransform) |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 49 | , fHasPerspective(needsTransform && geo->fDrawMatrix.hasPerspective()) |
| 50 | , fUseGammaCorrectDistanceTable(false) |
| 51 | , fHead{geo} |
| 52 | , fTail{&fHead->fNext} { |
Herb Derby | 268e48b | 2020-07-16 12:56:58 -0400 | [diff] [blame] | 53 | // We don't have tight bounds on the glyph paths in device space. For the purposes of bounds |
| 54 | // we treat this as a set of non-AA rects rendered with a texture. |
| 55 | this->setBounds(deviceRect, HasAABloat::kNo, IsHairline::kNo); |
| 56 | } |
| 57 | |
| 58 | GrAtlasTextOp::GrAtlasTextOp(MaskType maskType, |
| 59 | bool needsTransform, |
| 60 | int glyphCount, |
| 61 | SkRect deviceRect, |
Herb Derby | 3c873af | 2020-04-29 15:56:07 -0400 | [diff] [blame] | 62 | SkColor luminanceColor, |
| 63 | bool useGammaCorrectDistanceTable, |
Herb Derby | 268e48b | 2020-07-16 12:56:58 -0400 | [diff] [blame] | 64 | uint32_t DFGPFlags, |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 65 | Geometry* geo, |
Herb Derby | 1d17e49 | 2020-07-21 11:45:04 -0400 | [diff] [blame] | 66 | GrPaint&& paint) |
Herb Derby | 268e48b | 2020-07-16 12:56:58 -0400 | [diff] [blame] | 67 | : INHERITED{ClassID()} |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 68 | , fProcessors(std::move(paint)) |
| 69 | , fNumGlyphs(glyphCount) |
| 70 | , fDFGPFlags(DFGPFlags) |
| 71 | , fMaskType(static_cast<uint32_t>(maskType)) |
| 72 | , fUsesLocalCoords(false) |
| 73 | , fNeedsGlyphTransform(needsTransform) |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 74 | , fHasPerspective(needsTransform && geo->fDrawMatrix.hasPerspective()) |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 75 | , fUseGammaCorrectDistanceTable(useGammaCorrectDistanceTable) |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 76 | , fLuminanceColor(luminanceColor) |
| 77 | , fHead{geo} |
| 78 | , fTail{&fHead->fNext} { |
Herb Derby | 3c873af | 2020-04-29 15:56:07 -0400 | [diff] [blame] | 79 | // We don't have tight bounds on the glyph paths in device space. For the purposes of bounds |
| 80 | // we treat this as a set of non-AA rects rendered with a texture. |
Herb Derby | 268e48b | 2020-07-16 12:56:58 -0400 | [diff] [blame] | 81 | this->setBounds(deviceRect, HasAABloat::kNo, IsHairline::kNo); |
Herb Derby | 3c873af | 2020-04-29 15:56:07 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 84 | auto GrAtlasTextOp::Geometry::Make(GrRecordingContext* rc, |
| 85 | const GrAtlasSubRun& subRun, |
| 86 | const SkMatrix& drawMatrix, |
| 87 | SkPoint drawOrigin, |
| 88 | SkIRect clipRect, |
Herb Derby | 4f78f23 | 2021-02-18 10:42:35 -0500 | [diff] [blame] | 89 | sk_sp<GrTextBlob> blob, |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 90 | const SkPMColor4f& color) -> Geometry* { |
| 91 | auto arena = rc->priv().recordTimeAllocator(); |
Herb Derby | 4f78f23 | 2021-02-18 10:42:35 -0500 | [diff] [blame] | 92 | // Bypass the automatic dtor behavior in SkArenaAlloc. I'm leaving this up to the Op to run |
| 93 | // all geometry dtors for now. |
| 94 | void* geo = arena->makeBytesAlignedTo(sizeof(Geometry), alignof(Geometry)); |
| 95 | return new (geo) Geometry{subRun, |
| 96 | drawMatrix, |
| 97 | drawOrigin, |
| 98 | clipRect, |
| 99 | std::move(blob), |
| 100 | color}; |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | |
Herb Derby | 64391c4 | 2020-05-16 14:32:15 -0400 | [diff] [blame] | 105 | void GrAtlasTextOp::Geometry::fillVertexData(void *dst, int offset, int count) const { |
Herb Derby | 4089418 | 2020-12-02 11:39:48 -0500 | [diff] [blame] | 106 | SkMatrix positionMatrix = fDrawMatrix; |
| 107 | positionMatrix.preTranslate(fDrawOrigin.x(), fDrawOrigin.y()); |
| 108 | fSubRun.fillVertexData( |
| 109 | dst, offset, count, fColor.toBytes_RGBA(), positionMatrix, fClipRect); |
Herb Derby | 64391c4 | 2020-05-16 14:32:15 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Chris Dalton | 1706cbf | 2019-05-21 19:35:29 -0600 | [diff] [blame] | 112 | void GrAtlasTextOp::visitProxies(const VisitProxyFunc& func) const { |
Robert Phillips | e4fda6c | 2018-02-21 12:10:41 -0500 | [diff] [blame] | 113 | fProcessors.visitProxies(func); |
Robert Phillips | e4fda6c | 2018-02-21 12:10:41 -0500 | [diff] [blame] | 114 | } |
| 115 | |
John Stiles | 8d9bf64 | 2020-08-12 15:07:45 -0400 | [diff] [blame] | 116 | #if GR_TEST_UTILS |
John Stiles | 8dd1e22 | 2020-08-12 19:06:24 -0400 | [diff] [blame] | 117 | SkString GrAtlasTextOp::onDumpInfo() const { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 118 | SkString str; |
Michael Ludwig | 64596c5 | 2020-11-05 12:39:13 -0500 | [diff] [blame] | 119 | int i = 0; |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 120 | for(Geometry* geom = fHead; geom != nullptr; geom = geom->fNext) { |
Herb Derby | 1b8dcd1 | 2019-11-15 15:21:15 -0500 | [diff] [blame] | 121 | str.appendf("%d: Color: 0x%08x Trans: %.2f,%.2f\n", |
Michael Ludwig | 64596c5 | 2020-11-05 12:39:13 -0500 | [diff] [blame] | 122 | i++, |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 123 | geom->fColor.toBytes_RGBA(), |
| 124 | geom->fDrawOrigin.x(), |
| 125 | geom->fDrawOrigin.y()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 128 | str += fProcessors.dumpProcessors(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 129 | return str; |
| 130 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 131 | #endif |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 132 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 133 | GrDrawOp::FixedFunctionFlags GrAtlasTextOp::fixedFunctionFlags() const { |
| 134 | return FixedFunctionFlags::kNone; |
| 135 | } |
| 136 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 137 | GrProcessorSet::Analysis GrAtlasTextOp::finalize( |
| 138 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
| 139 | GrClampType clampType) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 140 | GrProcessorAnalysisCoverage coverage; |
| 141 | GrProcessorAnalysisColor color; |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 142 | if (this->maskType() == MaskType::kColorBitmap) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 143 | color.setToUnknown(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 144 | } else { |
Michael Ludwig | 136d878 | 2020-11-03 11:04:16 -0500 | [diff] [blame] | 145 | // finalize() is called before any merging is done, so at this point there's at most one |
| 146 | // Geometry with a color. Later, for non-bitmap ops, we may have mixed colors. |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 147 | color.setToConstant(fHead->fColor); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 148 | } |
Michael Ludwig | 136d878 | 2020-11-03 11:04:16 -0500 | [diff] [blame] | 149 | |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 150 | switch (this->maskType()) { |
Michael Ludwig | 136d878 | 2020-11-03 11:04:16 -0500 | [diff] [blame] | 151 | case MaskType::kGrayscaleCoverage: |
| 152 | case MaskType::kAliasedDistanceField: |
| 153 | case MaskType::kGrayscaleDistanceField: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 154 | coverage = GrProcessorAnalysisCoverage::kSingleChannel; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 155 | break; |
Michael Ludwig | 136d878 | 2020-11-03 11:04:16 -0500 | [diff] [blame] | 156 | case MaskType::kLCDCoverage: |
| 157 | case MaskType::kLCDDistanceField: |
| 158 | case MaskType::kLCDBGRDistanceField: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 159 | coverage = GrProcessorAnalysisCoverage::kLCD; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 160 | break; |
Michael Ludwig | 136d878 | 2020-11-03 11:04:16 -0500 | [diff] [blame] | 161 | case MaskType::kColorBitmap: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 162 | coverage = GrProcessorAnalysisCoverage::kNone; |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 163 | break; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 164 | } |
Michael Ludwig | 136d878 | 2020-11-03 11:04:16 -0500 | [diff] [blame] | 165 | |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 166 | auto analysis = fProcessors.finalize( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 167 | color, coverage, clip, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps, |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 168 | clampType, &fHead->fColor); |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 169 | // TODO(michaelludwig): Once processor analysis can be done external to op creation/finalization |
| 170 | // the atlas op metadata can be fully const. This is okay for now since finalize() happens |
| 171 | // before the op is merged, so during combineIfPossible, metadata is effectively const. |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 172 | fUsesLocalCoords = analysis.usesLocalCoords(); |
Chris Dalton | 4b62aed | 2019-01-15 11:53:00 -0700 | [diff] [blame] | 173 | return analysis; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 176 | void GrAtlasTextOp::onPrepareDraws(Target* target) { |
Robert Phillips | 4bc7011 | 2018-03-01 10:24:02 -0500 | [diff] [blame] | 177 | auto resourceProvider = target->resourceProvider(); |
| 178 | |
Michael Ludwig | 9597e2f | 2020-11-03 11:06:25 -0500 | [diff] [blame] | 179 | // If we need local coordinates, compute an inverse view matrix. If this is solid color, the |
| 180 | // processor analysis will not require local coords and the GPs will skip local coords when |
| 181 | // the matrix is identity. When the shaders require local coords, combineIfPossible requires all |
| 182 | // all geometries to have same draw matrix. |
| 183 | SkMatrix localMatrix = SkMatrix::I(); |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 184 | if (fUsesLocalCoords && !fHead->fDrawMatrix.invert(&localMatrix)) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 185 | return; |
| 186 | } |
| 187 | |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 188 | GrAtlasManager* atlasManager = target->atlasManager(); |
Mike Klein | 99e002f | 2020-01-16 16:45:03 +0000 | [diff] [blame] | 189 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 190 | GrMaskFormat maskFormat = this->maskFormat(); |
| 191 | |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 192 | unsigned int numActiveViews; |
| 193 | const GrSurfaceProxyView* views = atlasManager->getViews(maskFormat, &numActiveViews); |
| 194 | if (!views) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 195 | SkDebugf("Could not allocate backing texture for atlas\n"); |
| 196 | return; |
| 197 | } |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 198 | SkASSERT(views[0].proxy()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 199 | |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 200 | static constexpr int kMaxTextures = GrBitmapTextGeoProc::kMaxTextures; |
Brian Salomon | 4dea72a | 2019-12-18 10:43:10 -0500 | [diff] [blame] | 201 | static_assert(GrDistanceFieldA8TextGeoProc::kMaxTextures == kMaxTextures); |
| 202 | static_assert(GrDistanceFieldLCDTextGeoProc::kMaxTextures == kMaxTextures); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 203 | |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 204 | auto primProcProxies = target->allocPrimProcProxyPtrs(kMaxTextures); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 205 | for (unsigned i = 0; i < numActiveViews; ++i) { |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 206 | primProcProxies[i] = views[i].proxy(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 207 | // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the proxies |
| 208 | // don't get added during the visitProxies call. Thus we add them here. |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 209 | target->sampledProxyArray()->push_back(views[i].proxy()); |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 210 | } |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 211 | |
| 212 | FlushInfo flushInfo; |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 213 | flushInfo.fPrimProcProxies = primProcProxies; |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 214 | flushInfo.fIndexBuffer = resourceProvider->refNonAAQuadIndexBuffer(); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 215 | |
joshualitt | d9d30f7 | 2015-12-08 10:47:55 -0800 | [diff] [blame] | 216 | if (this->usesDistanceFields()) { |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 217 | flushInfo.fGeometryProcessor = this->setupDfProcessor(target->allocator(), |
| 218 | *target->caps().shaderCaps(), |
Michael Ludwig | 9597e2f | 2020-11-03 11:06:25 -0500 | [diff] [blame] | 219 | localMatrix, views, numActiveViews); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 220 | } else { |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 221 | auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kLinear |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 222 | : GrSamplerState::Filter::kNearest; |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 223 | // Bitmap text uses a single color, combineIfPossible ensures all geometries have the same |
| 224 | // color, so we can use the first's without worry. |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 225 | flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 226 | target->allocator(), *target->caps().shaderCaps(), fHead->fColor, |
Michael Ludwig | 64596c5 | 2020-11-05 12:39:13 -0500 | [diff] [blame] | 227 | false, views, numActiveViews, filter, maskFormat, localMatrix, fHasPerspective); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 230 | const int vertexStride = (int)flushInfo.fGeometryProcessor->vertexStride(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 231 | |
Brian Salomon | 43cbd72 | 2020-01-03 22:09:12 -0500 | [diff] [blame] | 232 | // Ensure we don't request an insanely large contiguous vertex allocation. |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 233 | static const int kMaxVertexBytes = GrBufferAllocPool::kDefaultBufferSize; |
| 234 | const int quadSize = vertexStride * kVerticesPerGlyph; |
| 235 | const int maxQuadsPerBuffer = kMaxVertexBytes / quadSize; |
| 236 | |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 237 | int allGlyphsCursor = 0; |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 238 | const int allGlyphsEnd = fNumGlyphs; |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 239 | int quadCursor; |
| 240 | int quadEnd; |
| 241 | char* vertices; |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 242 | |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 243 | auto resetVertexBuffer = [&] { |
| 244 | quadCursor = 0; |
| 245 | quadEnd = std::min(maxQuadsPerBuffer, allGlyphsEnd - allGlyphsCursor); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 246 | |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 247 | vertices = (char*)target->makeVertexSpace( |
| 248 | vertexStride, |
| 249 | kVerticesPerGlyph * quadEnd, |
| 250 | &flushInfo.fVertexBuffer, |
| 251 | &flushInfo.fVertexOffset); |
| 252 | |
| 253 | if (!vertices || !flushInfo.fVertexBuffer) { |
| 254 | SkDebugf("Could not allocate vertices\n"); |
| 255 | return false; |
| 256 | } |
| 257 | return true; |
| 258 | }; |
| 259 | |
| 260 | resetVertexBuffer(); |
| 261 | |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 262 | for (const Geometry* geo = fHead; geo != nullptr; geo = geo->fNext) { |
| 263 | const GrAtlasSubRun& subRun = geo->fSubRun; |
| 264 | SkASSERT((int) subRun.vertexStride(geo->fDrawMatrix) == vertexStride); |
Herb Derby | 62b12fe | 2020-01-14 17:57:24 -0500 | [diff] [blame] | 265 | |
Herb Derby | 43ad791 | 2020-07-20 16:14:19 -0400 | [diff] [blame] | 266 | const int subRunEnd = subRun.glyphCount(); |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 267 | for (int subRunCursor = 0; subRunCursor < subRunEnd;) { |
| 268 | // Regenerate the atlas for the remainder of the glyphs in the run, or the remainder |
| 269 | // of the glyphs to fill the vertex buffer. |
| 270 | int regenEnd = subRunCursor + std::min(subRunEnd - subRunCursor, quadEnd - quadCursor); |
Herb Derby | 43ad791 | 2020-07-20 16:14:19 -0400 | [diff] [blame] | 271 | auto[ok, glyphsRegenerated] = subRun.regenerateAtlas(subRunCursor, regenEnd, target); |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 272 | // There was a problem allocating the glyph in the atlas. Bail. |
Robert Phillips | 1576e4e | 2020-04-01 12:49:45 -0400 | [diff] [blame] | 273 | if (!ok) { |
| 274 | return; |
| 275 | } |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 276 | |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 277 | geo->fillVertexData(vertices + quadCursor * quadSize, subRunCursor, glyphsRegenerated); |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 278 | |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 279 | subRunCursor += glyphsRegenerated; |
| 280 | quadCursor += glyphsRegenerated; |
| 281 | allGlyphsCursor += glyphsRegenerated; |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 282 | flushInfo.fGlyphsToFlush += glyphsRegenerated; |
| 283 | |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 284 | if (quadCursor == quadEnd || subRunCursor < subRunEnd) { |
| 285 | // Flush if not all the glyphs are drawn because either the quad buffer is full or |
| 286 | // the atlas is out of space. |
Herb Derby | 89acfe7 | 2021-01-28 10:57:40 -0500 | [diff] [blame] | 287 | if (subRunCursor < subRunEnd) { |
| 288 | ATRACE_ANDROID_FRAMEWORK_ALWAYS("Atlas full"); |
| 289 | } |
Herb Derby | 4513cdd | 2020-01-31 13:28:49 -0500 | [diff] [blame] | 290 | this->createDrawForGeneratedGlyphs(target, &flushInfo); |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 291 | if (quadCursor == quadEnd && allGlyphsCursor < allGlyphsEnd) { |
| 292 | // If the vertex buffer is full and there are still glyphs to draw then |
| 293 | // get a new buffer. |
| 294 | if(!resetVertexBuffer()) { |
Herb Derby | 23f2976 | 2020-01-10 16:26:14 -0500 | [diff] [blame] | 295 | return; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
Herb Derby | fd894ff | 2020-07-15 13:23:33 -0400 | [diff] [blame] | 300 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 303 | void GrAtlasTextOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 304 | auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, |
| 305 | std::move(fProcessors), |
| 306 | GrPipeline::InputFlags::kNone); |
| 307 | |
Chris Dalton | 1b6a43c | 2020-09-25 12:21:18 -0600 | [diff] [blame] | 308 | flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline, |
| 309 | &GrUserStencilSettings::kUnused); |
Chris Dalton | 07cdcfc9 | 2019-02-26 11:13:22 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Herb Derby | 4513cdd | 2020-01-31 13:28:49 -0500 | [diff] [blame] | 312 | void GrAtlasTextOp::createDrawForGeneratedGlyphs( |
| 313 | GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { |
Robert Phillips | d2e9f76 | 2018-03-07 11:54:37 -0500 | [diff] [blame] | 314 | if (!flushInfo->fGlyphsToFlush) { |
| 315 | return; |
| 316 | } |
| 317 | |
Robert Phillips | 5a66efb | 2018-03-07 15:13:18 -0500 | [diff] [blame] | 318 | auto atlasManager = target->atlasManager(); |
Robert Phillips | c4039ea | 2018-03-01 11:36:45 -0500 | [diff] [blame] | 319 | |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 320 | GrGeometryProcessor* gp = flushInfo->fGeometryProcessor; |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 321 | GrMaskFormat maskFormat = this->maskFormat(); |
Robert Phillips | f3690dd | 2018-02-20 15:18:59 -0500 | [diff] [blame] | 322 | |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 323 | unsigned int numActiveViews; |
| 324 | const GrSurfaceProxyView* views = atlasManager->getViews(maskFormat, &numActiveViews); |
| 325 | SkASSERT(views); |
Jim Van Verth | 9f2516f | 2019-11-22 14:58:37 -0500 | [diff] [blame] | 326 | // Something has gone terribly wrong, bail |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 327 | if (!views || 0 == numActiveViews) { |
Jim Van Verth | 9f2516f | 2019-11-22 14:58:37 -0500 | [diff] [blame] | 328 | return; |
| 329 | } |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 330 | if (gp->numTextureSamplers() != (int) numActiveViews) { |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 331 | // During preparation the number of atlas pages has increased. |
| 332 | // Update the proxies used in the GP to match. |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 333 | for (unsigned i = gp->numTextureSamplers(); i < numActiveViews; ++i) { |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 334 | flushInfo->fPrimProcProxies[i] = views[i].proxy(); |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 335 | // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the |
| 336 | // proxies don't get added during the visitProxies call. Thus we add them here. |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 337 | target->sampledProxyArray()->push_back(views[i].proxy()); |
Brian Salomon | 43cbd72 | 2020-01-03 22:09:12 -0500 | [diff] [blame] | 338 | // These will get unreffed when the previously recorded draws destruct. |
| 339 | for (int d = 0; d < flushInfo->fNumDraws; ++d) { |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 340 | flushInfo->fPrimProcProxies[i]->ref(); |
Brian Salomon | 43cbd72 | 2020-01-03 22:09:12 -0500 | [diff] [blame] | 341 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 342 | } |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 343 | if (this->usesDistanceFields()) { |
| 344 | if (this->isLCD()) { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 345 | reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewViews( |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 346 | views, numActiveViews, GrSamplerState::Filter::kLinear); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 347 | } else { |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 348 | reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewViews( |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 349 | views, numActiveViews, GrSamplerState::Filter::kLinear); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 350 | } |
| 351 | } else { |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 352 | auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kLinear |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 353 | : GrSamplerState::Filter::kNearest; |
| 354 | reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewViews(views, numActiveViews, filter); |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 355 | } |
| 356 | } |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 357 | int maxGlyphsPerDraw = static_cast<int>(flushInfo->fIndexBuffer->size() / sizeof(uint16_t) / 6); |
Chris Dalton | eb694b7 | 2020-03-16 09:25:50 -0600 | [diff] [blame] | 358 | GrSimpleMesh* mesh = target->allocMesh(); |
Chris Dalton | 37c7bdd | 2020-03-13 09:21:12 -0600 | [diff] [blame] | 359 | mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerGlyph, flushInfo->fGlyphsToFlush, |
| 360 | maxGlyphsPerDraw, flushInfo->fVertexBuffer, kVerticesPerGlyph, |
| 361 | flushInfo->fVertexOffset); |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 362 | target->recordDraw(flushInfo->fGeometryProcessor, mesh, 1, flushInfo->fPrimProcProxies, |
Chris Dalton | 3bf2f3a | 2020-03-17 11:48:23 -0600 | [diff] [blame] | 363 | GrPrimitiveType::kTriangles); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 364 | flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
| 365 | flushInfo->fGlyphsToFlush = 0; |
Brian Salomon | 43cbd72 | 2020-01-03 22:09:12 -0500 | [diff] [blame] | 366 | ++flushInfo->fNumDraws; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 369 | GrOp::CombineResult GrAtlasTextOp::onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) { |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 370 | GrAtlasTextOp* that = t->cast<GrAtlasTextOp>(); |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 371 | |
| 372 | if (fDFGPFlags != that->fDFGPFlags || |
| 373 | fMaskType != that->fMaskType || |
| 374 | fUsesLocalCoords != that->fUsesLocalCoords || |
| 375 | fNeedsGlyphTransform != that->fNeedsGlyphTransform || |
| 376 | fHasPerspective != that->fHasPerspective || |
| 377 | fUseGammaCorrectDistanceTable != that->fUseGammaCorrectDistanceTable) { |
| 378 | // All flags must match for an op to be combined |
| 379 | return CombineResult::kCannotCombine; |
| 380 | } |
| 381 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 382 | if (fProcessors != that->fProcessors) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 383 | return CombineResult::kCannotCombine; |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 384 | } |
| 385 | |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 386 | if (fUsesLocalCoords) { |
| 387 | // If the fragment processors use local coordinates, the GPs compute them using the inverse |
| 388 | // of the view matrix stored in a uniform, so all geometries must have the same matrix. |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 389 | const SkMatrix& thisFirstMatrix = fHead->fDrawMatrix; |
| 390 | const SkMatrix& thatFirstMatrix = that->fHead->fDrawMatrix; |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 391 | if (!SkMatrixPriv::CheapEqual(thisFirstMatrix, thatFirstMatrix)) { |
| 392 | return CombineResult::kCannotCombine; |
| 393 | } |
Jim Van Verth | b515ae7 | 2018-05-23 16:44:55 -0400 | [diff] [blame] | 394 | } |
| 395 | |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 396 | if (this->usesDistanceFields()) { |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 397 | SkASSERT(that->usesDistanceFields()); |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 398 | if (fLuminanceColor != that->fLuminanceColor) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 399 | return CombineResult::kCannotCombine; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 400 | } |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 401 | } else { |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 402 | if (this->maskType() == MaskType::kColorBitmap && |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 403 | fHead->fColor != that->fHead->fColor) { |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 404 | // This ensures all merged bitmap color text ops have a constant color |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 405 | return CombineResult::kCannotCombine; |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 406 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 409 | fNumGlyphs += that->fNumGlyphs; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 410 | |
Michael Ludwig | 64596c5 | 2020-11-05 12:39:13 -0500 | [diff] [blame] | 411 | // After concat, that's geometry list is emptied so it will not unref the blobs when destructed |
Herb Derby | 6b748e4 | 2020-12-02 17:44:54 -0500 | [diff] [blame] | 412 | this->addGeometry(that->fHead); |
| 413 | that->fHead = nullptr; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 414 | return CombineResult::kMerged; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 415 | } |
| 416 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 417 | // TODO trying to figure out why lcd is so whack |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 418 | GrGeometryProcessor* GrAtlasTextOp::setupDfProcessor(SkArenaAlloc* arena, |
| 419 | const GrShaderCaps& caps, |
Michael Ludwig | 9597e2f | 2020-11-03 11:06:25 -0500 | [diff] [blame] | 420 | const SkMatrix& localMatrix, |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 421 | const GrSurfaceProxyView* views, |
| 422 | unsigned int numActiveViews) const { |
Michael Ludwig | 9597e2f | 2020-11-03 11:06:25 -0500 | [diff] [blame] | 423 | static constexpr int kDistanceAdjustLumShift = 5; |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 424 | auto dfAdjustTable = GrDistanceFieldAdjustTable::Get(); |
| 425 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 426 | // see if we need to create a new effect |
Michael Ludwig | 9597e2f | 2020-11-03 11:06:25 -0500 | [diff] [blame] | 427 | if (this->isLCD()) { |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 428 | float redCorrection = dfAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 429 | SkColorGetR(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 430 | fUseGammaCorrectDistanceTable); |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 431 | float greenCorrection = dfAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 432 | SkColorGetG(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 433 | fUseGammaCorrectDistanceTable); |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 434 | float blueCorrection = dfAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 435 | SkColorGetB(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 436 | fUseGammaCorrectDistanceTable); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 437 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 438 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make( |
| 439 | redCorrection, greenCorrection, blueCorrection); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 440 | return GrDistanceFieldLCDTextGeoProc::Make(arena, caps, views, numActiveViews, |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 441 | GrSamplerState::Filter::kLinear, widthAdjust, |
Brian Osman | 0906825 | 2018-01-03 09:57:29 -0500 | [diff] [blame] | 442 | fDFGPFlags, localMatrix); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 443 | } else { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 444 | #ifdef SK_GAMMA_APPLY_TO_A8 |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 445 | float correction = 0; |
Michael Ludwig | efc89d2 | 2020-11-05 11:43:10 -0500 | [diff] [blame] | 446 | if (this->maskType() != MaskType::kAliasedDistanceField) { |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame] | 447 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, |
| 448 | fLuminanceColor); |
Robert Phillips | 841c9a5 | 2020-03-27 12:41:31 -0400 | [diff] [blame] | 449 | correction = dfAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift, |
| 450 | fUseGammaCorrectDistanceTable); |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 451 | } |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 452 | return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews, |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 453 | GrSamplerState::Filter::kLinear, correction, |
Brian Salomon | ccb6142 | 2020-01-09 10:46:36 -0500 | [diff] [blame] | 454 | fDFGPFlags, localMatrix); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 455 | #else |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 456 | return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews, |
Brian Salomon | a3b02f5 | 2020-07-15 16:02:01 -0400 | [diff] [blame] | 457 | GrSamplerState::Filter::kLinear, fDFGPFlags, |
| 458 | localMatrix); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 459 | #endif |
| 460 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 461 | } |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 462 | |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 463 | #if GR_TEST_UTILS |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 464 | |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 465 | GrOp::Owner GrAtlasTextOp::CreateOpTestingOnly(GrSurfaceDrawContext* rtc, |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 466 | const SkPaint& skPaint, |
| 467 | const SkFont& font, |
| 468 | const SkMatrixProvider& mtxProvider, |
| 469 | const char* text, |
| 470 | int x, |
| 471 | int y) { |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 472 | size_t textLen = (int)strlen(text); |
| 473 | |
Herb Derby | 861ef8f | 2021-02-26 16:49:06 -0500 | [diff] [blame^] | 474 | SkMatrix drawMatrix(mtxProvider.localToDevice()); |
| 475 | drawMatrix.preTranslate(x, y); |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 476 | auto drawOrigin = SkPoint::Make(x, y); |
| 477 | SkGlyphRunBuilder builder; |
| 478 | builder.drawTextUTF8(skPaint, font, text, textLen, drawOrigin); |
| 479 | |
| 480 | auto glyphRunList = builder.useGlyphRunList(); |
Ben Wagner | 525e876 | 2020-07-09 16:19:35 -0400 | [diff] [blame] | 481 | if (glyphRunList.empty()) { |
| 482 | return nullptr; |
| 483 | } |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 484 | |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 485 | auto rContext = rtc->recordingContext(); |
Robert Phillips | a9306eb | 2020-07-21 13:01:25 -0400 | [diff] [blame] | 486 | GrSDFTOptions SDFOptions = rContext->priv().SDFTOptions(); |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 487 | |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 488 | sk_sp<GrTextBlob> blob = GrTextBlob::Make(glyphRunList, drawMatrix); |
Brian Salomon | 70fe17e | 2020-11-30 14:33:58 -0500 | [diff] [blame] | 489 | SkGlyphRunListPainter* painter = rtc->glyphRunPainter(); |
Herb Derby | 281583a | 2020-11-19 11:40:07 -0500 | [diff] [blame] | 490 | painter->processGlyphRun( |
| 491 | *glyphRunList.begin(), |
Herb Derby | 861ef8f | 2021-02-26 16:49:06 -0500 | [diff] [blame^] | 492 | drawMatrix, |
Herb Derby | 281583a | 2020-11-19 11:40:07 -0500 | [diff] [blame] | 493 | glyphRunList.paint(), |
| 494 | rtc->surfaceProps(), |
Robert Phillips | a9306eb | 2020-07-21 13:01:25 -0400 | [diff] [blame] | 495 | rContext->priv().caps()->shaderCaps()->supportsDistanceFieldText(), |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 496 | SDFOptions, blob.get()); |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 497 | if (blob->subRunList().isEmpty()) { |
Ben Wagner | 525e876 | 2020-07-09 16:19:35 -0400 | [diff] [blame] | 498 | return nullptr; |
| 499 | } |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 500 | |
Herb Derby | 55f795e | 2021-02-05 13:45:05 -0500 | [diff] [blame] | 501 | GrAtlasSubRun* subRun = blob->subRunList().front().testingOnly_atlasSubRun(); |
Herb Derby | d90024d | 2020-11-20 10:21:32 -0500 | [diff] [blame] | 502 | SkASSERT(subRun); |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 503 | GrOp::Owner op; |
Herb Derby | 252a3c0 | 2020-07-14 12:15:34 -0400 | [diff] [blame] | 504 | std::tie(std::ignore, op) = subRun->makeAtlasTextOp(nullptr, mtxProvider, glyphRunList, rtc); |
Herb Derby | 411e7aa | 2020-07-09 16:02:08 -0400 | [diff] [blame] | 505 | return op; |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) { |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 509 | // Setup dummy SkPaint / GrPaint / GrSurfaceDrawContext |
| 510 | auto rtc = GrSurfaceDrawContext::Make( |
Herb Derby | 4598fa1 | 2020-06-10 14:54:22 -0400 | [diff] [blame] | 511 | context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox, {1024, 1024}); |
| 512 | |
| 513 | SkSimpleMatrixProvider matrixProvider(GrTest::TestMatrixInvertible(random)); |
| 514 | |
| 515 | SkPaint skPaint; |
| 516 | skPaint.setColor(random->nextU()); |
| 517 | |
| 518 | SkFont font; |
| 519 | if (random->nextBool()) { |
| 520 | font.setEdging(SkFont::Edging::kSubpixelAntiAlias); |
| 521 | } else { |
| 522 | font.setEdging(random->nextBool() ? SkFont::Edging::kAntiAlias : SkFont::Edging::kAlias); |
| 523 | } |
| 524 | font.setSubpixel(random->nextBool()); |
| 525 | |
| 526 | const char* text = "The quick brown fox jumps over the lazy dog."; |
| 527 | |
| 528 | // create some random x/y offsets, including negative offsets |
| 529 | static const int kMaxTrans = 1024; |
| 530 | int xPos = (random->nextU() % 2) * 2 - 1; |
| 531 | int yPos = (random->nextU() % 2) * 2 - 1; |
| 532 | int xInt = (random->nextU() % kMaxTrans) * xPos; |
| 533 | int yInt = (random->nextU() % kMaxTrans) * yPos; |
| 534 | |
| 535 | return GrAtlasTextOp::CreateOpTestingOnly( |
| 536 | rtc.get(), skPaint, font, matrixProvider, text, xInt, yInt); |
| 537 | } |
| 538 | |
| 539 | #endif |