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