diff options
28 files changed, 98 insertions, 101 deletions
diff --git a/bench/TextBlobBench.cpp b/bench/TextBlobBench.cpp index 7c9b303430..b25c975579 100644 --- a/bench/TextBlobBench.cpp +++ b/bench/TextBlobBench.cpp @@ -44,7 +44,7 @@ protected: nullptr); memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); - fBlob.reset(builder.build()); + fBlob = builder.make(); } const char* onGetName() override { @@ -62,9 +62,9 @@ protected: private: - SkAutoTUnref<const SkTextBlob> fBlob; - SkTDArray<uint16_t> fGlyphs; - sk_sp<SkTypeface> fTypeface; + sk_sp<SkTextBlob> fBlob; + SkTDArray<uint16_t> fGlyphs; + sk_sp<SkTypeface> fTypeface; typedef Benchmark INHERITED; }; diff --git a/gm/largeglyphblur.cpp b/gm/largeglyphblur.cpp index 235c7cc5ad..19d390be54 100644 --- a/gm/largeglyphblur.cpp +++ b/gm/largeglyphblur.cpp @@ -32,9 +32,9 @@ DEF_SIMPLE_GM(largeglyphblur, canvas, 1920, 600) { sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); - canvas->drawTextBlob(blob.get(), 10, 200, blurPaint); - canvas->drawTextBlob(blob.get(), 10, 200, paint); + sk_sp<SkTextBlob> blob(builder.make()); + canvas->drawTextBlob(blob, 10, 200, blurPaint); + canvas->drawTextBlob(blob, 10, 200, paint); size_t len = strlen(text); canvas->drawText(text, len, 10, 500, blurPaint); diff --git a/gm/lcdoverlap.cpp b/gm/lcdoverlap.cpp index de159e19ac..623d74622d 100644 --- a/gm/lcdoverlap.cpp +++ b/gm/lcdoverlap.cpp @@ -44,7 +44,7 @@ protected: paint.setSubpixelText(true); paint.setLCDRenderText(true); sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0); - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkISize onISize() override { return SkISize::Make(kWidth, kHeight); } @@ -90,7 +90,7 @@ protected: private: SkScalar fTextHeight; - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; typedef skiagm::GM INHERITED; }; diff --git a/gm/mixedtextblobs.cpp b/gm/mixedtextblobs.cpp index 66e2379ee6..00081d0778 100644 --- a/gm/mixedtextblobs.cpp +++ b/gm/mixedtextblobs.cpp @@ -94,7 +94,7 @@ protected: text = "aA"; paint.setTypeface(fReallyBigATypeface); sk_tool_utils::add_to_text_blob(&builder, text, paint, corruptedAx, corruptedAy); - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkString onShortName() override { @@ -138,7 +138,7 @@ protected: size_t count = sizeof(clipRects) / sizeof(SkRect); for (size_t x = 0; x < count; ++x) { - draw_blob(canvas, fBlob, paint, clipRects[x]); + draw_blob(canvas, fBlob.get(), paint, clipRects[x]); if (x == (count >> 1) - 1) { canvas->translate(SkScalarFloorToScalar(bounds.width() + SkIntToScalar(25)), -(x * SkScalarFloorToScalar(bounds.height() + @@ -153,7 +153,7 @@ private: sk_sp<SkTypeface> fEmojiTypeface; sk_sp<SkTypeface> fReallyBigATypeface; const char* fEmojiText; - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; static constexpr int kWidth = 1250; static constexpr int kHeight = 700; diff --git a/gm/textblob.cpp b/gm/textblob.cpp index 2ac7d27f07..aa2bfb04a8 100644 --- a/gm/textblob.cpp +++ b/gm/textblob.cpp @@ -92,7 +92,7 @@ protected: void onDraw(SkCanvas* canvas) override { for (unsigned b = 0; b < SK_ARRAY_COUNT(blobConfigs); ++b) { - SkAutoTUnref<const SkTextBlob> blob(this->makeBlob(b)); + sk_sp<SkTextBlob> blob(this->makeBlob(b)); SkPaint p; SkPoint offset = SkPoint::Make(SkIntToScalar(10 + 300 * (b % 2)), @@ -110,7 +110,7 @@ protected: } private: - const SkTextBlob* makeBlob(unsigned blobIndex) { + sk_sp<SkTextBlob> makeBlob(unsigned blobIndex) { SkTextBlobBuilder builder; SkPaint font; @@ -177,7 +177,7 @@ private: } } - return builder.build(); + return builder.make(); } SkTDArray<uint16_t> fGlyphs; diff --git a/gm/textblobblockreordering.cpp b/gm/textblobblockreordering.cpp index ea90308b1f..3974aca5ab 100644 --- a/gm/textblobblockreordering.cpp +++ b/gm/textblobblockreordering.cpp @@ -35,7 +35,7 @@ protected: sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 30); // build - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkString onShortName() override { @@ -77,7 +77,7 @@ protected: } private: - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; static constexpr int kWidth = 275; static constexpr int kHeight = 200; diff --git a/gm/textblobcolortrans.cpp b/gm/textblobcolortrans.cpp index 1e7a66667a..286dc77ef5 100644 --- a/gm/textblobcolortrans.cpp +++ b/gm/textblobcolortrans.cpp @@ -48,7 +48,7 @@ protected: sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 8); // build - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkString onShortName() override { @@ -87,7 +87,7 @@ protected: } private: - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; static constexpr int kWidth = 675; static constexpr int kHeight = 1600; diff --git a/gm/textblobgeometrychange.cpp b/gm/textblobgeometrychange.cpp index 9e33e95e74..f84a55fbf4 100644 --- a/gm/textblobgeometrychange.cpp +++ b/gm/textblobgeometrychange.cpp @@ -40,7 +40,7 @@ protected: sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); @@ -55,12 +55,12 @@ protected: SkPaint rectPaint; rectPaint.setColor(0xffffffff); canvas->drawRect(rect, rectPaint); - canvas->drawTextBlob(blob.get(), 10, 50, paint); + canvas->drawTextBlob(blob, 10, 50, paint); // This should not look garbled since we should disable LCD text in this case // (i.e., unknown pixel geometry) c->clear(0x00ffffff); - c->drawTextBlob(blob.get(), 10, 150, paint); + c->drawTextBlob(blob, 10, 150, paint); surface->draw(canvas, 0, 0, nullptr); } diff --git a/gm/textbloblooper.cpp b/gm/textbloblooper.cpp index 752fd54a41..3adf34909c 100644 --- a/gm/textbloblooper.cpp +++ b/gm/textbloblooper.cpp @@ -148,7 +148,7 @@ protected: paint.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&paint); add_to_text_blob(&builder, text, paint, 0, 0); - fBlob.reset(builder.build()); + fBlob = builder.make(); // create a looper which sandwhiches an effect in two normal draws LooperSettings looperSandwhich[] = { @@ -245,7 +245,7 @@ protected: } private: - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; SkTArray<sk_sp<SkDrawLooper>, true> fLoopers; typedef GM INHERITED; diff --git a/gm/textblobmixedsizes.cpp b/gm/textblobmixedsizes.cpp index 6ce0eafe62..8c51cae45e 100644 --- a/gm/textblobmixedsizes.cpp +++ b/gm/textblobmixedsizes.cpp @@ -80,7 +80,7 @@ protected: sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset); // build - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkString onShortName() override { @@ -177,7 +177,7 @@ protected: } private: - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; static constexpr int kWidth = 2100; static constexpr int kHeight = 1900; diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp index 583f4fc5b3..a2e46972b4 100644 --- a/gm/textblobrandomfont.cpp +++ b/gm/textblobrandomfont.cpp @@ -77,7 +77,7 @@ protected: } // build - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkString onShortName() override { @@ -136,7 +136,7 @@ protected: } private: - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; static constexpr int kWidth = 2000; static constexpr int kHeight = 1600; diff --git a/gm/textblobshader.cpp b/gm/textblobshader.cpp index bb0e03c4f3..acb6436d1a 100644 --- a/gm/textblobshader.cpp +++ b/gm/textblobshader.cpp @@ -56,7 +56,7 @@ protected: run->pos[i * 2 + 1] = 150 + 5 * sinf((float)i * 8 / glyphCount); } - fBlob.reset(builder.build()); + fBlob = builder.make(); SkColor colors[2]; colors[0] = SK_ColorRED; @@ -102,9 +102,9 @@ protected: } private: - SkTDArray<uint16_t> fGlyphs; - SkAutoTUnref<const SkTextBlob> fBlob; - sk_sp<SkShader> fShader; + SkTDArray<uint16_t> fGlyphs; + sk_sp<SkTextBlob> fBlob; + sk_sp<SkShader> fShader; typedef skiagm::GM INHERITED; }; diff --git a/gm/textblobtransforms.cpp b/gm/textblobtransforms.cpp index 537ddb1616..54c6b4417c 100644 --- a/gm/textblobtransforms.cpp +++ b/gm/textblobtransforms.cpp @@ -49,7 +49,7 @@ protected: sk_tool_utils::add_to_text_blob(&builder, text, paint, xOffset, -yOffset - 10); // build - fBlob.reset(builder.build()); + fBlob = builder.make(); } SkString onShortName() override { @@ -158,7 +158,7 @@ protected: } private: - SkAutoTUnref<const SkTextBlob> fBlob; + sk_sp<SkTextBlob> fBlob; static constexpr int kWidth = 1000; static constexpr int kHeight = 1200; diff --git a/gm/textblobuseaftergpufree.cpp b/gm/textblobuseaftergpufree.cpp index c104e9b121..44fd85488c 100644 --- a/gm/textblobuseaftergpufree.cpp +++ b/gm/textblobuseaftergpufree.cpp @@ -47,18 +47,18 @@ protected: sk_tool_utils::add_to_text_blob(&builder, text, paint, 10, 10); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); // draw textblob SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f); SkPaint rectPaint; rectPaint.setColor(0xffffffff); canvas->drawRect(rect, rectPaint); - canvas->drawTextBlob(blob.get(), 10, 50, paint); + canvas->drawTextBlob(blob, 10, 50, paint); // This text should look fine canvas->getGrContext()->freeGpuResources(); - canvas->drawTextBlob(blob.get(), 10, 150, paint); + canvas->drawTextBlob(blob, 10, 150, paint); } private: diff --git a/gm/texteffects.cpp b/gm/texteffects.cpp index c89b4e003b..6a5a9c1fb0 100644 --- a/gm/texteffects.cpp +++ b/gm/texteffects.cpp @@ -351,7 +351,7 @@ DEF_SIMPLE_GM(fancyposunderline, canvas, 900, 1350) { namespace { -sk_sp<const SkTextBlob> MakeFancyBlob(const SkPaint& paint, const char* text) { +sk_sp<SkTextBlob> MakeFancyBlob(const SkPaint& paint, const char* text) { SkPaint blobPaint(paint); const size_t textLen = strlen(text); @@ -411,7 +411,7 @@ sk_sp<const SkTextBlob> MakeFancyBlob(const SkPaint& paint, const char* text) { } } - return sk_sp<const SkTextBlob>(blobBuilder.build()); + return blobBuilder.make(); } } // anonymous ns @@ -431,8 +431,8 @@ DEF_SIMPLE_GM(fancyblobunderline, canvas, 1480, 1380) { paint.setStrokeWidth(uWidth); paint.setStyle(SkPaint::kFill_Style); - sk_sp<const SkTextBlob> blob = MakeFancyBlob(paint, test); - canvas->drawTextBlob(blob.get(), blobOffset.x(), blobOffset.y(), paint); + sk_sp<SkTextBlob> blob = MakeFancyBlob(paint, test); + canvas->drawTextBlob(blob, blobOffset.x(), blobOffset.y(), paint); const SkScalar uPos = uWidth; const SkScalar bounds[2] = { uPos - uWidth / 2, uPos + uWidth / 2 }; diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h index 01263af02d..35d5dc4173 100644 --- a/include/core/SkTextBlob.h +++ b/include/core/SkTextBlob.h @@ -106,9 +106,11 @@ public: */ sk_sp<SkTextBlob> make(); +#ifdef SK_SUPPORT_LEGACY_TEXTBLOB_BUILDER const SkTextBlob* build() { return this->make().release(); } +#endif /** * Glyph and position buffers associated with a run. diff --git a/include/utils/SkTextBox.h b/include/utils/SkTextBox.h index d4372d1b6a..90903b558d 100644 --- a/include/utils/SkTextBox.h +++ b/include/utils/SkTextBox.h @@ -60,7 +60,7 @@ public: int countLines() const; SkScalar getTextHeight() const; - SkTextBlob* snapshotTextBlob(SkScalar* computedBottom) const; + sk_sp<SkTextBlob> snapshotTextBlob(SkScalar* computedBottom) const; class Visitor { public: diff --git a/public.bzl b/public.bzl index 7a0719eb87..fb8edb004c 100644 --- a/public.bzl +++ b/public.bzl @@ -612,6 +612,7 @@ DEFINES_ALL = [ "SK_SUPPORT_LEGACY_XFERMODE_PTR", "SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF", "SK_SUPPORT_LEGACY_STREAM_DATA", + "SK_SUPPORT_LEGACY_TEXTBLOB_BUILDER", ] ################################################################################ diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index 35adc24a34..ca75a2e038 100644 --- a/src/core/SkTextBlob.cpp +++ b/src/core/SkTextBlob.cpp @@ -486,7 +486,7 @@ SkTextBlobBuilder::~SkTextBlobBuilder() { if (nullptr != fStorage.get()) { // We are abandoning runs and must destruct the associated font data. // The easiest way to accomplish that is to use the blob destructor. - build()->unref(); + this->make(); } } diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp index 02b7ffd15a..32d80218d3 100644 --- a/src/gpu/text/GrStencilAndCoverTextContext.cpp +++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp @@ -344,7 +344,7 @@ public: void appendGlyph(uint16_t glyphId, const SkPoint& pos); - const SkTextBlob* buildIfNeeded(int* count); + sk_sp<SkTextBlob> makeIfNeeded(int* count); private: enum { kWriteBufferSize = 1024 }; @@ -521,7 +521,7 @@ void GrStencilAndCoverTextContext::TextRun::setText(const char text[], size_t by y += SkFloatToScalar(glyph.fAdvanceY) * fTextRatio; } - fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); + fFallbackTextBlob = fallback.makeIfNeeded(&fFallbackGlyphCount); } void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t byteLength, @@ -557,7 +557,7 @@ void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t pos += scalarsPerPosition; } - fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); + fFallbackTextBlob = fallback.makeIfNeeded(&fFallbackGlyphCount); } GrPathRange* GrStencilAndCoverTextContext::TextRun::createGlyphs(GrContext* ctx) const { @@ -654,7 +654,8 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, } fallbackTextContext->drawTextBlob(ctx, drawContext, clip, fallbackSkPaint, viewMatrix, - props, fFallbackTextBlob, x, y, nullptr, clipBounds); + props, fFallbackTextBlob.get(), x, y, nullptr, + clipBounds); } } @@ -728,11 +729,11 @@ void GrStencilAndCoverTextContext::FallbackBlobBuilder::flush() { fBuffIdx = 0; } -const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeeded(int *count) { +sk_sp<SkTextBlob> GrStencilAndCoverTextContext::FallbackBlobBuilder::makeIfNeeded(int *count) { *count = fCount; if (fCount) { this->flush(); - return fBuilder->build(); + return fBuilder->make(); } return nullptr; } diff --git a/src/gpu/text/GrStencilAndCoverTextContext.h b/src/gpu/text/GrStencilAndCoverTextContext.h index 3c92b39eb7..0f6735e133 100644 --- a/src/gpu/text/GrStencilAndCoverTextContext.h +++ b/src/gpu/text/GrStencilAndCoverTextContext.h @@ -97,18 +97,18 @@ private: GrPathRange* createGlyphs(GrContext*) const; void appendGlyph(const SkGlyph&, const SkPoint&, FallbackBlobBuilder*); - GrStyle fStyle; - SkPaint fFont; - SkScalar fTextRatio; - float fTextInverseRatio; - bool fUsingRawGlyphPaths; - GrUniqueKey fGlyphPathsKey; - int fTotalGlyphCount; - SkAutoTUnref<InstanceData> fInstanceData; - int fFallbackGlyphCount; - SkAutoTUnref<const SkTextBlob> fFallbackTextBlob; - mutable SkGlyphCache* fDetachedGlyphCache; - mutable uint32_t fLastDrawnGlyphsID; + GrStyle fStyle; + SkPaint fFont; + SkScalar fTextRatio; + float fTextInverseRatio; + bool fUsingRawGlyphPaths; + GrUniqueKey fGlyphPathsKey; + int fTotalGlyphCount; + SkAutoTUnref<InstanceData> fInstanceData; + int fFallbackGlyphCount; + sk_sp<SkTextBlob> fFallbackTextBlob; + mutable SkGlyphCache* fDetachedGlyphCache; + mutable uint32_t fLastDrawnGlyphsID; }; // Text blobs/caches. diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 8ea9eee5fc..117cb8af83 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -2076,8 +2076,7 @@ static int lsk_newTextBlob(lua_State* L) { box.setText(text, strlen(text), paint); SkScalar newBottom; - SkAutoTUnref<SkTextBlob> blob(box.snapshotTextBlob(&newBottom)); - push_ref<SkTextBlob>(L, blob); + push_ref<SkTextBlob>(L, box.snapshotTextBlob(&newBottom)); SkLua(L).pushScalar(newBottom); return 2; } diff --git a/src/utils/SkTextBox.cpp b/src/utils/SkTextBox.cpp index d237f4513c..bc2e2217d9 100644 --- a/src/utils/SkTextBox.cpp +++ b/src/utils/SkTextBox.cpp @@ -292,11 +292,11 @@ public: } }; -SkTextBlob* SkTextBox::snapshotTextBlob(SkScalar* computedBottom) const { +sk_sp<SkTextBlob> SkTextBox::snapshotTextBlob(SkScalar* computedBottom) const { TextBlobVisitor visitor; SkScalar newB = this->visit(visitor, fText, fLen, *fPaint); if (computedBottom) { *computedBottom = newB; } - return (SkTextBlob*)visitor.fBuilder.build(); + return visitor.fBuilder.make(); } diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp index cbc6b99f84..964a64ff29 100644 --- a/tests/TextBlobCacheTest.cpp +++ b/tests/TextBlobCacheTest.cpp @@ -27,19 +27,11 @@ #include "GrContext.h" #include "GrTest.h" -struct TextBlobWrapper { - // This class assumes it 'owns' the textblob it wraps, and thus does not need to take a ref - explicit TextBlobWrapper(const SkTextBlob* blob) : fBlob(blob) {} - TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get())) {} - - SkAutoTUnref<const SkTextBlob> fBlob; -}; - -static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>& blobs) { +static void draw(SkCanvas* canvas, int redraw, const SkTArray<sk_sp<SkTextBlob>>& blobs) { int yOffset = 0; for (int r = 0; r < redraw; r++) { for (int i = 0; i < blobs.count(); i++) { - const SkTextBlob* blob = blobs[i].fBlob.get(); + const auto& blob = blobs[i]; const SkRect& bounds = blob->bounds(); yOffset += SkScalarCeilToInt(bounds.height()); SkPaint paint; @@ -85,7 +77,7 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte } // generate textblobs - SkTArray<TextBlobWrapper> blobs; + SkTArray<sk_sp<SkTextBlob>> blobs; for (int i = 0; i < count; i++) { SkPaint paint; paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); @@ -124,7 +116,7 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte } } } - blobs.emplace_back(builder.build()); + blobs.emplace_back(builder.make()); } } diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp index 82bbb21a11..dafbe74e69 100644 --- a/tests/TextBlobTest.cpp +++ b/tests/TextBlobTest.cpp @@ -104,28 +104,28 @@ public: // Explicit bounds. { - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); } { SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); builder.allocRun(font, 16, 0, 0, &r1); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds() == r1); } { SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); builder.allocRunPosH(font, 16, 0, &r1); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds() == r1); } { SkRect r1 = SkRect::MakeXYWH(10, 10, 20, 20); builder.allocRunPos(font, 16, &r1); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds() == r1); } @@ -138,13 +138,13 @@ public: builder.allocRunPosH(font, 16, 0, &r2); builder.allocRunPos(font, 16, &r3); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds() == SkRect::MakeXYWH(0, 5, 65, 65)); } { // Verify empty blob bounds after building some non-empty blobs. - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); } @@ -168,7 +168,7 @@ public: p.textToGlyphs(txt, txtLen, buffer.glyphs); memset(buffer.pos, 0, sizeof(SkScalar) * glyphCount * 2); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); REPORTER_ASSERT(reporter, blob->bounds().isEmpty()); } } @@ -224,9 +224,9 @@ public: AddRun(font, 1, SkTextBlob::kDefault_Positioning, SkPoint::Make(0, 0), builder); AddRun(font, 1, SkTextBlob::kHorizontal_Positioning, SkPoint::Make(0, 0), builder); AddRun(font, 1, SkTextBlob::kFull_Positioning, SkPoint::Make(0, 0), builder); - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); - SkTextBlobRunIterator it(blob); + SkTextBlobRunIterator it(blob.get()); while (!it.done()) { SkPaint paint; it.applyFontToPaint(&paint); @@ -278,9 +278,9 @@ private: posCount += in[i].count * in[i].pos; } - SkAutoTUnref<const SkTextBlob> blob(builder.build()); + sk_sp<SkTextBlob> blob(builder.make()); - SkTextBlobRunIterator it(blob); + SkTextBlobRunIterator it(blob.get()); for (unsigned i = 0; i < outCount; ++i) { REPORTER_ASSERT(reporter, !it.done()); REPORTER_ASSERT(reporter, out[i].pos == it.positioning()); @@ -368,7 +368,7 @@ DEF_TEST(TextBlob_extended, reporter) { for (int i = 0; i < glyphCount; ++i) { run.clusters[i] = SkTMin(SkToU32(i), SkToU32(strlen(text2))); } - sk_sp<const SkTextBlob> blob(textBlobBuilder.build()); + sk_sp<SkTextBlob> blob(textBlobBuilder.make()); REPORTER_ASSERT(reporter, blob); for (SkTextBlobRunIterator it(blob.get()); !it.done(); it.next()) { diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp index 86125b891d..4c633ab8fc 100644 --- a/tools/debugger/SkDebugCanvas.cpp +++ b/tools/debugger/SkDebugCanvas.cpp @@ -9,8 +9,9 @@ #include "SkClipStack.h" #include "SkDebugCanvas.h" #include "SkDrawCommand.h" -#include "SkPaintFilterCanvas.h" #include "SkOverdrawMode.h" +#include "SkPaintFilterCanvas.h" +#include "SkTextBlob.h" #if SK_SUPPORT_GPU #include "GrAuditTrail.h" @@ -677,7 +678,8 @@ void SkDebugCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const void SkDebugCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) { - this->addDrawCommand(new SkDrawTextBlobCommand(blob, x, y, paint)); + this->addDrawCommand(new SkDrawTextBlobCommand(sk_ref_sp(const_cast<SkTextBlob*>(blob)), + x, y, paint)); } void SkDebugCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 6ca3fe074e..0f8101306b 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -2796,10 +2796,10 @@ static const char* gPositioningLabels[] = { "kFull_Positioning", }; -SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, +SkDrawTextBlobCommand::SkDrawTextBlobCommand(sk_sp<SkTextBlob> blob, SkScalar x, SkScalar y, const SkPaint& paint) : INHERITED(kDrawTextBlob_OpType) - , fBlob(SkRef(blob)) + , fBlob(std::move(blob)) , fXPos(x) , fYPos(y) , fPaint(paint) { @@ -2813,7 +2813,7 @@ SkDrawTextBlobCommand::SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, unsigned runs = 0; SkPaint runPaint(paint); - SkTextBlobRunIterator iter(blob); + SkTextBlobRunIterator iter(blob.get()); while (!iter.done()) { SkAutoTDelete<SkString> tmpStr(new SkString); tmpStr->printf("==== Run [%d] ====", runs++); @@ -2846,7 +2846,7 @@ bool SkDrawTextBlobCommand::render(SkCanvas* canvas) const { SkRect bounds = fBlob->bounds().makeOffset(fXPos, fYPos); xlate_and_scale_to_bounds(canvas, bounds); - canvas->drawTextBlob(fBlob.get(), fXPos, fYPos, fPaint); + canvas->drawTextBlob(fBlob, fXPos, fYPos, fPaint); canvas->restore(); @@ -2949,7 +2949,7 @@ SkDrawTextBlobCommand* SkDrawTextBlobCommand::fromJSON(Json::Value& command, SkScalar y = command[SKDEBUGCANVAS_ATTRIBUTE_Y].asFloat(); SkPaint paint; extract_json_paint(command[SKDEBUGCANVAS_ATTRIBUTE_PAINT], urlDataManager, &paint); - return new SkDrawTextBlobCommand(builder.build(), x, y, paint); + return new SkDrawTextBlobCommand(builder.make(), x, y, paint); } SkDrawPatchCommand::SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4], diff --git a/tools/debugger/SkDrawCommand.h b/tools/debugger/SkDrawCommand.h index 2e5f9c659a..07dd477f6a 100644 --- a/tools/debugger/SkDrawCommand.h +++ b/tools/debugger/SkDrawCommand.h @@ -625,7 +625,7 @@ private: class SkDrawTextBlobCommand : public SkDrawCommand { public: - SkDrawTextBlobCommand(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint); + SkDrawTextBlobCommand(sk_sp<SkTextBlob> blob, SkScalar x, SkScalar y, const SkPaint& paint); void execute(SkCanvas* canvas) const override; bool render(SkCanvas* canvas) const override; @@ -633,10 +633,10 @@ public: static SkDrawTextBlobCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); private: - SkAutoTUnref<const SkTextBlob> fBlob; - SkScalar fXPos; - SkScalar fYPos; - SkPaint fPaint; + sk_sp<SkTextBlob> fBlob; + SkScalar fXPos; + SkScalar fYPos; + SkPaint fPaint; typedef SkDrawCommand INHERITED; }; |