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