From 434a58ab5fefcc1b86588c7fce898b1e5bd248ba Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 14 Jul 2017 15:14:59 -0400 Subject: Make GrAtlasTextOp a non-legacy GrMeshDrawOp Change-Id: Ib9eaf149100b0ccecf1c18a755263f2579b8e6f6 Reviewed-on: https://skia-review.googlesource.com/23482 Reviewed-by: Jim Van Verth Commit-Queue: Brian Salomon --- src/gpu/text/GrAtlasTextBlob.cpp | 38 +++++++++++++++++++------------------ src/gpu/text/GrAtlasTextBlob.h | 20 ++++++++++--------- src/gpu/text/GrAtlasTextContext.cpp | 14 +++++++++----- src/gpu/text/GrAtlasTextContext.h | 2 +- 4 files changed, 41 insertions(+), 33 deletions(-) (limited to 'src/gpu/text') diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp index 10b1c81639..835105b4d2 100644 --- a/src/gpu/text/GrAtlasTextBlob.cpp +++ b/src/gpu/text/GrAtlasTextBlob.cpp @@ -257,22 +257,26 @@ bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint, return false; } -inline std::unique_ptr GrAtlasTextBlob::makeOp( +inline std::unique_ptr GrAtlasTextBlob::makeOp( const Run::SubRunInfo& info, int glyphCount, int run, int subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, - bool useGammaCorrectDistanceTable, GrAtlasGlyphCache* cache) { + GrAtlasGlyphCache* cache, GrRenderTargetContext* renderTargetContext) { GrMaskFormat format = info.maskFormat(); + GrPaint grPaint; + if (!paint.toGrPaint(info.maskFormat(), renderTargetContext, viewMatrix, &grPaint)) { + return nullptr; + } std::unique_ptr op; if (info.drawAsDistanceFields()) { - SkColor luminanceColor = paint.luminanceColor(); bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); - op = GrAtlasTextOp::MakeDistanceField(glyphCount, cache, distanceAdjustTable, - useGammaCorrectDistanceTable, luminanceColor, - info.hasUseLCDText(), useBGR, info.isAntiAliased()); + op = GrAtlasTextOp::MakeDistanceField( + std::move(grPaint), glyphCount, cache, distanceAdjustTable, + renderTargetContext->isGammaCorrect(), paint.luminanceColor(), info.hasUseLCDText(), + useBGR, info.isAntiAliased()); } else { - op = GrAtlasTextOp::MakeBitmap(format, glyphCount, cache); + op = GrAtlasTextOp::MakeBitmap(std::move(grPaint), format, glyphCount, cache); } GrAtlasTextOp::Geometry& geometry = op->geometry(); geometry.fViewMatrix = viewMatrix; @@ -284,7 +288,6 @@ inline std::unique_ptr GrAtlasTextBlob::makeOp( geometry.fX = x; geometry.fY = y; op->init(); - return std::move(op); } @@ -304,13 +307,11 @@ inline void GrAtlasTextBlob::flushRun(GrRenderTargetContext* rtc, const GrClip& if (0 == glyphCount) { continue; } - - std::unique_ptr op( - this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, paint, props, - distanceAdjustTable, rtc->isGammaCorrect(), cache)); - GrPipelineBuilder pipelineBuilder(std::move(grPaint), GrAAType::kNone); - - rtc->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); + auto op = this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, std::move(paint), + props, distanceAdjustTable, cache, rtc); + if (op) { + rtc->addDrawOp(clip, std::move(op)); + } } } @@ -425,13 +426,14 @@ void GrAtlasTextBlob::flushThrowaway(GrContext* context, GrRenderTargetContext* this->flushBigGlyphs(context, rtc, clip, paint, viewMatrix, x, y, clipBounds); } -std::unique_ptr GrAtlasTextBlob::test_makeOp( +std::unique_ptr GrAtlasTextBlob::test_makeOp( int glyphCount, int run, int subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, const SkSurfaceProps& props, - const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache) { + const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache, + GrRenderTargetContext* rtc) { const GrAtlasTextBlob::Run::SubRunInfo& info = fRuns[run].fSubRunInfo[subRun]; return this->makeOp(info, glyphCount, run, subRun, viewMatrix, x, y, paint, props, - distanceAdjustTable, false, cache); + distanceAdjustTable, cache, rtc); } void GrAtlasTextBlob::AssertEqual(const GrAtlasTextBlob& l, const GrAtlasTextBlob& r) { diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h index 12fe68b948..1bce3414da 100644 --- a/src/gpu/text/GrAtlasTextBlob.h +++ b/src/gpu/text/GrAtlasTextBlob.h @@ -271,10 +271,11 @@ public: //////////////////////////////////////////////////////////////////////////////////////////////// // Internal test methods - std::unique_ptr test_makeOp( - int glyphCount, int run, int subRun, const SkMatrix& viewMatrix, SkScalar x, SkScalar y, - const GrTextUtils::Paint& paint, const SkSurfaceProps& props, - const GrDistanceFieldAdjustTable* distanceAdjustTable, GrAtlasGlyphCache* cache); + std::unique_ptr test_makeOp(int glyphCount, int run, int subRun, + const SkMatrix& viewMatrix, SkScalar x, SkScalar y, + const GrTextUtils::Paint&, const SkSurfaceProps&, + const GrDistanceFieldAdjustTable*, GrAtlasGlyphCache*, + GrRenderTargetContext*); private: GrAtlasTextBlob() @@ -497,11 +498,12 @@ private: Run* run, Run::SubRunInfo* info, SkAutoGlyphCache*, int glyphCount, size_t vertexStride, GrColor color, SkScalar transX, SkScalar transY) const; - inline std::unique_ptr makeOp( - const Run::SubRunInfo& info, int glyphCount, int run, int subRun, - const SkMatrix& viewMatrix, SkScalar x, SkScalar y, const GrTextUtils::Paint& paint, - const SkSurfaceProps& props, const GrDistanceFieldAdjustTable* distanceAdjustTable, - bool useGammaCorrectDistanceTable, GrAtlasGlyphCache* cache); + inline std::unique_ptr makeOp(const Run::SubRunInfo& info, int glyphCount, int run, + int subRun, const SkMatrix& viewMatrix, SkScalar x, + SkScalar y, const GrTextUtils::Paint& paint, + const SkSurfaceProps& props, + const GrDistanceFieldAdjustTable* distanceAdjustTable, + GrAtlasGlyphCache* cache, GrRenderTargetContext*); struct BigGlyph { BigGlyph(const SkPath& path, SkScalar vx, SkScalar vy, SkScalar scale, bool treatAsBMP) diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index 71c410eab7..22228ed2b6 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -339,7 +339,7 @@ void GrAtlasTextContext::drawPosText(GrContext* context, GrRenderTargetContext* #if GR_TEST_UTILS -GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(TextBlobOp) { +GR_DRAW_OP_TEST_DEFINE(GrAtlasTextOp) { static uint32_t gContextID = SK_InvalidGenID; static GrAtlasTextContext* gTextContext = nullptr; static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); @@ -356,11 +356,15 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(TextBlobOp) { SkBackingFit::kApprox, 1024, 1024, kRGBA_8888_GrPixelConfig, nullptr)); SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); + + // Because we the GrTextUtils::Paint requires an SkPaint for font info, we ignore the GrPaint + // param. SkPaint skPaint; skPaint.setColor(random->nextU()); skPaint.setLCDRenderText(random->nextBool()); skPaint.setAntiAlias(skPaint.isLCDRenderText() ? true : random->nextBool()); skPaint.setSubpixelText(random->nextBool()); + GrTextUtils::Paint utilsPaint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB()); const char* text = "The quick brown fox jumps over the lazy dog."; int textLen = (int)strlen(text); @@ -374,17 +378,17 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(TextBlobOp) { SkScalar x = SkIntToScalar(xInt); SkScalar y = SkIntToScalar(yInt); - GrTextUtils::Paint paint(&skPaint, rtc->getColorSpace(), rtc->getColorXformFromSRGB()); // right now we don't handle textblobs, nor do we handle drawPosText. Since we only intend to // test the text op with this unit test, that is okay. sk_sp blob(GrAtlasTextContext::MakeDrawTextBlob( context->getTextBlobCache(), context->getAtlasGlyphCache(), - *context->caps()->shaderCaps(), paint, + *context->caps()->shaderCaps(), utilsPaint, GrAtlasTextContext::kTextBlobOpScalerContextFlags, viewMatrix, gSurfaceProps, text, static_cast(textLen), x, y)); - return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, paint, gSurfaceProps, - gTextContext->dfAdjustTable(), context->getAtlasGlyphCache()); + return blob->test_makeOp(textLen, 0, 0, viewMatrix, x, y, utilsPaint, gSurfaceProps, + gTextContext->dfAdjustTable(), context->getAtlasGlyphCache(), + rtc.get()); } #endif diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h index e375195cde..c47ec65666 100644 --- a/src/gpu/text/GrAtlasTextContext.h +++ b/src/gpu/text/GrAtlasTextContext.h @@ -89,7 +89,7 @@ private: #if GR_TEST_UTILS static const uint32_t kTextBlobOpScalerContextFlags = SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags; - GR_LEGACY_MESH_DRAW_OP_TEST_FRIEND(TextBlobOp); + GR_DRAW_OP_TEST_FRIEND(GrAtlasTextOp); #endif }; -- cgit v1.2.3