blob: cba8046c8eee4300c69501d506c76f06885724a7 [file] [log] [blame]
joshualitta751c972015-11-20 13:37:32 -08001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/ops/GrAtlasTextOp.h"
Robert Phillipse4fda6c2018-02-21 12:10:41 -05009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkPoint3.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040011#include "include/gpu/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/core/SkMathPriv.h"
13#include "src/core/SkMatrixPriv.h"
Herb Derby7a1d9422020-07-06 14:18:01 -040014#include "src/core/SkMatrixProvider.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#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 Derby4598fa12020-06-10 14:54:22 -040020#include "src/gpu/GrRenderTargetContext.h"
Herb Derby7a1d9422020-07-06 14:18:01 -040021#include "src/gpu/GrRenderTargetContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "src/gpu/GrResourceProvider.h"
Herb Derby7a1d9422020-07-06 14:18:01 -040023#include "src/gpu/SkGr.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/effects/GrBitmapTextGeoProc.h"
25#include "src/gpu/effects/GrDistanceFieldGeoProc.h"
Robert Phillips3968fcb2019-12-05 16:40:31 -050026#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/text/GrAtlasManager.h"
Robert Phillips841c9a52020-03-27 12:41:31 -040028#include "src/gpu/text/GrDistanceFieldAdjustTable.h"
joshualitta751c972015-11-20 13:37:32 -080029
Herb Derbya08bde62020-06-12 15:46:06 -040030#if GR_TEST_UTILS
31#include "src/gpu/GrDrawOpTest.h"
32#endif
33
joshualitt60ce86d2015-11-23 13:08:22 -080034///////////////////////////////////////////////////////////////////////////////////////////////////
35
Herb Derby3c873af2020-04-29 15:56:07 -040036GrAtlasTextOp::GrAtlasTextOp(MaskType maskType,
37 GrPaint&& paint,
38 GrTextBlob::SubRun* subrun,
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 Derbyd5cbc1e2020-05-16 13:45:55 -040054 , fNumGlyphs{subrun->glyphCount()} {
Herb Derby3c873af2020-04-29 15:56:07 -040055 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 Derby64391c42020-05-16 14:32:15 -040073void 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
Herb Derby7a1d9422020-07-06 14:18:01 -040078static SkPMColor4f generate_filtered_color(const SkPaint& paint, const GrColorInfo& colorInfo) {
79 SkColor4f c = paint.getColor4f();
80 if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) {
81 c = xform->apply(c);
82 }
83 if (auto* cf = paint.getColorFilter()) {
84 c = cf->filterColor4f(c, colorInfo.colorSpace(), colorInfo.colorSpace());
85 }
86 return c.premul();
87}
88
Herb Derby786c5b22020-06-09 15:33:43 -040089std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeBitmap(GrRenderTargetContext* rtc,
Herb Derby7a1d9422020-07-06 14:18:01 -040090 const SkPaint& paint,
Herb Derby3c873af2020-04-29 15:56:07 -040091 GrTextBlob::SubRun* subrun,
Herb Derby7a1d9422020-07-06 14:18:01 -040092 const SkMatrixProvider& matrixProvider,
Herb Derby3c873af2020-04-29 15:56:07 -040093 SkPoint drawOrigin,
Herb Derby7a1d9422020-07-06 14:18:01 -040094 const SkIRect& clipRect) {
95 GrPaint grPaint;
96 GrRecordingContext* context = rtc->priv().getContext();
97 const GrColorInfo& colorInfo = rtc->colorInfo();
98 if (kARGB_GrMaskFormat == subrun->maskFormat()) {
99 SkPaintToGrPaintWithPrimitiveColor(context, colorInfo, paint, matrixProvider, &grPaint);
100 } else {
101 SkPaintToGrPaint(context, colorInfo, paint, matrixProvider, &grPaint);
102 }
103
104 // This is the color the op will use to draw.
105 SkPMColor4f drawingColor = generate_filtered_color(paint, colorInfo);
106
107 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -0400108
Herb Derby3c873af2020-04-29 15:56:07 -0400109 MaskType maskType = [&]() {
110 switch (subrun->maskFormat()) {
111 case kA8_GrMaskFormat: return kGrayscaleCoverageMask_MaskType;
112 case kA565_GrMaskFormat: return kLCDCoverageMask_MaskType;
113 case kARGB_GrMaskFormat: return kColorBitmapMask_MaskType;
114 // Needed to placate some compilers.
115 default: return kGrayscaleCoverageMask_MaskType;
Robert Phillips7c525e62018-06-12 10:11:12 -0400116 }
Herb Derby3c873af2020-04-29 15:56:07 -0400117 }();
118
119 return pool->allocate<GrAtlasTextOp>(maskType,
Herb Derby7a1d9422020-07-06 14:18:01 -0400120 std::move(grPaint),
Herb Derby3c873af2020-04-29 15:56:07 -0400121 subrun,
Herb Derby7a1d9422020-07-06 14:18:01 -0400122 matrixProvider.localToDevice(),
Herb Derby3c873af2020-04-29 15:56:07 -0400123 drawOrigin,
124 clipRect,
Herb Derby7a1d9422020-07-06 14:18:01 -0400125 drawingColor,
Herb Derby3c873af2020-04-29 15:56:07 -0400126 0,
127 false,
128 0);
129}
Robert Phillips7c525e62018-06-12 10:11:12 -0400130
131std::unique_ptr<GrAtlasTextOp> GrAtlasTextOp::MakeDistanceField(
Herb Derby7a1d9422020-07-06 14:18:01 -0400132 GrRenderTargetContext* rtc,
133 const SkPaint& paint,
134 GrTextBlob::SubRun* subrun,
135 const SkMatrixProvider& matrixProvider,
Herb Derbybab3dab2020-07-08 10:16:49 -0400136 SkPoint drawOrigin) {
Herb Derby7a1d9422020-07-06 14:18:01 -0400137 GrPaint grPaint;
138 GrRecordingContext* context = rtc->priv().getContext();
139 const GrColorInfo& colorInfo = rtc->colorInfo();
140 SkPaintToGrPaint(context, colorInfo, paint, matrixProvider, &grPaint);
141
142 // This is the color the op will use to draw.
143 SkPMColor4f drawingColor = generate_filtered_color(paint, colorInfo);
144
145 const SkSurfaceProps& props = rtc->surfaceProps();
146 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Herb Derby3c873af2020-04-29 15:56:07 -0400147 bool isBGR = SkPixelGeometryIsBGR(props.pixelGeometry());
148 bool isLCD = subrun->hasUseLCDText() && SkPixelGeometryIsH(props.pixelGeometry());
149 MaskType maskType = !subrun->isAntiAliased() ? kAliasedDistanceField_MaskType
150 : isLCD ? (isBGR ? kLCDBGRDistanceField_MaskType
151 : kLCDDistanceField_MaskType)
152 : kGrayscaleDistanceField_MaskType;
Robert Phillipsc994a932018-06-19 13:09:54 -0400153
Herb Derby7a1d9422020-07-06 14:18:01 -0400154 const SkMatrix& drawMatrix = matrixProvider.localToDevice();
155 bool useGammaCorrectDistanceTable = colorInfo.isLinearlyBlended();
Herb Derby3c873af2020-04-29 15:56:07 -0400156 uint32_t DFGPFlags = drawMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
157 DFGPFlags |= drawMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0;
158 DFGPFlags |= drawMatrix.hasPerspective() ? kPerspective_DistanceFieldEffectFlag : 0;
159 DFGPFlags |= useGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0;
160 DFGPFlags |= kAliasedDistanceField_MaskType == maskType ? kAliased_DistanceFieldEffectFlag : 0;
Robert Phillips7c525e62018-06-12 10:11:12 -0400161
Herb Derby3c873af2020-04-29 15:56:07 -0400162 if (isLCD) {
163 DFGPFlags |= kUseLCD_DistanceFieldEffectFlag;
164 DFGPFlags |= kLCDBGRDistanceField_MaskType == maskType ? kBGR_DistanceFieldEffectFlag : 0;
Robert Phillips7c525e62018-06-12 10:11:12 -0400165 }
166
Herb Derby3c873af2020-04-29 15:56:07 -0400167 return pool->allocate<GrAtlasTextOp>(maskType,
Herb Derby7a1d9422020-07-06 14:18:01 -0400168 std::move(grPaint),
Herb Derby3c873af2020-04-29 15:56:07 -0400169 subrun,
170 drawMatrix,
171 drawOrigin,
Herb Derbybab3dab2020-07-08 10:16:49 -0400172 SkIRect::MakeEmpty(),
Herb Derby7a1d9422020-07-06 14:18:01 -0400173 drawingColor,
174 SkPaintPriv::ComputeLuminanceColor(paint),
Herb Derby3c873af2020-04-29 15:56:07 -0400175 useGammaCorrectDistanceTable,
176 DFGPFlags);
Brian Salomon5c6ac642017-12-19 11:09:32 -0500177}
178
Chris Dalton1706cbf2019-05-21 19:35:29 -0600179void GrAtlasTextOp::visitProxies(const VisitProxyFunc& func) const {
Robert Phillipse4fda6c2018-02-21 12:10:41 -0500180 fProcessors.visitProxies(func);
Robert Phillipse4fda6c2018-02-21 12:10:41 -0500181}
182
Brian Osman9a390ac2018-11-12 09:47:48 -0500183#ifdef SK_DEBUG
Brian Salomon344ec422016-12-15 10:58:41 -0500184SkString GrAtlasTextOp::dumpInfo() const {
joshualitta751c972015-11-20 13:37:32 -0800185 SkString str;
186
187 for (int i = 0; i < fGeoCount; ++i) {
Herb Derby1b8dcd12019-11-15 15:21:15 -0500188 str.appendf("%d: Color: 0x%08x Trans: %.2f,%.2f\n",
joshualitta751c972015-11-20 13:37:32 -0800189 i,
Brian Osmancf860852018-10-31 14:04:39 -0400190 fGeoData[i].fColor.toBytes_RGBA(),
Herb Derby5bf5b042019-12-12 16:37:03 -0500191 fGeoData[i].fDrawOrigin.x(),
192 fGeoData[i].fDrawOrigin.y());
joshualitta751c972015-11-20 13:37:32 -0800193 }
194
Brian Salomon44acb5b2017-07-18 19:59:24 -0400195 str += fProcessors.dumpProcessors();
196 str += INHERITED::dumpInfo();
joshualitta751c972015-11-20 13:37:32 -0800197 return str;
198}
Brian Osman9a390ac2018-11-12 09:47:48 -0500199#endif
joshualitta751c972015-11-20 13:37:32 -0800200
Brian Salomon44acb5b2017-07-18 19:59:24 -0400201GrDrawOp::FixedFunctionFlags GrAtlasTextOp::fixedFunctionFlags() const {
202 return FixedFunctionFlags::kNone;
203}
204
Chris Dalton6ce447a2019-06-23 18:07:38 -0600205GrProcessorSet::Analysis GrAtlasTextOp::finalize(
206 const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
207 GrClampType clampType) {
Brian Salomon44acb5b2017-07-18 19:59:24 -0400208 GrProcessorAnalysisCoverage coverage;
209 GrProcessorAnalysisColor color;
joshualitta751c972015-11-20 13:37:32 -0800210 if (kColorBitmapMask_MaskType == fMaskType) {
Brian Salomon44acb5b2017-07-18 19:59:24 -0400211 color.setToUnknown();
joshualitta751c972015-11-20 13:37:32 -0800212 } else {
Brian Osman09068252018-01-03 09:57:29 -0500213 color.setToConstant(this->color());
joshualitta751c972015-11-20 13:37:32 -0800214 }
joshualitta751c972015-11-20 13:37:32 -0800215 switch (fMaskType) {
joshualitta751c972015-11-20 13:37:32 -0800216 case kGrayscaleCoverageMask_MaskType:
Jim Van Verth90e89b32017-07-06 16:36:55 -0400217 case kAliasedDistanceField_MaskType:
218 case kGrayscaleDistanceField_MaskType:
Brian Salomon44acb5b2017-07-18 19:59:24 -0400219 coverage = GrProcessorAnalysisCoverage::kSingleChannel;
joshualitta751c972015-11-20 13:37:32 -0800220 break;
221 case kLCDCoverageMask_MaskType:
222 case kLCDDistanceField_MaskType:
Jim Van Verth90e89b32017-07-06 16:36:55 -0400223 case kLCDBGRDistanceField_MaskType:
Brian Salomon44acb5b2017-07-18 19:59:24 -0400224 coverage = GrProcessorAnalysisCoverage::kLCD;
joshualitta751c972015-11-20 13:37:32 -0800225 break;
226 case kColorBitmapMask_MaskType:
Brian Salomon44acb5b2017-07-18 19:59:24 -0400227 coverage = GrProcessorAnalysisCoverage::kNone;
Brian Salomonc0b642c2017-03-27 13:09:36 -0400228 break;
joshualitta751c972015-11-20 13:37:32 -0800229 }
Chris Daltonb8fff0d2019-03-05 10:11:58 -0700230 auto analysis = fProcessors.finalize(
Chris Dalton6ce447a2019-06-23 18:07:38 -0600231 color, coverage, clip, &GrUserStencilSettings::kUnused, hasMixedSampledCoverage, caps,
232 clampType, &fGeoData[0].fColor);
Brian Salomon44acb5b2017-07-18 19:59:24 -0400233 fUsesLocalCoords = analysis.usesLocalCoords();
Chris Dalton4b62aed2019-01-15 11:53:00 -0700234 return analysis;
joshualitta751c972015-11-20 13:37:32 -0800235}
236
Brian Salomon91326c32017-08-09 16:02:19 -0400237void GrAtlasTextOp::onPrepareDraws(Target* target) {
Robert Phillips4bc70112018-03-01 10:24:02 -0500238 auto resourceProvider = target->resourceProvider();
239
joshualitta751c972015-11-20 13:37:32 -0800240 // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix.
241 // TODO actually only invert if we don't have RGBA
242 SkMatrix localMatrix;
Herb Derby1c5be7b2019-12-13 12:03:06 -0500243 if (this->usesLocalCoords() && !fGeoData[0].fDrawMatrix.invert(&localMatrix)) {
joshualitta751c972015-11-20 13:37:32 -0800244 return;
245 }
246
Robert Phillips5a66efb2018-03-07 15:13:18 -0500247 GrAtlasManager* atlasManager = target->atlasManager();
Mike Klein99e002f2020-01-16 16:45:03 +0000248
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400249 GrMaskFormat maskFormat = this->maskFormat();
250
Greg Daniel9715b6c2019-12-10 15:03:10 -0500251 unsigned int numActiveViews;
252 const GrSurfaceProxyView* views = atlasManager->getViews(maskFormat, &numActiveViews);
253 if (!views) {
joshualitta751c972015-11-20 13:37:32 -0800254 SkDebugf("Could not allocate backing texture for atlas\n");
255 return;
256 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500257 SkASSERT(views[0].proxy());
joshualitta751c972015-11-20 13:37:32 -0800258
Brian Salomon7eae3e02018-08-07 14:02:38 +0000259 static constexpr int kMaxTextures = GrBitmapTextGeoProc::kMaxTextures;
Brian Salomon4dea72a2019-12-18 10:43:10 -0500260 static_assert(GrDistanceFieldA8TextGeoProc::kMaxTextures == kMaxTextures);
261 static_assert(GrDistanceFieldLCDTextGeoProc::kMaxTextures == kMaxTextures);
Brian Salomon7eae3e02018-08-07 14:02:38 +0000262
Chris Dalton304e14d2020-03-17 14:29:06 -0600263 auto primProcProxies = target->allocPrimProcProxyPtrs(kMaxTextures);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500264 for (unsigned i = 0; i < numActiveViews; ++i) {
Chris Dalton304e14d2020-03-17 14:29:06 -0600265 primProcProxies[i] = views[i].proxy();
Greg Danielb20d7e52019-09-03 13:54:39 -0400266 // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the proxies
267 // don't get added during the visitProxies call. Thus we add them here.
Greg Daniel9715b6c2019-12-10 15:03:10 -0500268 target->sampledProxyArray()->push_back(views[i].proxy());
Brian Salomon7eae3e02018-08-07 14:02:38 +0000269 }
Brian Salomon49348902018-06-26 09:12:38 -0400270
271 FlushInfo flushInfo;
Chris Dalton304e14d2020-03-17 14:29:06 -0600272 flushInfo.fPrimProcProxies = primProcProxies;
Brian Salomon49348902018-06-26 09:12:38 -0400273
Herb Derby1c5be7b2019-12-13 12:03:06 -0500274 bool vmPerspective = fGeoData[0].fDrawMatrix.hasPerspective();
joshualittd9d30f72015-12-08 10:47:55 -0800275 if (this->usesDistanceFields()) {
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500276 flushInfo.fGeometryProcessor = this->setupDfProcessor(target->allocator(),
277 *target->caps().shaderCaps(),
Greg Daniel9715b6c2019-12-10 15:03:10 -0500278 views, numActiveViews);
joshualitta751c972015-11-20 13:37:32 -0800279 } else {
Brian Salomonccb61422020-01-09 10:46:36 -0500280 auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kBilerp
281 : GrSamplerState::Filter::kNearest;
282 flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(
283 target->allocator(), *target->caps().shaderCaps(), this->color(), false, views,
284 numActiveViews, filter, maskFormat, localMatrix, vmPerspective);
joshualitta751c972015-11-20 13:37:32 -0800285 }
286
Herb Derby23f29762020-01-10 16:26:14 -0500287 int vertexStride = (int)flushInfo.fGeometryProcessor->vertexStride();
joshualitta751c972015-11-20 13:37:32 -0800288
Brian Salomon43cbd722020-01-03 22:09:12 -0500289 // Ensure we don't request an insanely large contiguous vertex allocation.
Herb Derby23f29762020-01-10 16:26:14 -0500290 static const int kMaxVertexBytes = GrBufferAllocPool::kDefaultBufferSize;
291 const int quadSize = vertexStride * kVerticesPerGlyph;
292 const int maxQuadsPerBuffer = kMaxVertexBytes / quadSize;
293
294 // Where the quad buffer begins and ends relative to totalGlyphsRegened.
295 int quadBufferBegin = 0;
296 int quadBufferEnd = std::min(this->numGlyphs(), maxQuadsPerBuffer);
297
Robert Phillipsee08d522019-10-28 16:34:44 -0400298 flushInfo.fIndexBuffer = resourceProvider->refNonAAQuadIndexBuffer();
Herb Derby23f29762020-01-10 16:26:14 -0500299 void* vertices = target->makeVertexSpace(
300 vertexStride,
301 kVerticesPerGlyph * (quadBufferEnd - quadBufferBegin),
302 &flushInfo.fVertexBuffer,
303 &flushInfo.fVertexOffset);
joshualitta751c972015-11-20 13:37:32 -0800304 if (!vertices || !flushInfo.fVertexBuffer) {
305 SkDebugf("Could not allocate vertices\n");
306 return;
307 }
308
Herb Derby23f29762020-01-10 16:26:14 -0500309 // totalGlyphsRegened is all the glyphs for the op [0, this->numGlyphs()). The subRun glyph and
310 // quad buffer indices are calculated from this.
311 int totalGlyphsRegened = 0;
joshualitta751c972015-11-20 13:37:32 -0800312 for (int i = 0; i < fGeoCount; i++) {
joshualitt144c3c82015-11-30 12:30:13 -0800313 const Geometry& args = fGeoData[i];
Herb Derby23f29762020-01-10 16:26:14 -0500314 auto subRun = args.fSubRunPtr;
315 SkASSERT((int)subRun->vertexStride() == vertexStride);
316
Robert Phillips207d24b2020-04-09 10:23:42 -0400317 subRun->prepareGrGlyphs(target->strikeCache());
Herb Derby62b12fe2020-01-14 17:57:24 -0500318
Brian Osman1be2b7c2018-10-29 16:07:15 -0400319 // TODO4F: Preserve float colors
Robert Phillips297a2192020-04-08 15:26:54 -0400320 GrTextBlob::VertexRegenerator regenerator(resourceProvider, subRun,
321 target->deferredUploadTarget(), atlasManager);
Herb Derby23f29762020-01-10 16:26:14 -0500322
323 // Where the subRun begins and ends relative to totalGlyphsRegened.
324 int subRunBegin = totalGlyphsRegened;
Herb Derbyd5cbc1e2020-05-16 13:45:55 -0400325 int subRunEnd = subRunBegin + subRun->glyphCount();
Herb Derby23f29762020-01-10 16:26:14 -0500326
327 // Draw all the glyphs in the subRun.
328 while (totalGlyphsRegened < subRunEnd) {
329 // drawBegin and drawEnd are indices for the subRun on the
330 // interval [0, subRun->fGlyphs.size()).
331 int drawBegin = totalGlyphsRegened - subRunBegin;
332 // drawEnd is either the end of the subRun or the end of the current quad buffer.
333 int drawEnd = std::min(subRunEnd, quadBufferEnd) - subRunBegin;
334 auto[ok, glyphsRegenerated] = regenerator.regenerate(drawBegin, drawEnd);
335
336 // There was a problem allocating the glyph in the atlas. Bail.
Robert Phillips1576e4e2020-04-01 12:49:45 -0400337 if (!ok) {
338 return;
339 }
Herb Derby23f29762020-01-10 16:26:14 -0500340
341 // Update all the vertices for glyphsRegenerate glyphs.
342 if (glyphsRegenerated > 0) {
343 int quadBufferIndex = totalGlyphsRegened - quadBufferBegin;
Herb Derby23f29762020-01-10 16:26:14 -0500344 auto regeneratedQuadBuffer =
345 SkTAddOffset<char>(vertices, subRun->quadOffset(quadBufferIndex));
Herb Derby64391c42020-05-16 14:32:15 -0400346 int subRunIndex = totalGlyphsRegened - subRunBegin;
347 args.fillVertexData(regeneratedQuadBuffer, subRunIndex, glyphsRegenerated);
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500348 }
Herb Derby23f29762020-01-10 16:26:14 -0500349
350 totalGlyphsRegened += glyphsRegenerated;
351 flushInfo.fGlyphsToFlush += glyphsRegenerated;
352
353 // regenerate() has stopped part way through a SubRun. This means that either the atlas
354 // or the quad buffer is full or both. There is a case were the flow through
355 // the loop is strange. If we run out of quad buffer space at the same time the
356 // SubRun ends, then this is not triggered which is the right result for the last
357 // SubRun. But, if this is not the last SubRun, then advance to the next SubRun which
358 // will process no glyphs, and return to this point where the quad buffer will be
359 // expanded.
360 if (totalGlyphsRegened != subRunEnd) {
361 // Flush if not all glyphs drawn because either the quad buffer is full or the
362 // atlas is out of space.
Herb Derby4513cdd2020-01-31 13:28:49 -0500363 this->createDrawForGeneratedGlyphs(target, &flushInfo);
Herb Derby23f29762020-01-10 16:26:14 -0500364 if (totalGlyphsRegened == quadBufferEnd) {
365 // Quad buffer is full. Get more buffer.
366 quadBufferBegin = totalGlyphsRegened;
367 int quadBufferSize =
368 std::min(maxQuadsPerBuffer, this->numGlyphs() - totalGlyphsRegened);
369 quadBufferEnd = quadBufferBegin + quadBufferSize;
370
371 vertices = target->makeVertexSpace(
372 vertexStride,
373 kVerticesPerGlyph * quadBufferSize,
374 &flushInfo.fVertexBuffer,
375 &flushInfo.fVertexOffset);
376 if (!vertices || !flushInfo.fVertexBuffer) {
377 SkDebugf("Could not allocate vertices\n");
378 return;
379 }
380 }
381 }
382 }
Herb Derby5f6f8512020-01-10 12:50:35 -0500383 } // for all geometries
Herb Derby4513cdd2020-01-31 13:28:49 -0500384 this->createDrawForGeneratedGlyphs(target, &flushInfo);
joshualitta751c972015-11-20 13:37:32 -0800385}
386
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700387void GrAtlasTextOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
Robert Phillips3968fcb2019-12-05 16:40:31 -0500388 auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState,
389 std::move(fProcessors),
390 GrPipeline::InputFlags::kNone);
391
392 flushState->executeDrawsAndUploadsForMeshDrawOp(this, chainBounds, pipeline);
Chris Dalton07cdcfc92019-02-26 11:13:22 -0700393}
394
Herb Derby4513cdd2020-01-31 13:28:49 -0500395void GrAtlasTextOp::createDrawForGeneratedGlyphs(
396 GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const {
Robert Phillipsd2e9f762018-03-07 11:54:37 -0500397 if (!flushInfo->fGlyphsToFlush) {
398 return;
399 }
400
Robert Phillips5a66efb2018-03-07 15:13:18 -0500401 auto atlasManager = target->atlasManager();
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500402
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500403 GrGeometryProcessor* gp = flushInfo->fGeometryProcessor;
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400404 GrMaskFormat maskFormat = this->maskFormat();
Robert Phillipsf3690dd2018-02-20 15:18:59 -0500405
Greg Daniel9715b6c2019-12-10 15:03:10 -0500406 unsigned int numActiveViews;
407 const GrSurfaceProxyView* views = atlasManager->getViews(maskFormat, &numActiveViews);
408 SkASSERT(views);
Jim Van Verth9f2516f2019-11-22 14:58:37 -0500409 // Something has gone terribly wrong, bail
Greg Daniel9715b6c2019-12-10 15:03:10 -0500410 if (!views || 0 == numActiveViews) {
Jim Van Verth9f2516f2019-11-22 14:58:37 -0500411 return;
412 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500413 if (gp->numTextureSamplers() != (int) numActiveViews) {
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400414 // During preparation the number of atlas pages has increased.
415 // Update the proxies used in the GP to match.
Greg Daniel9715b6c2019-12-10 15:03:10 -0500416 for (unsigned i = gp->numTextureSamplers(); i < numActiveViews; ++i) {
Chris Dalton304e14d2020-03-17 14:29:06 -0600417 flushInfo->fPrimProcProxies[i] = views[i].proxy();
Greg Danielb20d7e52019-09-03 13:54:39 -0400418 // This op does not know its atlas proxies when it is added to a GrOpsTasks, so the
419 // proxies don't get added during the visitProxies call. Thus we add them here.
Greg Daniel9715b6c2019-12-10 15:03:10 -0500420 target->sampledProxyArray()->push_back(views[i].proxy());
Brian Salomon43cbd722020-01-03 22:09:12 -0500421 // These will get unreffed when the previously recorded draws destruct.
422 for (int d = 0; d < flushInfo->fNumDraws; ++d) {
Chris Dalton304e14d2020-03-17 14:29:06 -0600423 flushInfo->fPrimProcProxies[i]->ref();
Brian Salomon43cbd722020-01-03 22:09:12 -0500424 }
Brian Salomon7eae3e02018-08-07 14:02:38 +0000425 }
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400426 if (this->usesDistanceFields()) {
427 if (this->isLCD()) {
Greg Daniel9715b6c2019-12-10 15:03:10 -0500428 reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewViews(
Brian Salomonccb61422020-01-09 10:46:36 -0500429 views, numActiveViews, GrSamplerState::Filter::kBilerp);
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400430 } else {
Greg Daniel9715b6c2019-12-10 15:03:10 -0500431 reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewViews(
Brian Salomonccb61422020-01-09 10:46:36 -0500432 views, numActiveViews, GrSamplerState::Filter::kBilerp);
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400433 }
434 } else {
Brian Salomonccb61422020-01-09 10:46:36 -0500435 auto filter = fNeedsGlyphTransform ? GrSamplerState::Filter::kBilerp
436 : GrSamplerState::Filter::kNearest;
437 reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewViews(views, numActiveViews, filter);
Jim Van Vertheafa64b2017-09-18 10:05:00 -0400438 }
439 }
Brian Salomondbf70722019-02-07 11:31:24 -0500440 int maxGlyphsPerDraw = static_cast<int>(flushInfo->fIndexBuffer->size() / sizeof(uint16_t) / 6);
Chris Daltoneb694b72020-03-16 09:25:50 -0600441 GrSimpleMesh* mesh = target->allocMesh();
Chris Dalton37c7bdd2020-03-13 09:21:12 -0600442 mesh->setIndexedPatterned(flushInfo->fIndexBuffer, kIndicesPerGlyph, flushInfo->fGlyphsToFlush,
443 maxGlyphsPerDraw, flushInfo->fVertexBuffer, kVerticesPerGlyph,
444 flushInfo->fVertexOffset);
Chris Dalton304e14d2020-03-17 14:29:06 -0600445 target->recordDraw(flushInfo->fGeometryProcessor, mesh, 1, flushInfo->fPrimProcProxies,
Chris Dalton3bf2f3a2020-03-17 11:48:23 -0600446 GrPrimitiveType::kTriangles);
joshualitta751c972015-11-20 13:37:32 -0800447 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
448 flushInfo->fGlyphsToFlush = 0;
Brian Salomon43cbd722020-01-03 22:09:12 -0500449 ++flushInfo->fNumDraws;
joshualitta751c972015-11-20 13:37:32 -0800450}
451
Michael Ludwig28b0c5d2019-12-19 14:51:00 -0500452GrOp::CombineResult GrAtlasTextOp::onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
453 const GrCaps& caps) {
Brian Salomon344ec422016-12-15 10:58:41 -0500454 GrAtlasTextOp* that = t->cast<GrAtlasTextOp>();
Brian Salomon44acb5b2017-07-18 19:59:24 -0400455 if (fProcessors != that->fProcessors) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000456 return CombineResult::kCannotCombine;
Brian Salomon44acb5b2017-07-18 19:59:24 -0400457 }
458
joshualitta751c972015-11-20 13:37:32 -0800459 if (fMaskType != that->fMaskType) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000460 return CombineResult::kCannotCombine;
joshualitta751c972015-11-20 13:37:32 -0800461 }
462
Herb Derby1c5be7b2019-12-13 12:03:06 -0500463 const SkMatrix& thisFirstMatrix = fGeoData[0].fDrawMatrix;
464 const SkMatrix& thatFirstMatrix = that->fGeoData[0].fDrawMatrix;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500465
Mike Reed2c383152019-12-18 16:47:47 -0500466 if (this->usesLocalCoords() && !SkMatrixPriv::CheapEqual(thisFirstMatrix, thatFirstMatrix)) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000467 return CombineResult::kCannotCombine;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500468 }
469
Jim Van Verthb515ae72018-05-23 16:44:55 -0400470 if (fNeedsGlyphTransform != that->fNeedsGlyphTransform) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000471 return CombineResult::kCannotCombine;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400472 }
473
474 if (fNeedsGlyphTransform &&
475 (thisFirstMatrix.hasPerspective() != thatFirstMatrix.hasPerspective())) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000476 return CombineResult::kCannotCombine;
Jim Van Verthb515ae72018-05-23 16:44:55 -0400477 }
478
Brian Salomon5c6ac642017-12-19 11:09:32 -0500479 if (this->usesDistanceFields()) {
480 if (fDFGPFlags != that->fDFGPFlags) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000481 return CombineResult::kCannotCombine;
joshualitta751c972015-11-20 13:37:32 -0800482 }
483
Jim Van Verthbc2cdd12017-06-08 11:14:35 -0400484 if (fLuminanceColor != that->fLuminanceColor) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000485 return CombineResult::kCannotCombine;
joshualitta751c972015-11-20 13:37:32 -0800486 }
Brian Salomon5c6ac642017-12-19 11:09:32 -0500487 } else {
488 if (kColorBitmapMask_MaskType == fMaskType && this->color() != that->color()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +0000489 return CombineResult::kCannotCombine;
Brian Salomon5c6ac642017-12-19 11:09:32 -0500490 }
joshualitta751c972015-11-20 13:37:32 -0800491 }
492
Brian Salomon344ec422016-12-15 10:58:41 -0500493 fNumGlyphs += that->numGlyphs();
joshualitta751c972015-11-20 13:37:32 -0800494
Jim Van Verth56c37142017-10-31 14:44:25 -0400495 // Reallocate space for geo data if necessary and then import that geo's data.
joshualitta751c972015-11-20 13:37:32 -0800496 int newGeoCount = that->fGeoCount + fGeoCount;
joshualitta751c972015-11-20 13:37:32 -0800497
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400498 // We reallocate at a rate of 1.5x to try to get better total memory usage
499 if (newGeoCount > fGeoDataAllocSize) {
Jim Van Verth56c37142017-10-31 14:44:25 -0400500 int newAllocSize = fGeoDataAllocSize + fGeoDataAllocSize / 2;
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400501 while (newAllocSize < newGeoCount) {
502 newAllocSize += newAllocSize / 2;
503 }
joshualitta751c972015-11-20 13:37:32 -0800504 fGeoData.realloc(newAllocSize);
Jim Van Verthc8a65e32017-10-25 14:25:27 -0400505 fGeoDataAllocSize = newAllocSize;
joshualitta751c972015-11-20 13:37:32 -0800506 }
507
Brian Salomon344ec422016-12-15 10:58:41 -0500508 // We steal the ref on the blobs from the other AtlasTextOp and set its count to 0 so that
joshualitta751c972015-11-20 13:37:32 -0800509 // it doesn't try to unref them.
Brian Salomon344ec422016-12-15 10:58:41 -0500510 memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry));
joshualitta751c972015-11-20 13:37:32 -0800511#ifdef SK_DEBUG
512 for (int i = 0; i < that->fGeoCount; ++i) {
Herb Derbyc514e7d2019-12-11 17:00:31 -0500513 that->fGeoData.get()[i].fBlob = (GrTextBlob*)0x1;
joshualitta751c972015-11-20 13:37:32 -0800514 }
515#endif
516 that->fGeoCount = 0;
517 fGeoCount = newGeoCount;
518
Brian Salomon7eae3e02018-08-07 14:02:38 +0000519 return CombineResult::kMerged;
joshualitta751c972015-11-20 13:37:32 -0800520}
521
Herb Derby3c873af2020-04-29 15:56:07 -0400522static const int kDistanceAdjustLumShift = 5;
523
joshualitta751c972015-11-20 13:37:32 -0800524// TODO trying to figure out why lcd is so whack
Robert Phillips7cd0bfe2019-11-20 16:08:10 -0500525GrGeometryProcessor* GrAtlasTextOp::setupDfProcessor(SkArenaAlloc* arena,
526 const GrShaderCaps& caps,
Greg Daniel9715b6c2019-12-10 15:03:10 -0500527 const GrSurfaceProxyView* views,
528 unsigned int numActiveViews) const {
joshualitta751c972015-11-20 13:37:32 -0800529 bool isLCD = this->isLCD();
Brian Salomon5c6ac642017-12-19 11:09:32 -0500530
531 SkMatrix localMatrix = SkMatrix::I();
532 if (this->usesLocalCoords()) {
533 // If this fails we'll just use I().
Herb Derby1c5be7b2019-12-13 12:03:06 -0500534 bool result = fGeoData[0].fDrawMatrix.invert(&localMatrix);
Brian Salomon5c6ac642017-12-19 11:09:32 -0500535 (void)result;
536 }
joshualitta751c972015-11-20 13:37:32 -0800537
Robert Phillips841c9a52020-03-27 12:41:31 -0400538 auto dfAdjustTable = GrDistanceFieldAdjustTable::Get();
539
joshualitta751c972015-11-20 13:37:32 -0800540 // see if we need to create a new effect
541 if (isLCD) {
Robert Phillips841c9a52020-03-27 12:41:31 -0400542 float redCorrection = dfAdjustTable->getAdjustment(
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400543 SkColorGetR(fLuminanceColor) >> kDistanceAdjustLumShift,
Brian Salomon344ec422016-12-15 10:58:41 -0500544 fUseGammaCorrectDistanceTable);
Robert Phillips841c9a52020-03-27 12:41:31 -0400545 float greenCorrection = dfAdjustTable->getAdjustment(
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400546 SkColorGetG(fLuminanceColor) >> kDistanceAdjustLumShift,
Brian Salomon344ec422016-12-15 10:58:41 -0500547 fUseGammaCorrectDistanceTable);
Robert Phillips841c9a52020-03-27 12:41:31 -0400548 float blueCorrection = dfAdjustTable->getAdjustment(
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400549 SkColorGetB(fLuminanceColor) >> kDistanceAdjustLumShift,
Brian Salomon344ec422016-12-15 10:58:41 -0500550 fUseGammaCorrectDistanceTable);
joshualitta751c972015-11-20 13:37:32 -0800551 GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust =
Brian Salomon344ec422016-12-15 10:58:41 -0500552 GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(
553 redCorrection, greenCorrection, blueCorrection);
Greg Daniel9715b6c2019-12-10 15:03:10 -0500554 return GrDistanceFieldLCDTextGeoProc::Make(arena, caps, views, numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -0500555 GrSamplerState::Filter::kBilerp, widthAdjust,
Brian Osman09068252018-01-03 09:57:29 -0500556 fDFGPFlags, localMatrix);
joshualitta751c972015-11-20 13:37:32 -0800557 } else {
joshualitta751c972015-11-20 13:37:32 -0800558#ifdef SK_GAMMA_APPLY_TO_A8
Jim Van Verth90e89b32017-07-06 16:36:55 -0400559 float correction = 0;
560 if (kAliasedDistanceField_MaskType != fMaskType) {
Jim Van Verth58c3cce2017-10-19 15:50:24 -0400561 U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT,
562 fLuminanceColor);
Robert Phillips841c9a52020-03-27 12:41:31 -0400563 correction = dfAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift,
564 fUseGammaCorrectDistanceTable);
Jim Van Verth90e89b32017-07-06 16:36:55 -0400565 }
Greg Daniel9715b6c2019-12-10 15:03:10 -0500566 return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -0500567 GrSamplerState::Filter::kBilerp, correction,
568 fDFGPFlags, localMatrix);
joshualitta751c972015-11-20 13:37:32 -0800569#else
Greg Daniel9715b6c2019-12-10 15:03:10 -0500570 return GrDistanceFieldA8TextGeoProc::Make(arena, caps, views, numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -0500571 GrSamplerState::Filter::kBilerp,
Brian Salomon5c6ac642017-12-19 11:09:32 -0500572 fDFGPFlags, localMatrix);
joshualitta751c972015-11-20 13:37:32 -0800573#endif
574 }
joshualitta751c972015-11-20 13:37:32 -0800575}
joshualittddd22d82016-02-16 06:47:52 -0800576
Herb Derby4598fa12020-06-10 14:54:22 -0400577#if GR_TEST_UTILS
578std::unique_ptr<GrDrawOp> GrAtlasTextOp::CreateOpTestingOnly(GrRenderTargetContext* rtc,
579 const SkPaint& skPaint,
580 const SkFont& font,
581 const SkMatrixProvider& mtxProvider,
582 const char* text,
583 int x,
584 int y) {
Herb Derby4598fa12020-06-10 14:54:22 -0400585 size_t textLen = (int)strlen(text);
586
587 const SkMatrix& drawMatrix(mtxProvider.localToDevice());
588
589 auto drawOrigin = SkPoint::Make(x, y);
590 SkGlyphRunBuilder builder;
591 builder.drawTextUTF8(skPaint, font, text, textLen, drawOrigin);
592
593 auto glyphRunList = builder.useGlyphRunList();
Ben Wagner525e8762020-07-09 16:19:35 -0400594 if (glyphRunList.empty()) {
595 return nullptr;
596 }
Herb Derby4598fa12020-06-10 14:54:22 -0400597
598 const GrRecordingContextPriv& contextPriv = rtc->fContext->priv();
Herb Derbya08bde62020-06-12 15:46:06 -0400599 GrSDFTOptions SDFOptions = rtc->fContext->priv().SDFTOptions();
Herb Derby4598fa12020-06-10 14:54:22 -0400600
Herb Derby4598fa12020-06-10 14:54:22 -0400601 sk_sp<GrTextBlob> blob = GrTextBlob::Make(glyphRunList, drawMatrix);
602 SkGlyphRunListPainter* painter = &rtc->fGlyphPainter;
603 painter->processGlyphRunList(
Herb Derbyd5764642020-07-08 09:57:11 -0400604 glyphRunList, drawMatrix, rtc->surfaceProps(),
Herb Derby4598fa12020-06-10 14:54:22 -0400605 contextPriv.caps()->shaderCaps()->supportsDistanceFieldText(),
606 SDFOptions, blob.get());
Ben Wagner525e8762020-07-09 16:19:35 -0400607 if (!blob->firstSubRun()) {
608 return nullptr;
609 }
Herb Derby4598fa12020-06-10 14:54:22 -0400610
Herb Derbyd5764642020-07-08 09:57:11 -0400611 return GrAtlasTextOp::MakeBitmap(rtc,
612 skPaint,
613 blob->firstSubRun(),
614 mtxProvider,
615 drawOrigin,
616 SkIRect::MakeEmpty());
Herb Derby4598fa12020-06-10 14:54:22 -0400617}
618
619GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) {
620 // Setup dummy SkPaint / GrPaint / GrRenderTargetContext
621 auto rtc = GrRenderTargetContext::Make(
622 context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kApprox, {1024, 1024});
623
624 SkSimpleMatrixProvider matrixProvider(GrTest::TestMatrixInvertible(random));
625
626 SkPaint skPaint;
627 skPaint.setColor(random->nextU());
628
629 SkFont font;
630 if (random->nextBool()) {
631 font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
632 } else {
633 font.setEdging(random->nextBool() ? SkFont::Edging::kAntiAlias : SkFont::Edging::kAlias);
634 }
635 font.setSubpixel(random->nextBool());
636
637 const char* text = "The quick brown fox jumps over the lazy dog.";
638
639 // create some random x/y offsets, including negative offsets
640 static const int kMaxTrans = 1024;
641 int xPos = (random->nextU() % 2) * 2 - 1;
642 int yPos = (random->nextU() % 2) * 2 - 1;
643 int xInt = (random->nextU() % kMaxTrans) * xPos;
644 int yInt = (random->nextU() % kMaxTrans) * yPos;
645
646 return GrAtlasTextOp::CreateOpTestingOnly(
647 rtc.get(), skPaint, font, matrixProvider, text, xInt, yInt);
648}
649
650#endif
651
652