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, |
| 47 | const GrAppliedClip* clip) { |
| 48 | GrProcessorAnalysisCoverage coverage; |
| 49 | GrProcessorAnalysisColor color; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 50 | if (kColorBitmapMask_MaskType == fMaskType) { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 51 | color.setToUnknown(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 52 | } else { |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 53 | color.setToConstant(fColor); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 54 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 55 | switch (fMaskType) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 56 | case kGrayscaleCoverageMask_MaskType: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 57 | case kAliasedDistanceField_MaskType: |
| 58 | case kGrayscaleDistanceField_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 59 | coverage = GrProcessorAnalysisCoverage::kSingleChannel; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 60 | break; |
| 61 | case kLCDCoverageMask_MaskType: |
| 62 | case kLCDDistanceField_MaskType: |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 63 | case kLCDBGRDistanceField_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 64 | coverage = GrProcessorAnalysisCoverage::kLCD; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 65 | break; |
| 66 | case kColorBitmapMask_MaskType: |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 67 | coverage = GrProcessorAnalysisCoverage::kNone; |
Brian Salomon | c0b642c | 2017-03-27 13:09:36 -0400 | [diff] [blame] | 68 | break; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 69 | } |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 70 | auto analysis = fProcessors.finalize(color, coverage, clip, false, caps, &fColor); |
| 71 | fUsesLocalCoords = analysis.usesLocalCoords(); |
| 72 | fCanCombineOnTouchOrOverlap = |
| 73 | !analysis.requiresDstTexture() && |
| 74 | !(fProcessors.xferProcessor() && fProcessors.xferProcessor()->xferBarrierType(caps)); |
| 75 | return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Brian Salomon | 91326c3 | 2017-08-09 16:02:19 -0400 | [diff] [blame] | 78 | void GrAtlasTextOp::onPrepareDraws(Target* target) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 79 | // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix. |
| 80 | // TODO actually only invert if we don't have RGBA |
| 81 | SkMatrix localMatrix; |
| 82 | if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix)) { |
| 83 | SkDebugf("Cannot invert viewmatrix\n"); |
| 84 | return; |
| 85 | } |
| 86 | |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame^] | 87 | GrMaskFormat maskFormat = this->maskFormat(); |
| 88 | |
| 89 | uint32_t atlasPageCount = fFontCache->getAtlasPageCount(maskFormat); |
| 90 | const sk_sp<GrTextureProxy>* proxies = fFontCache->getProxies(maskFormat); |
| 91 | if (!atlasPageCount || !proxies[0]) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 92 | SkDebugf("Could not allocate backing texture for atlas\n"); |
| 93 | return; |
| 94 | } |
| 95 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 96 | FlushInfo flushInfo; |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 97 | flushInfo.fPipeline = |
| 98 | target->makePipeline(fSRGBFlags, std::move(fProcessors), target->detachAppliedClip()); |
joshualitt | d9d30f7 | 2015-12-08 10:47:55 -0800 | [diff] [blame] | 99 | if (this->usesDistanceFields()) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 100 | flushInfo.fGeometryProcessor = |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame^] | 101 | this->setupDfProcessor(this->viewMatrix(), |
| 102 | fLuminanceColor, this->color(), proxies); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 103 | } else { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 104 | flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame^] | 105 | this->color(), proxies, GrSamplerState::ClampNearest(), maskFormat, |
| 106 | localMatrix, this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 107 | } |
| 108 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 109 | flushInfo.fGlyphsToFlush = 0; |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 110 | size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride(); |
joshualitt | f528e0d | 2015-12-09 06:42:52 -0800 | [diff] [blame] | 111 | SkASSERT(vertexStride == GrAtlasTextBlob::GetVertexStride(maskFormat)); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 112 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 113 | int glyphCount = this->numGlyphs(); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 114 | const GrBuffer* vertexBuffer; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 115 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 116 | void* vertices = target->makeVertexSpace( |
| 117 | vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 118 | flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
| 119 | flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer()); |
| 120 | if (!vertices || !flushInfo.fVertexBuffer) { |
| 121 | SkDebugf("Could not allocate vertices\n"); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
| 126 | |
bsalomon | 342bfc2 | 2016-04-01 06:06:20 -0700 | [diff] [blame] | 127 | GrBlobRegenHelper helper(this, target, &flushInfo); |
bsalomon | d1c71fd | 2016-05-19 12:51:46 -0700 | [diff] [blame] | 128 | SkAutoGlyphCache glyphCache; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 129 | for (int i = 0; i < fGeoCount; i++) { |
joshualitt | 144c3c8 | 2015-11-30 12:30:13 -0800 | [diff] [blame] | 130 | const Geometry& args = fGeoData[i]; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 131 | Blob* blob = args.fBlob; |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 132 | size_t byteCount; |
| 133 | void* blobVertices; |
joshualitt | 8e0ef29 | 2016-02-19 14:13:03 -0800 | [diff] [blame] | 134 | int subRunGlyphCount; |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 135 | blob->regenInOp(target, fFontCache, &helper, args.fRun, args.fSubRun, &glyphCache, |
| 136 | vertexStride, args.fViewMatrix, args.fX, args.fY, args.fColor, |
| 137 | &blobVertices, &byteCount, &subRunGlyphCount); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 138 | |
| 139 | // now copy all vertices |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 140 | memcpy(currVertex, blobVertices, byteCount); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 141 | |
| 142 | currVertex += byteCount; |
| 143 | } |
joshualitt | 60ce86d | 2015-11-23 13:08:22 -0800 | [diff] [blame] | 144 | |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 145 | this->flush(target, &flushInfo); |
| 146 | } |
| 147 | |
Brian Salomon | e5b399e | 2017-07-19 13:50:54 -0400 | [diff] [blame] | 148 | void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { |
Jim Van Verth | eafa64b | 2017-09-18 10:05:00 -0400 | [diff] [blame^] | 149 | GrGeometryProcessor* gp = flushInfo->fGeometryProcessor.get(); |
| 150 | GrMaskFormat maskFormat = this->maskFormat(); |
| 151 | if (gp->numTextureSamplers() != (int)fFontCache->getAtlasPageCount(maskFormat)) { |
| 152 | // During preparation the number of atlas pages has increased. |
| 153 | // Update the proxies used in the GP to match. |
| 154 | if (this->usesDistanceFields()) { |
| 155 | if (this->isLCD()) { |
| 156 | reinterpret_cast<GrDistanceFieldLCDTextGeoProc*>(gp)->addNewProxies( |
| 157 | fFontCache->getProxies(maskFormat), GrSamplerState::ClampBilerp()); |
| 158 | } else { |
| 159 | reinterpret_cast<GrDistanceFieldA8TextGeoProc*>(gp)->addNewProxies( |
| 160 | fFontCache->getProxies(maskFormat), GrSamplerState::ClampBilerp()); |
| 161 | } |
| 162 | } else { |
| 163 | reinterpret_cast<GrBitmapTextGeoProc*>(gp)->addNewProxies( |
| 164 | fFontCache->getProxies(maskFormat), GrSamplerState::ClampNearest()); |
| 165 | } |
| 166 | } |
| 167 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 168 | GrMesh mesh(GrPrimitiveType::kTriangles); |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 169 | int maxGlyphsPerDraw = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 170 | static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 171 | mesh.setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph, |
Chris Dalton | bca46e2 | 2017-05-15 11:03:26 -0600 | [diff] [blame] | 172 | flushInfo->fGlyphsToFlush, maxGlyphsPerDraw); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 173 | mesh.setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 174 | target->draw(flushInfo->fGeometryProcessor.get(), flushInfo->fPipeline, mesh); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 175 | flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
| 176 | flushInfo->fGlyphsToFlush = 0; |
| 177 | } |
| 178 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 179 | bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { |
| 180 | GrAtlasTextOp* that = t->cast<GrAtlasTextOp>(); |
Brian Salomon | 44acb5b | 2017-07-18 19:59:24 -0400 | [diff] [blame] | 181 | if (fProcessors != that->fProcessors) { |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | if (!fCanCombineOnTouchOrOverlap && GrRectsTouchOrOverlap(this->bounds(), that->bounds())) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 186 | return false; |
| 187 | } |
| 188 | |
| 189 | if (fMaskType != that->fMaskType) { |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | if (!this->usesDistanceFields()) { |
joshualitt | d9d30f7 | 2015-12-08 10:47:55 -0800 | [diff] [blame] | 194 | if (kColorBitmapMask_MaskType == fMaskType && this->color() != that->color()) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 198 | return false; |
| 199 | } |
| 200 | } else { |
| 201 | if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 202 | return false; |
| 203 | } |
| 204 | |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 205 | if (fLuminanceColor != that->fLuminanceColor) { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 206 | return false; |
| 207 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 210 | fNumGlyphs += that->numGlyphs(); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 211 | |
| 212 | // Reallocate space for geo data if necessary and then import that's geo data. |
| 213 | int newGeoCount = that->fGeoCount + fGeoCount; |
| 214 | // We assume (and here enforce) that the allocation size is the smallest power of two that |
| 215 | // is greater than or equal to the number of geometries (and at least |
| 216 | // kMinGeometryAllocated). |
| 217 | int newAllocSize = GrNextPow2(newGeoCount); |
| 218 | int currAllocSize = SkTMax<int>(kMinGeometryAllocated, GrNextPow2(fGeoCount)); |
| 219 | |
| 220 | if (newGeoCount > currAllocSize) { |
| 221 | fGeoData.realloc(newAllocSize); |
| 222 | } |
| 223 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 224 | // 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] | 225 | // it doesn't try to unref them. |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 226 | memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry)); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 227 | #ifdef SK_DEBUG |
| 228 | for (int i = 0; i < that->fGeoCount; ++i) { |
| 229 | that->fGeoData.get()[i].fBlob = (Blob*)0x1; |
| 230 | } |
| 231 | #endif |
| 232 | that->fGeoCount = 0; |
| 233 | fGeoCount = newGeoCount; |
| 234 | |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 235 | this->joinBounds(*that); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 236 | return true; |
| 237 | } |
| 238 | |
| 239 | // TODO just use class params |
| 240 | // TODO trying to figure out why lcd is so whack |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 241 | sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor( |
| 242 | const SkMatrix& viewMatrix, |
| 243 | SkColor luminanceColor, |
| 244 | GrColor color, |
| 245 | const sk_sp<GrTextureProxy> p[kMaxTextures]) const { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 246 | bool isLCD = this->isLCD(); |
| 247 | // set up any flags |
| 248 | uint32_t flags = viewMatrix.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
jvanverth | cf371bb | 2016-03-10 11:10:43 -0800 | [diff] [blame] | 249 | flags |= viewMatrix.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0; |
brianosman | b461d34 | 2016-04-13 13:10:14 -0700 | [diff] [blame] | 250 | flags |= fUseGammaCorrectDistanceTable ? kGammaCorrect_DistanceFieldEffectFlag : 0; |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 251 | flags |= (kAliasedDistanceField_MaskType == fMaskType) ? kAliased_DistanceFieldEffectFlag : 0; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 252 | |
| 253 | // see if we need to create a new effect |
| 254 | if (isLCD) { |
| 255 | flags |= kUseLCD_DistanceFieldEffectFlag; |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 256 | flags |= (kLCDBGRDistanceField_MaskType == fMaskType) ? kBGR_DistanceFieldEffectFlag : 0; |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 257 | |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 258 | float redCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 259 | SkColorGetR(luminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 260 | fUseGammaCorrectDistanceTable); |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 261 | float greenCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 262 | SkColorGetG(luminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 263 | fUseGammaCorrectDistanceTable); |
brianosman | 0586f5c | 2016-04-12 12:48:21 -0700 | [diff] [blame] | 264 | float blueCorrection = fDistanceAdjustTable->getAdjustment( |
Jim Van Verth | bc2cdd1 | 2017-06-08 11:14:35 -0400 | [diff] [blame] | 265 | SkColorGetB(luminanceColor) >> kDistanceAdjustLumShift, |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 266 | fUseGammaCorrectDistanceTable); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 267 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 268 | GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make( |
| 269 | redCorrection, greenCorrection, blueCorrection); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 270 | |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 271 | return GrDistanceFieldLCDTextGeoProc::Make(color, viewMatrix, p, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 272 | GrSamplerState::ClampBilerp(), widthAdjust, |
| 273 | flags, this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 274 | } else { |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 275 | #ifdef SK_GAMMA_APPLY_TO_A8 |
Jim Van Verth | 90e89b3 | 2017-07-06 16:36:55 -0400 | [diff] [blame] | 276 | float correction = 0; |
| 277 | if (kAliasedDistanceField_MaskType != fMaskType) { |
| 278 | U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, luminanceColor); |
| 279 | correction = fDistanceAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift, |
| 280 | fUseGammaCorrectDistanceTable); |
| 281 | } |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 282 | return GrDistanceFieldA8TextGeoProc::Make(color, viewMatrix, p, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 283 | GrSamplerState::ClampBilerp(), correction, flags, |
| 284 | this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 285 | #else |
Jim Van Verth | a950b63 | 2017-09-12 11:54:11 -0400 | [diff] [blame] | 286 | return GrDistanceFieldA8TextGeoProc::Make(color, viewMatrix, p, |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 287 | GrSamplerState::ClampBilerp(), flags, |
| 288 | this->usesLocalCoords()); |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 289 | #endif |
| 290 | } |
joshualitt | a751c97 | 2015-11-20 13:37:32 -0800 | [diff] [blame] | 291 | } |
joshualitt | ddd22d8 | 2016-02-16 06:47:52 -0800 | [diff] [blame] | 292 | |
Brian Salomon | 344ec42 | 2016-12-15 10:58:41 -0500 | [diff] [blame] | 293 | void GrBlobRegenHelper::flush() { fOp->flush(fTarget, fFlushInfo); } |