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