diff options
author | joshualitt <joshualitt@chromium.org> | 2015-02-11 06:56:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-11 06:56:30 -0800 |
commit | 02b05015b55d1900a9e34039942101da189053ce (patch) | |
tree | e7162807a7a960539d3fe40796594654a528570c | |
parent | 9e33d1dbccee9b13ac001dfc3094a503f9e84e9d (diff) |
Small change to use a GrGeometryProcessor for all BitmapText draw calls
BUG=skia:
Review URL: https://codereview.chromium.org/914723002
-rw-r--r-- | bench/TextBench.cpp | 38 | ||||
-rwxr-xr-x | src/gpu/GrBitmapTextContext.cpp | 40 | ||||
-rw-r--r-- | src/gpu/GrBitmapTextContext.h | 1 | ||||
-rw-r--r-- | src/gpu/effects/GrBitmapTextGeoProc.cpp | 74 | ||||
-rw-r--r-- | src/gpu/effects/GrBitmapTextGeoProc.h | 12 |
5 files changed, 112 insertions, 53 deletions
diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp index 6c3bab13d9..39484a2e04 100644 --- a/bench/TextBench.cpp +++ b/bench/TextBench.cpp @@ -5,17 +5,21 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ + #include "Benchmark.h" +#include "Resources.h" #include "SkCanvas.h" #include "SkPaint.h" #include "SkRandom.h" +#include "SkStream.h" #include "SkString.h" #include "SkTemplates.h" +#include "SkTypeface.h" enum FontQuality { kBW, kAA, - kLCD + kLCD, }; static const char* fontQualityName(const SkPaint& paint) { @@ -43,13 +47,16 @@ class TextBench : public Benchmark { SkString fName; FontQuality fFQ; bool fDoPos; + bool fDoColorEmoji; + SkAutoTUnref<SkTypeface> fColorEmojiTypeface; SkPoint* fPos; public: TextBench(const char text[], int ps, - SkColor color, FontQuality fq, bool doPos = false) { + SkColor color, FontQuality fq, bool doColorEmoji = false, bool doPos = false) { fPos = NULL; fFQ = fq; fDoPos = doPos; + fDoColorEmoji = doColorEmoji; fText.set(text); fPaint.setAntiAlias(kBW != fq); @@ -57,6 +64,17 @@ public: fPaint.setTextSize(SkIntToScalar(ps)); fPaint.setColor(color); + if (doColorEmoji) { + SkASSERT(kBW == fFQ); + SkString filename = GetResourcePath("/Funkster.ttf"); + SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str())); + if (stream->isValid()) { + fColorEmojiTypeface.reset(SkTypeface::CreateFromStream(stream.detach())); + } else { + SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n"); + } + } + if (doPos) { size_t len = strlen(text); SkScalar* adv = new SkScalar[len]; @@ -87,6 +105,11 @@ protected: } else { fName.append("_BK"); } + + if (fDoColorEmoji && fColorEmojiTypeface) { + fName.append("_ColorEmoji"); + } + return fName.c_str(); } @@ -101,6 +124,10 @@ protected: paint.setAntiAlias(kBW != fFQ); paint.setLCDRenderText(kLCD == fFQ); + if (fDoColorEmoji && fColorEmojiTypeface) { + paint.setTypeface(fColorEmojiTypeface); + } + const SkScalar x0 = SkIntToScalar(-10); const SkScalar y0 = SkIntToScalar(-10); @@ -141,4 +168,9 @@ DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kLCD); ) DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kLCD); ) DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kLCD); ) -DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, true); ) +DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true); ) +DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kBW, true); ) +DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW, true); ) + +DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true, true); ) +DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, false, true); ) diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp index 4af5c0ad04..5e5aa6a3cd 100755 --- a/src/gpu/GrBitmapTextContext.cpp +++ b/src/gpu/GrBitmapTextContext.cpp @@ -561,33 +561,19 @@ void GrBitmapTextContext::flush() { } GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode); - if (kARGB_GrMaskFormat == fCurrMaskFormat) { - uint32_t textureUniqueID = fCurrTexture->getUniqueID(); - if (textureUniqueID != fEffectTextureUniqueID || - fCachedGeometryProcessor->color() != color) { - uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType; - fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(flags, color)); - fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCurrTexture, - SkMatrix::I(), - params)); - fEffectTextureUniqueID = textureUniqueID; - } - pipelineBuilder.addColorProcessor(fCachedTextureProcessor.get()); - } else { - uint32_t textureUniqueID = fCurrTexture->getUniqueID(); - if (textureUniqueID != fEffectTextureUniqueID || - fCachedGeometryProcessor->color() != color || - !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatrix)) { - bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat; - bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor()); - fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color, - fCurrTexture, - params, - hasColor, - opaqueVertexColors, - fLocalMatrix)); - fEffectTextureUniqueID = textureUniqueID; - } + uint32_t textureUniqueID = fCurrTexture->getUniqueID(); + if (textureUniqueID != fEffectTextureUniqueID || + fCachedGeometryProcessor->color() != color || + !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatrix)) { + // This will be ignored in the non A8 case + bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor()); + fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color, + fCurrTexture, + params, + fCurrMaskFormat, + opaqueVertexColors, + fLocalMatrix)); + fEffectTextureUniqueID = textureUniqueID; } int nGlyphs = fCurrVertex / kVerticesPerGlyph; diff --git a/src/gpu/GrBitmapTextContext.h b/src/gpu/GrBitmapTextContext.h index bffacd52d0..5137f82b70 100644 --- a/src/gpu/GrBitmapTextContext.h +++ b/src/gpu/GrBitmapTextContext.h @@ -32,7 +32,6 @@ private: GrTexture* fCurrTexture; GrMaskFormat fCurrMaskFormat; SkAutoTUnref<const GrGeometryProcessor> fCachedGeometryProcessor; - SkAutoTUnref<const GrFragmentProcessor> fCachedTextureProcessor; // Used to check whether fCachedEffect is still valid. uint32_t fEffectTextureUniqueID; SkMatrix fLocalMatrix; diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index 313326561c..a699b0410e 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -47,17 +47,26 @@ public: this->addUniformViewMatrix(pb); // Setup position - SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName, - cte.viewMatrix(), this->uViewM()); + SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName, cte.viewMatrix(), this->uViewM()); // emit transforms this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->fName, cte.localMatrix(), args.fTransformsIn, args.fTransformsOut); GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); - fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); - fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLType); - fsBuilder->codeAppend(";"); + if (cte.maskFormat() == kARGB_GrMaskFormat) { + fsBuilder->codeAppendf("%s = ", args.fOutputColor); + fsBuilder->appendTextureLookupAndModulate(args.fOutputColor, + args.fSamplers[0], + v.fsIn(), + kVec2f_GrSLType); + fsBuilder->codeAppend(";"); + fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); + } else { + fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); + fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLType); + fsBuilder->codeAppend(";"); + } } virtual void setData(const GrGLProgramDataManager& pdman, @@ -86,7 +95,8 @@ public: uint32_t key = 0; key |= SkToBool(gp.inColor()) ? 0x1 : 0x0; key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0x2 : 0x0; - key |= ComputePosKey(gp.viewMatrix()) << 2; + key |= gp.maskFormat() == kARGB_GrMaskFormat ? 0x4 : 0x0; + key |= ComputePosKey(gp.viewMatrix()) << 3; b->add32(local.fInputColorType << 16 | key); } @@ -100,19 +110,22 @@ private: /////////////////////////////////////////////////////////////////////////////// GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture, - const GrTextureParams& params, bool useColorAttrib, + const GrTextureParams& params, GrMaskFormat format, bool opaqueVertexColors, const SkMatrix& localMatrix) : INHERITED(color, SkMatrix::I(), localMatrix, opaqueVertexColors) , fTextureAccess(texture, params) - , fInColor(NULL) { + , fInColor(NULL) + , fMaskFormat(format) { this->initClassID<GrBitmapTextGeoProc>(); fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); - if (useColorAttrib) { + + bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat; + if (hasVertexColor) { fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType)); this->setHasVertexColor(); } fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", - kVec2f_GrVertexAttribType)); + kVec2f_GrVertexAttribType)); this->addTextureAccess(&fTextureAccess); } @@ -121,15 +134,25 @@ bool GrBitmapTextGeoProc::onIsEqual(const GrGeometryProcessor& other) const { return SkToBool(this->inColor()) == SkToBool(gp.inColor()); } +void GrBitmapTextGeoProc::onGetInvariantOutputColor(GrInitInvariantOutput* out) const { + if (kARGB_GrMaskFormat == fMaskFormat) { + out->setUnknownFourComponents(); + } +} + void GrBitmapTextGeoProc::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const { - if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { - out->setUnknownSingleComponent(); - } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { - out->setUnknownOpaqueFourComponents(); - out->setUsingLCDCoverage(); + if (kARGB_GrMaskFormat != fMaskFormat) { + if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { + out->setUnknownSingleComponent(); + } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { + out->setUnknownOpaqueFourComponents(); + out->setUsingLCDCoverage(); + } else { + out->setUnknownFourComponents(); + out->setUsingLCDCoverage(); + } } else { - out->setUnknownFourComponents(); - out->setUsingLCDCoverage(); + out->setKnownSingleComponent(0xff); } } @@ -185,7 +208,22 @@ GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(SkRandom* random, GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_FilterMode); + GrMaskFormat format; + switch (random->nextULessThan(3)) { + default: + SkFAIL("Incomplete enum\n"); + case 0: + format = kA8_GrMaskFormat; + break; + case 1: + format = kA565_GrMaskFormat; + break; + case 2: + format = kARGB_GrMaskFormat; + break; + } + return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx], params, - random->nextBool(), random->nextBool(), + format, random->nextBool(), GrProcessorUnitTest::TestMatrix(random)); } diff --git a/src/gpu/effects/GrBitmapTextGeoProc.h b/src/gpu/effects/GrBitmapTextGeoProc.h index d5684d746e..b5a4145367 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.h +++ b/src/gpu/effects/GrBitmapTextGeoProc.h @@ -22,9 +22,9 @@ class GrInvariantOutput; class GrBitmapTextGeoProc : public GrGeometryProcessor { public: static GrGeometryProcessor* Create(GrColor color, GrTexture* tex, const GrTextureParams& p, - bool useColorAttrib, bool opaqueVertexColors, + GrMaskFormat format, bool opaqueVertexColors, const SkMatrix& localMatrix) { - return SkNEW_ARGS(GrBitmapTextGeoProc, (color, tex, p, useColorAttrib, opaqueVertexColors, + return SkNEW_ARGS(GrBitmapTextGeoProc, (color, tex, p, format, opaqueVertexColors, localMatrix)); } @@ -35,6 +35,7 @@ public: const Attribute* inPosition() const { return fInPosition; } const Attribute* inColor() const { return fInColor; } const Attribute* inTextureCoords() const { return fInTextureCoords; } + GrMaskFormat maskFormat() const { return fMaskFormat; } virtual void getGLProcessorKey(const GrBatchTracker& bt, const GrGLCaps& caps, @@ -50,16 +51,19 @@ public: private: GrBitmapTextGeoProc(GrColor, GrTexture* texture, const GrTextureParams& params, - bool useColorAttrib, bool opaqueVertexColors, const SkMatrix& localMatrix); + GrMaskFormat format, bool opaqueVertexColors, const SkMatrix& localMatrix); bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; + void onGetInvariantOutputColor(GrInitInvariantOutput*) const SK_OVERRIDE; + void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_OVERRIDE; - GrTextureAccess fTextureAccess; + GrTextureAccess fTextureAccess; const Attribute* fInPosition; const Attribute* fInColor; const Attribute* fInTextureCoords; + GrMaskFormat fMaskFormat; GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |