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 | |
Brian Salomon | 09e019e | 2016-12-15 10:20:35 -0500 | [diff] [blame] | 8 | #include "GrAtlasTextOp.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 9 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 10 | #include "GrContext.h" |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 11 | #include "GrOpFlushState.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 12 | #include "GrResourceProvider.h" |
| 13 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 14 | #include "SkGlyphCache.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 15 | #include "SkMathPriv.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 16 | |
| 17 | #include "effects/GrBitmapTextGeoProc.h" |
| 18 | #include "effects/GrDistanceFieldGeoProc.h" |
Brian Salomon | f856fd1 | 2016-12-16 14:24:34 -0500 | [diff] [blame] | 19 | #include "text/GrAtlasGlyphCache.h" |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 20 | |
joshualitt | 60ce86d | 2015-11-23 13:08:22 -0800 | [diff] [blame] | 21 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 22 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 23 | static const int kDistanceAdjustLumShift = 5; |
| 24 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 25 | SkString GrAtlasTextOp::dumpInfo() const { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 26 | SkString str; |
| 27 | |
| 28 | for (int i = 0; i < fGeoCount; ++i) { |
| 29 | str.appendf("%d: Color: 0x%08x Trans: %.2f,%.2f Runs: %d\n", |
| 30 | i, |
| 31 | fGeoData[i].fColor, |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 32 | fGeoData[i].fX, |
| 33 | fGeoData[i].fY, |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 34 | fGeoData[i].fBlob->runCount()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 35 | } |
| 36 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 37 | str += fProcessors.dumpProcessors(); |
| 38 | str += INHERITED::dumpInfo(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 39 | return str; |
| 40 | } |
| 41 | |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 42 | GrDrawOp::FixedFunctionFlags GrAtlasTextOp::fixedFunctionFlags() const { |
| 43 | return FixedFunctionFlags::kNone; |
| 44 | } |
| 45 | |
| 46 | GrDrawOp::RequiresDstTexture GrAtlasTextOp::finalize(const GrCaps& caps, |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 47 | const GrAppliedClip* clip, |
| 48 | GrPixelConfigIsClamped dstIsClamped) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 49 | GrProcessorAnalysisCoverage coverage; |
| 50 | GrProcessorAnalysisColor color; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 51 | if (kColorBitmapMask_MaskType == fMaskType) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 52 | color.setToUnknown(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 53 | } else { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 54 | color.setToConstant(fColor); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 55 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 56 | switch (fMaskType) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 57 | case kGrayscaleCoverageMask_MaskType: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 58 | case kAliasedDistanceField_MaskType: |
| 59 | case kGrayscaleDistanceField_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 60 | coverage = GrProcessorAnalysisCoverage::kSingleChannel; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 61 | break; |
| 62 | case kLCDCoverageMask_MaskType: |
| 63 | case kLCDDistanceField_MaskType: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 64 | case kLCDBGRDistanceField_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 65 | coverage = GrProcessorAnalysisCoverage::kLCD; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 66 | break; |
| 67 | case kColorBitmapMask_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 68 | coverage = GrProcessorAnalysisCoverage::kNone; |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 69 | break; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 70 | } |
Brian Osman | 9a725dd | 2017-09-20 09:53:22 -0400 | [diff] [blame] | 71 | auto analysis = fProcessors.finalize(color, coverage, clip, false, caps, dstIsClamped, &fColor); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 72 | fUsesLocalCoords = analysis.usesLocalCoords(); |
| 73 | fCanCombineOnTouchOrOverlap = |
| 74 | !analysis.requiresDstTexture() && |
| 75 | !(fProcessors.xferProcessor() && fProcessors.xferProcessor()->xferBarrierType(caps)); |
| 76 | return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 79 | static void clip_quads(const SkIRect& clipRect, |
| 80 | unsigned char* currVertex, unsigned char* blobVertices, |
| 81 | size_t vertexStride, int glyphCount) { |
| 82 | for (int i = 0; i < glyphCount; ++i) { |
| 83 | SkPoint* blobPositionLT = reinterpret_cast<SkPoint*>(blobVertices); |
| 84 | SkPoint* blobPositionRB = reinterpret_cast<SkPoint*>(blobVertices + 3*vertexStride); |
| 85 | |
| 86 | SkRect positionRect = SkRect::MakeLTRB(blobPositionLT->fX, |
| 87 | blobPositionLT->fY, |
| 88 | blobPositionRB->fX, |
| 89 | blobPositionRB->fY); |
| 90 | if (clipRect.contains(positionRect)) { |
| 91 | memcpy(currVertex, blobVertices, 4 * vertexStride); |
| 92 | currVertex += 4 * vertexStride; |
| 93 | } else { |
| 94 | // Pull out some more data that we'll need. |
| 95 | // In the LCD case the color will be garbage, but we'll overwrite it with the texcoords |
| 96 | // and it avoids a lot of conditionals. |
| 97 | SkColor color = *reinterpret_cast<SkColor*>(blobVertices + sizeof(SkPoint)); |
| 98 | size_t coordOffset = vertexStride - sizeof(SkIPoint16); |
| 99 | SkIPoint16* blobCoordsLT = reinterpret_cast<SkIPoint16*>(blobVertices + coordOffset); |
| 100 | SkIPoint16* blobCoordsRB = reinterpret_cast<SkIPoint16*>(blobVertices + |
| 101 | 3*vertexStride + |
| 102 | coordOffset); |
| 103 | SkIRect coordsRect = SkIRect::MakeLTRB(blobCoordsLT->fX >> 1, |
| 104 | blobCoordsLT->fY >> 1, |
| 105 | blobCoordsRB->fX >> 1, |
| 106 | blobCoordsRB->fY >> 1); |
| 107 | int pageIndexX = blobCoordsLT->fX & 0x1; |
| 108 | int pageIndexY = blobCoordsLT->fY & 0x1; |
| 109 | |
| 110 | SkASSERT(positionRect.width() == coordsRect.width()); |
| 111 | |
| 112 | // Clip position and texCoords to the clipRect |
| 113 | if (positionRect.fLeft < clipRect.fLeft) { |
| 114 | coordsRect.fLeft += clipRect.fLeft - positionRect.fLeft; |
| 115 | positionRect.fLeft = clipRect.fLeft; |
| 116 | } |
| 117 | if (positionRect.fTop < clipRect.fTop) { |
| 118 | coordsRect.fTop += clipRect.fTop - positionRect.fTop; |
| 119 | positionRect.fTop = clipRect.fTop; |
| 120 | } |
| 121 | if (positionRect.fRight > clipRect.fRight) { |
| 122 | coordsRect.fRight += clipRect.fRight - positionRect.fRight; |
| 123 | positionRect.fRight = clipRect.fRight; |
| 124 | } |
| 125 | if (positionRect.fBottom > clipRect.fBottom) { |
| 126 | coordsRect.fBottom += clipRect.fBottom - positionRect.fBottom; |
| 127 | positionRect.fBottom = clipRect.fBottom; |
| 128 | } |
| 129 | if (positionRect.fLeft > positionRect.fRight) { |
| 130 | positionRect.fLeft = positionRect.fRight; |
| 131 | } |
| 132 | if (positionRect.fTop > positionRect.fBottom) { |
| 133 | positionRect.fTop = positionRect.fBottom; |
| 134 | } |
| 135 | coordsRect.fLeft = coordsRect.fLeft << 1 | pageIndexX; |
| 136 | coordsRect.fTop = coordsRect.fTop << 1 | pageIndexY; |
| 137 | coordsRect.fRight = coordsRect.fRight << 1 | pageIndexX; |
| 138 | coordsRect.fBottom = coordsRect.fBottom << 1 | pageIndexY; |
| 139 | |
| 140 | SkPoint* currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 141 | currPosition->fX = positionRect.fLeft; |
| 142 | currPosition->fY = positionRect.fTop; |
| 143 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
| 144 | SkIPoint16* currCoords = reinterpret_cast<SkIPoint16*>(currVertex + coordOffset); |
| 145 | currCoords->fX = coordsRect.fLeft; |
| 146 | currCoords->fY = coordsRect.fTop; |
| 147 | currVertex += vertexStride; |
| 148 | |
| 149 | currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 150 | currPosition->fX = positionRect.fLeft; |
| 151 | currPosition->fY = positionRect.fBottom; |
| 152 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
| 153 | currCoords = reinterpret_cast<SkIPoint16*>(currVertex + coordOffset); |
| 154 | currCoords->fX = coordsRect.fLeft; |
| 155 | currCoords->fY = coordsRect.fBottom; |
| 156 | currVertex += vertexStride; |
| 157 | |
| 158 | currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 159 | currPosition->fX = positionRect.fRight; |
| 160 | currPosition->fY = positionRect.fTop; |
| 161 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
| 162 | currCoords = reinterpret_cast<SkIPoint16*>(currVertex + coordOffset); |
| 163 | currCoords->fX = coordsRect.fRight; |
| 164 | currCoords->fY = coordsRect.fTop; |
| 165 | currVertex += vertexStride; |
| 166 | |
| 167 | currPosition = reinterpret_cast<SkPoint*>(currVertex); |
| 168 | currPosition->fX = positionRect.fRight; |
| 169 | currPosition->fY = positionRect.fBottom; |
| 170 | *(reinterpret_cast<SkColor*>(currVertex + sizeof(SkPoint))) = color; |
| 171 | currCoords = reinterpret_cast<SkIPoint16*>(currVertex + coordOffset); |
| 172 | currCoords->fX = coordsRect.fRight; |
| 173 | currCoords->fY = coordsRect.fBottom; |
| 174 | currVertex += vertexStride; |
| 175 | } |
| 176 | |
| 177 | blobVertices += 4 * vertexStride; |
| 178 | } |
| 179 | } |
| 180 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 181 | void GrAtlasTextOp::onPrepareDraws(Target* target) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 182 | // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix. |
| 183 | // TODO actually only invert if we don't have RGBA |
| 184 | SkMatrix localMatrix; |
| 185 | if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { |
| 186 | SkDebugf("Cannot invert viewmatrix\n"); |
| 187 | return; |
| 188 | } |
| 189 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 190 | GrMaskFormat maskFormat = this->maskFormat(); |
| 191 | |
| 192 | uint32_t atlasPageCount = fFontCache->getAtlasPageCount(maskFormat); |
| 193 | const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat); |
| 194 | if (!atlasPageCount || !proxies[0]) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 195 | SkDebugf("Could not allocate backing texture for atlas\n"); |
| 196 | return; |
| 197 | } |
| 198 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 199 | FlushInfo flushInfo; |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 200 | flushInfo.fPipeline = |
| 201 | target->makePipeline(fSRGBFlags, std::move(fProcessors), target->detachAppliedClip()); |
joshualitt | d9d30f7 | 2015-12-08 10:47:55 -0800 | [diff] [blame] | 202 | if (this->usesDistanceFields()) { |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 203 | flushInfo.fGeometryProcessor = this->setupDfProcessor(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 204 | } else { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 205 | flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 206 | this->color(), proxies, GrSamplerState::ClampNearest(), maskFormat, |
| 207 | localMatrix, this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 208 | } |
| 209 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 210 | flushInfo.fGlyphsToFlush = 0; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 211 | size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride(); |
joshualitt | f528e0d | 2015-12-09 06:42:52 -0800 | [diff] [blame] | 212 | SkASSERT(vertexStride == GrAtlasTextBlob::GetVertexStride(maskFormat)); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 213 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 214 | int glyphCount = this->numGlyphs(); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 215 | const GrBuffer* vertexBuffer; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 216 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 217 | void* vertices = target->makeVertexSpace( |
| 218 | vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 219 | flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
Brian Salomon | d28a79d | 2017-10-16 13:01:07 -0400 | [diff] [blame] | 220 | flushInfo.fIndexBuffer = target->resourceProvider()->refQuadIndexBuffer(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 221 | if (!vertices || !flushInfo.fVertexBuffer) { |
| 222 | SkDebugf("Could not allocate vertices\n"); |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
| 227 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 228 | GrBlobRegenHelper helper(this, target, &flushInfo); |
bsalomon | d1c71fd | 2016-05-19 12:51:46 -0700 | [diff] [blame] | 229 | SkAutoGlyphCache glyphCache; |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 230 | // each of these is a SubRun |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 231 | for (int i = 0; i < fGeoCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 232 | const Geometry& args = fGeoData[i]; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 233 | Blob* blob = args.fBlob; |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 234 | size_t byteCount; |
| 235 | void* blobVertices; |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 236 | int subRunGlyphCount; |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 237 | blob->regenInOp(target, fFontCache, &helper, args.fRun, args.fSubRun, &glyphCache, |
| 238 | vertexStride, args.fViewMatrix, args.fX, args.fY, args.fColor, |
| 239 | &blobVertices, &byteCount, &subRunGlyphCount); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 240 | |
| 241 | // now copy all vertices |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 242 | if (args.fClipRect.isEmpty()) { |
| 243 | memcpy(currVertex, blobVertices, byteCount); |
| 244 | } else { |
| 245 | clip_quads(args.fClipRect, currVertex, reinterpret_cast<unsigned char*>(blobVertices), |
| 246 | vertexStride, subRunGlyphCount); |
| 247 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 248 | |
| 249 | currVertex += byteCount; |
| 250 | } |
joshualitt | 60ce86d | 2015-11-23 13:08:22 -0800 | [diff] [blame] | 251 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 252 | this->flush(target, &flushInfo); |
| 253 | } |
| 254 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 255 | void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame] | 256 | GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get(); |
| 257 | GrMaskFormat maskFormat = this->maskFormat(); |
| 258 | if (gp->numTextureSamplers() != (int)fFontCache->getAtlasPageCount(maskFormat)) { |
| 259 | // During preparation the number of atlas pages has increased. |
| 260 | // Update the proxies used in the GP to match. |
| 261 | if (this->usesDistanceFields()) { |
| 262 | if (this->isLCD()) { |
| 263 | reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewProxies( |
| 264 | fFontCache->getProxies(maskFormat), GrSamplerState::ClampBilerp()); |
| 265 | } else { |
| 266 | reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewProxies( |
| 267 | fFontCache->getProxies(maskFormat), GrSamplerState::ClampBilerp()); |
| 268 | } |
| 269 | } else { |
| 270 | reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewProxies( |
| 271 | fFontCache->getProxies(maskFormat), GrSamplerState::ClampNearest()); |
| 272 | } |
| 273 | } |
| 274 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 275 | GrMesh mesh(GrPrimitiveType::kTriangles); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 276 | int maxGlyphsPerDraw = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 277 | static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 278 | mesh.setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 279 | flushInfo->fGlyphsToFlush, maxGlyphsPerDraw); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 280 | mesh.setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 281 | target->draw(flushInfo->fGeometryProcessor.get(), flushInfo->fPipeline, mesh); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 282 | flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
| 283 | flushInfo->fGlyphsToFlush = 0; |
| 284 | } |
| 285 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 286 | bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { |
| 287 | GrAtlasTextOp* that = t->cast<GrAtlasTextOp>(); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 288 | if (fProcessors != that->fProcessors) { |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | if (!fCanCombineOnTouchOrOverlap && GrRectsTouchOrOverlap(this->bounds(), that->bounds())) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 293 | return false; |
| 294 | } |
| 295 | |
| 296 | if (fMaskType != that->fMaskType) { |
| 297 | return false; |
| 298 | } |
| 299 | |
| 300 | if (!this->usesDistanceFields()) { |
joshualitt | d9d30f7 | 2015-12-08 10:47:55 -0800 | [diff] [blame] | 301 | if (kColorBitmapMask_MaskType == fMaskType && this->color() != that->color()) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 302 | return false; |
| 303 | } |
| 304 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 305 | return false; |
| 306 | } |
| 307 | } else { |
| 308 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 309 | return false; |
| 310 | } |
| 311 | |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 312 | if (fLuminanceColor != that->fLuminanceColor) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 313 | return false; |
| 314 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 317 | fNumGlyphs += that->numGlyphs(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 318 | |
| 319 | // Reallocate space for geo data if necessary and then import that's geo data. |
| 320 | int newGeoCount = that->fGeoCount + fGeoCount; |
| 321 | // We assume (and here enforce) that the allocation size is the smallest power of two that |
| 322 | // is greater than or equal to the number of geometries (and at least |
| 323 | // kMinGeometryAllocated). |
| 324 | int newAllocSize = GrNextPow2(newGeoCount); |
| 325 | int currAllocSize = SkTMax<int>(kMinGeometryAllocated, GrNextPow2(fGeoCount)); |
| 326 | |
| 327 | if (newGeoCount > currAllocSize) { |
| 328 | fGeoData.realloc(newAllocSize); |
| 329 | } |
| 330 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 331 | // 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] | 332 | // it doesn't try to unref them. |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 333 | memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry)); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 334 | #ifdef SK_DEBUG |
| 335 | for (int i = 0; i < that->fGeoCount; ++i) { |
| 336 | that->fGeoData.get()[i].fBlob = (Blob*)0x1; |
| 337 | } |
| 338 | #endif |
| 339 | that->fGeoCount = 0; |
| 340 | fGeoCount = newGeoCount; |
| 341 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 342 | this->joinBounds(*that); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 343 | return true; |
| 344 | } |
| 345 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 346 | // TODO trying to figure out why lcd is so whack |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 347 | // (see comments in GrAtlasTextContext::ComputeCanonicalColor) |
| 348 | sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor() const { |
| 349 | const SkMatrix& viewMatrix = this->viewMatrix(); |
| 350 | const sk_sp<GrTextureProxy>* p = fFontCache->getProxies(this->maskFormat()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 351 | bool isLCD = this->isLCD(); |
| 352 | // set up any flags |
| 353 | uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
jvanverth | cf371bb | 2016-03-10 11:10:43 -0800 | [diff] [blame] | 354 | flags |= viewMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0; |
brianosman | b461d34 | 2016-04-13 13:10:14 -0700 | [diff] [blame] | 355 | flags |= fUseGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0; |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 356 | flags |= (kAliasedDistanceField_MaskType == fMaskType) ? kAliased_DistanceFieldEffectFlag : 0; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 357 | |
| 358 | // see if we need to create a new effect |
| 359 | if (isLCD) { |
| 360 | flags |= kUseLCD_DistanceFieldEffectFlag; |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 361 | flags |= (kLCDBGRDistanceField_MaskType == fMaskType) ? kBGR_DistanceFieldEffectFlag : 0; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 362 | |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 363 | float redCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 364 | SkColorGetR(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 365 | fUseGammaCorrectDistanceTable); |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 366 | float greenCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 367 | SkColorGetG(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 368 | fUseGammaCorrectDistanceTable); |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 369 | float blueCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 370 | SkColorGetB(fLuminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 371 | fUseGammaCorrectDistanceTable); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 372 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 373 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make( |
| 374 | redCorrection, greenCorrection, blueCorrection); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 375 | |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 376 | return GrDistanceFieldLCDTextGeoProc::Make(this->color(), viewMatrix, p, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 377 | GrSamplerState::ClampBilerp(), widthAdjust, |
| 378 | flags, this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 379 | } else { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 380 | #ifdef SK_GAMMA_APPLY_TO_A8 |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 381 | float correction = 0; |
| 382 | if (kAliasedDistanceField_MaskType != fMaskType) { |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 383 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, |
| 384 | fLuminanceColor); |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 385 | correction = fDistanceAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift, |
| 386 | fUseGammaCorrectDistanceTable); |
| 387 | } |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 388 | return GrDistanceFieldA8TextGeoProc::Make(this->color(), viewMatrix, p, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 389 | GrSamplerState::ClampBilerp(), correction, flags, |
| 390 | this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 391 | #else |
Jim Van Verth | 58c3cce | 2017-10-19 15:50:24 -0400 | [diff] [blame^] | 392 | return GrDistanceFieldA8TextGeoProc::Make(this->color(), viewMatrix, p, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 393 | GrSamplerState::ClampBilerp(), flags, |
| 394 | this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 395 | #endif |
| 396 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 397 | } |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 398 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 399 | void GrBlobRegenHelper::flush() { fOp->flush(fTarget, fFlushInfo); } |