diff options
Diffstat (limited to 'src/gpu/batches')
-rw-r--r-- | src/gpu/batches/GrAtlasTextOp.cpp | 122 | ||||
-rw-r--r-- | src/gpu/batches/GrAtlasTextOp.h | 129 |
2 files changed, 108 insertions, 143 deletions
diff --git a/src/gpu/batches/GrAtlasTextOp.cpp b/src/gpu/batches/GrAtlasTextOp.cpp index 0b692d15b3..d576789e26 100644 --- a/src/gpu/batches/GrAtlasTextOp.cpp +++ b/src/gpu/batches/GrAtlasTextOp.cpp @@ -28,7 +28,7 @@ static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { static const int kDistanceAdjustLumShift = 5; -SkString GrAtlasTextBatch::dumpInfo() const { +SkString GrAtlasTextOp::dumpInfo() const { SkString str; for (int i = 0; i < fGeoCount; ++i) { @@ -45,13 +45,13 @@ SkString GrAtlasTextBatch::dumpInfo() const { return str; } -void GrAtlasTextBatch::computePipelineOptimizations(GrInitInvariantOutput* color, - GrInitInvariantOutput* coverage, - GrBatchToXPOverrides* overrides) const { +void GrAtlasTextOp::computePipelineOptimizations(GrInitInvariantOutput* color, + GrInitInvariantOutput* coverage, + GrBatchToXPOverrides* overrides) const { if (kColorBitmapMask_MaskType == fMaskType) { color->setUnknownFourComponents(); } else { - color->setKnownFourComponents(fBatch.fColor); + color->setKnownFourComponents(fColor); } switch (fMaskType) { case kGrayscaleDistanceField_MaskType: @@ -68,21 +68,20 @@ void GrAtlasTextBatch::computePipelineOptimizations(GrInitInvariantOutput* color } } -void GrAtlasTextBatch::initBatchTracker(const GrXPOverridesForBatch& overrides) { +void GrAtlasTextOp::initBatchTracker(const GrXPOverridesForBatch& overrides) { // Handle any color overrides if (!overrides.readsColor()) { fGeoData[0].fColor = GrColor_ILLEGAL; } overrides.getOverrideColorIfSet(&fGeoData[0].fColor); - // setup batch properties - fBatch.fColorIgnored = !overrides.readsColor(); - fBatch.fColor = fGeoData[0].fColor; - fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); - fBatch.fCoverageIgnored = !overrides.readsCoverage(); + fColorIgnored = !overrides.readsColor(); + fColor = fGeoData[0].fColor; + fUsesLocalCoords = overrides.readsLocalCoords(); + fCoverageIgnored = !overrides.readsCoverage(); } -void GrAtlasTextBatch::onPrepareDraws(Target* target) const { +void GrAtlasTextOp::onPrepareDraws(Target* target) const { // if we have RGB, then we won't have any SkShaders so no need to use a localmatrix. // TODO actually only invert if we don't have RGBA SkMatrix localMatrix; @@ -102,15 +101,11 @@ void GrAtlasTextBatch::onPrepareDraws(Target* target) const { FlushInfo flushInfo; if (this->usesDistanceFields()) { flushInfo.fGeometryProcessor = - this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this->color(), texture); + this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this->color(), texture); } else { GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode); - flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make(this->color(), - texture, - params, - maskFormat, - localMatrix, - this->usesLocalCoords()); + flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( + this->color(), texture, params, maskFormat, localMatrix, this->usesLocalCoords()); } flushInfo.fGlyphsToFlush = 0; @@ -120,10 +115,8 @@ void GrAtlasTextBatch::onPrepareDraws(Target* target) const { int glyphCount = this->numGlyphs(); const GrBuffer* vertexBuffer; - void* vertices = target->makeVertexSpace(vertexStride, - glyphCount * kVerticesPerGlyph, - &vertexBuffer, - &flushInfo.fVertexOffset); + void* vertices = target->makeVertexSpace( + vertexStride, glyphCount * kVerticesPerGlyph, &vertexBuffer, &flushInfo.fVertexOffset); flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer()); if (!vertices || !flushInfo.fVertexBuffer) { @@ -152,7 +145,7 @@ void GrAtlasTextBatch::onPrepareDraws(Target* target) const { // bounds sanity check SkRect rect; rect.setLargestInverted(); - SkPoint* vertex = (SkPoint*) ((char*)blobVertices); + SkPoint* vertex = (SkPoint*)((char*)blobVertices); rect.growToInclude(vertex, vertexStride, kVerticesPerGlyph * subRunGlyphCount); if (this->usesDistanceFields()) { @@ -170,21 +163,20 @@ void GrAtlasTextBatch::onPrepareDraws(Target* target) const { this->flush(target, &flushInfo); } -void GrAtlasTextBatch::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { +void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const { GrMesh mesh; int maxGlyphsPerDraw = - static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6); + static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6); mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer.get(), - flushInfo->fIndexBuffer.get(), flushInfo->fVertexOffset, - kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsToFlush, - maxGlyphsPerDraw); + flushInfo->fIndexBuffer.get(), flushInfo->fVertexOffset, kVerticesPerGlyph, + kIndicesPerGlyph, flushInfo->fGlyphsToFlush, maxGlyphsPerDraw); target->draw(flushInfo->fGeometryProcessor.get(), mesh); flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; flushInfo->fGlyphsToFlush = 0; } -bool GrAtlasTextBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { - GrAtlasTextBatch* that = t->cast<GrAtlasTextBatch>(); +bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { + GrAtlasTextOp* that = t->cast<GrAtlasTextOp>(); if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), that->bounds(), caps)) { return false; @@ -215,7 +207,7 @@ bool GrAtlasTextBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { } } - fBatch.fNumGlyphs += that->numGlyphs(); + fNumGlyphs += that->numGlyphs(); // Reallocate space for geo data if necessary and then import that's geo data. int newGeoCount = that->fGeoCount + fGeoCount; @@ -229,9 +221,9 @@ bool GrAtlasTextBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { fGeoData.realloc(newAllocSize); } - memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry)); - // We steal the ref on the blobs from the other TextBatch and set its count to 0 so that + // We steal the ref on the blobs from the other AtlasTextOp and set its count to 0 so that // it doesn't try to unref them. + memcpy(&fGeoData[fGeoCount], that->fGeoData.get(), that->fGeoCount * sizeof(Geometry)); #ifdef SK_DEBUG for (int i = 0; i < that->fGeoCount; ++i) { that->fGeoData.get()[i].fBlob = (Blob*)0x1; @@ -246,10 +238,10 @@ bool GrAtlasTextBatch::onCombineIfPossible(GrOp* t, const GrCaps& caps) { // TODO just use class params // TODO trying to figure out why lcd is so whack -sk_sp<GrGeometryProcessor> GrAtlasTextBatch::setupDfProcessor(const SkMatrix& viewMatrix, - SkColor filteredColor, - GrColor color, - GrTexture* texture) const { +sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(const SkMatrix& viewMatrix, + SkColor filteredColor, + GrColor color, + GrTexture* texture) const { GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode); bool isLCD = this->isLCD(); // set up any flags @@ -265,50 +257,32 @@ sk_sp<GrGeometryProcessor> GrAtlasTextBatch::setupDfProcessor(const SkMatrix& vi GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor); float redCorrection = fDistanceAdjustTable->getAdjustment( - GrColorUnpackR(colorNoPreMul) >> kDistanceAdjustLumShift, - fUseGammaCorrectDistanceTable); + GrColorUnpackR(colorNoPreMul) >> kDistanceAdjustLumShift, + fUseGammaCorrectDistanceTable); float greenCorrection = fDistanceAdjustTable->getAdjustment( - GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift, - fUseGammaCorrectDistanceTable); + GrColorUnpackG(colorNoPreMul) >> kDistanceAdjustLumShift, + fUseGammaCorrectDistanceTable); float blueCorrection = fDistanceAdjustTable->getAdjustment( - GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift, - fUseGammaCorrectDistanceTable); + GrColorUnpackB(colorNoPreMul) >> kDistanceAdjustLumShift, + fUseGammaCorrectDistanceTable); GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = - GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(redCorrection, - greenCorrection, - blueCorrection); - - return GrDistanceFieldLCDTextGeoProc::Make(color, - viewMatrix, - texture, - params, - widthAdjust, - flags, - this->usesLocalCoords()); + GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make( + redCorrection, greenCorrection, blueCorrection); + + return GrDistanceFieldLCDTextGeoProc::Make( + color, viewMatrix, texture, params, widthAdjust, flags, this->usesLocalCoords()); } else { #ifdef SK_GAMMA_APPLY_TO_A8 U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, filteredColor); - float correction = fDistanceAdjustTable->getAdjustment( - lum >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable); - return GrDistanceFieldA8TextGeoProc::Make(color, - viewMatrix, - texture, - params, - correction, - flags, - this->usesLocalCoords()); + float correction = fDistanceAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift, + fUseGammaCorrectDistanceTable); + return GrDistanceFieldA8TextGeoProc::Make( + color, viewMatrix, texture, params, correction, flags, this->usesLocalCoords()); #else - return GrDistanceFieldA8TextGeoProc::Make(color, - viewMatrix, - texture, - params, - flags, - this->usesLocalCoords()); + return GrDistanceFieldA8TextGeoProc::Make( + color, viewMatrix, texture, params, flags, this->usesLocalCoords()); #endif } - } -void GrBlobRegenHelper::flush() { - fBatch->flush(fTarget, fFlushInfo); -} +void GrBlobRegenHelper::flush() { fOp->flush(fTarget, fFlushInfo); } diff --git a/src/gpu/batches/GrAtlasTextOp.h b/src/gpu/batches/GrAtlasTextOp.h index 313a78e940..6cb269c099 100644 --- a/src/gpu/batches/GrAtlasTextOp.h +++ b/src/gpu/batches/GrAtlasTextOp.h @@ -5,15 +5,15 @@ * found in the LICENSE file. */ -#ifndef GrAtlasTextBatch_DEFINED -#define GrAtlasTextBatch_DEFINED +#ifndef GrAtlasTextOp_DEFINED +#define GrAtlasTextOp_DEFINED #include "batches/GrMeshDrawOp.h" #include "text/GrAtlasTextContext.h" #include "text/GrDistanceFieldAdjustTable.h" -class GrAtlasTextBatch final : public GrMeshDrawOp { +class GrAtlasTextOp final : public GrMeshDrawOp { public: DEFINE_OP_CLASS_ID @@ -31,57 +31,55 @@ public: GrColor fColor; }; - static GrAtlasTextBatch* CreateBitmap(GrMaskFormat maskFormat, int glyphCount, - GrBatchFontCache* fontCache) { - GrAtlasTextBatch* batch = new GrAtlasTextBatch; + static sk_sp<GrAtlasTextOp> MakeBitmap(GrMaskFormat maskFormat, int glyphCount, + GrBatchFontCache* fontCache) { + sk_sp<GrAtlasTextOp> op(new GrAtlasTextOp); - batch->fFontCache = fontCache; + op->fFontCache = fontCache; switch (maskFormat) { case kA8_GrMaskFormat: - batch->fMaskType = kGrayscaleCoverageMask_MaskType; + op->fMaskType = kGrayscaleCoverageMask_MaskType; break; case kA565_GrMaskFormat: - batch->fMaskType = kLCDCoverageMask_MaskType; + op->fMaskType = kLCDCoverageMask_MaskType; break; case kARGB_GrMaskFormat: - batch->fMaskType = kColorBitmapMask_MaskType; + op->fMaskType = kColorBitmapMask_MaskType; break; } - batch->fBatch.fNumGlyphs = glyphCount; - batch->fGeoCount = 1; - batch->fFilteredColor = 0; - batch->fFontCache = fontCache; - batch->fUseBGR = false; - return batch; + op->fNumGlyphs = glyphCount; + op->fGeoCount = 1; + op->fFilteredColor = 0; + op->fFontCache = fontCache; + op->fUseBGR = false; + return op; } - static GrAtlasTextBatch* CreateDistanceField( - int glyphCount, GrBatchFontCache* fontCache, - const GrDistanceFieldAdjustTable* distanceAdjustTable, - bool useGammaCorrectDistanceTable, - SkColor filteredColor, bool isLCD, - bool useBGR) { - GrAtlasTextBatch* batch = new GrAtlasTextBatch; - - batch->fFontCache = fontCache; - batch->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistanceField_MaskType; - batch->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); - batch->fUseGammaCorrectDistanceTable = useGammaCorrectDistanceTable; - batch->fFilteredColor = filteredColor; - batch->fUseBGR = useBGR; - batch->fBatch.fNumGlyphs = glyphCount; - batch->fGeoCount = 1; - return batch; + static sk_sp<GrAtlasTextOp> MakeDistanceField( + int glyphCount, GrBatchFontCache* fontCache, + const GrDistanceFieldAdjustTable* distanceAdjustTable, + bool useGammaCorrectDistanceTable, SkColor filteredColor, bool isLCD, bool useBGR) { + sk_sp<GrAtlasTextOp> op(new GrAtlasTextOp); + + op->fFontCache = fontCache; + op->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistanceField_MaskType; + op->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); + op->fUseGammaCorrectDistanceTable = useGammaCorrectDistanceTable; + op->fFilteredColor = filteredColor; + op->fUseBGR = useBGR; + op->fNumGlyphs = glyphCount; + op->fGeoCount = 1; + return op; } - // to avoid even the initial copy of the struct, we have a getter for the first item which - // is used to seed the batch with its initial geometry. After seeding, the client should call - // init() so the Batch can initialize itself + // To avoid even the initial copy of the struct, we have a getter for the first item which + // is used to seed the op with its initial geometry. After seeding, the client should call + // init() so the op can initialize itself Geometry& geometry() { return fGeoData[0]; } void init() { const Geometry& geo = fGeoData[0]; - fBatch.fColor = geo.fColor; + fColor = geo.fColor; SkRect bounds; geo.fBlob->computeSubRunBounds(&bounds, geo.fRun, geo.fSubRun, geo.fViewMatrix, geo.fX, geo.fY); @@ -90,7 +88,7 @@ public: this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); } - const char* name() const override { return "TextBatch"; } + const char* name() const override { return "AtlasTextOp"; } SkString dumpInfo() const override; @@ -99,23 +97,22 @@ protected: GrInitInvariantOutput* coverage, GrBatchToXPOverrides* overrides) const override; - private: void initBatchTracker(const GrXPOverridesForBatch& overrides) override; struct FlushInfo { - sk_sp<const GrBuffer> fVertexBuffer; - sk_sp<const GrBuffer> fIndexBuffer; + sk_sp<const GrBuffer> fVertexBuffer; + sk_sp<const GrBuffer> fIndexBuffer; sk_sp<GrGeometryProcessor> fGeometryProcessor; - int fGlyphsToFlush; - int fVertexOffset; + int fGlyphsToFlush; + int fVertexOffset; }; void onPrepareDraws(Target* target) const override; - GrAtlasTextBatch() : INHERITED(ClassID()) {} // initialized in factory functions. + GrAtlasTextOp() : INHERITED(ClassID()) {} // initialized in factory functions. - ~GrAtlasTextBatch() { + ~GrAtlasTextOp() { for (int i = 0; i < fGeoCount; i++) { fGeoData[i].fBlob->unref(); } @@ -132,7 +129,7 @@ private: case kLCDDistanceField_MaskType: return kA8_GrMaskFormat; } - return kA8_GrMaskFormat; // suppress warning + return kA8_GrMaskFormat; // suppress warning } bool usesDistanceFields() const { @@ -141,16 +138,15 @@ private: } bool isLCD() const { - return kLCDCoverageMask_MaskType == fMaskType || - kLCDDistanceField_MaskType == fMaskType; + return kLCDCoverageMask_MaskType == fMaskType || kLCDDistanceField_MaskType == fMaskType; } inline void flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) const; - GrColor color() const { return fBatch.fColor; } + GrColor color() const { return fColor; } const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } - bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } - int numGlyphs() const { return fBatch.fNumGlyphs; } + bool usesLocalCoords() const { return fUsesLocalCoords; } + int numGlyphs() const { return fNumGlyphs; } bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override; @@ -159,15 +155,12 @@ private: sk_sp<GrGeometryProcessor> setupDfProcessor(const SkMatrix& viewMatrix, SkColor filteredColor, GrColor color, GrTexture* texture) const; - struct BatchTracker { - GrColor fColor; - bool fUsesLocalCoords; - bool fColorIgnored; - bool fCoverageIgnored; - int fNumGlyphs; - }; + GrColor fColor; + bool fUsesLocalCoords; + bool fColorIgnored; + bool fCoverageIgnored; + int fNumGlyphs; - BatchTracker fBatch; // The minimum number of Geometry we will try to allocate. enum { kMinGeometryAllocated = 4 }; SkAutoSTMalloc<kMinGeometryAllocated, Geometry> fGeoData; @@ -180,7 +173,7 @@ private: kGrayscaleDistanceField_MaskType, kLCDDistanceField_MaskType, } fMaskType; - bool fUseBGR; // fold this into the enum? + bool fUseBGR; // fold this into the enum? GrBatchFontCache* fFontCache; @@ -189,7 +182,7 @@ private: SkColor fFilteredColor; bool fUseGammaCorrectDistanceTable; - friend class GrBlobRegenHelper; // Needs to trigger flushes + friend class GrBlobRegenHelper; // Needs to trigger flushes typedef GrMeshDrawOp INHERITED; }; @@ -200,20 +193,18 @@ private: */ class GrBlobRegenHelper { public: - GrBlobRegenHelper(const GrAtlasTextBatch* batch, GrMeshDrawOp::Target* target, - GrAtlasTextBatch::FlushInfo* flushInfo) - : fBatch(batch), fTarget(target), fFlushInfo(flushInfo) {} + GrBlobRegenHelper(const GrAtlasTextOp* op, GrMeshDrawOp::Target* target, + GrAtlasTextOp::FlushInfo* flushInfo) + : fOp(op), fTarget(target), fFlushInfo(flushInfo) {} void flush(); - void incGlyphCount(int glyphCount = 1) { - fFlushInfo->fGlyphsToFlush += glyphCount; - } + void incGlyphCount(int glyphCount = 1) { fFlushInfo->fGlyphsToFlush += glyphCount; } private: - const GrAtlasTextBatch* fBatch; + const GrAtlasTextOp* fOp; GrMeshDrawOp::Target* fTarget; - GrAtlasTextBatch::FlushInfo* fFlushInfo; + GrAtlasTextOp::FlushInfo* fFlushInfo; }; #endif |