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