diff options
-rw-r--r-- | include/core/SkCanvas.h | 3 | ||||
-rw-r--r-- | include/core/SkTextBlob.h | 12 | ||||
-rw-r--r-- | src/core/SkTextBlob.cpp | 10 |
3 files changed, 18 insertions, 7 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 26e3c8e3c5..b2fc5d326d 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -1071,6 +1071,9 @@ public: @param paint The paint used for the text (e.g. color, size, style) */ void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint); + void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) { + this->drawTextBlob(blob.get(), x, y, paint); + } /** Draw the picture into this canvas. This method effective brackets the playback of the picture's draw calls with save/restore, so the state diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h index 3c5d87359a..1addb6f914 100644 --- a/include/core/SkTextBlob.h +++ b/include/core/SkTextBlob.h @@ -43,7 +43,11 @@ public: * @return A new SkTextBlob representing the serialized data, or NULL if the buffer is * invalid. */ - static const SkTextBlob* CreateFromBuffer(SkReadBuffer&); + static sk_sp<SkTextBlob> MakeFromBuffer(SkReadBuffer&); + + static const SkTextBlob* CreateFromBuffer(SkReadBuffer& buffer) { + return MakeFromBuffer(buffer).release(); + } enum GlyphPositioning { kDefault_Positioning = 0, // Default glyph advances -- zero scalars per glyph. @@ -99,7 +103,11 @@ public: * Returns an immutable SkTextBlob for the current runs/glyphs. The builder is reset and * can be reused. */ - const SkTextBlob* build(); + sk_sp<SkTextBlob> make(); + + const SkTextBlob* build() { + return this->make().release(); + } /** * Glyph and position buffers associated with a run. diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index 1cbb2b6d6d..3c7345f9a0 100644 --- a/src/core/SkTextBlob.cpp +++ b/src/core/SkTextBlob.cpp @@ -246,7 +246,7 @@ void SkTextBlob::flatten(SkWriteBuffer& buffer) const { SkASSERT(0 == runCount); } -const SkTextBlob* SkTextBlob::CreateFromBuffer(SkReadBuffer& reader) { +sk_sp<SkTextBlob> SkTextBlob::MakeFromBuffer(SkReadBuffer& reader) { int runCount = reader.read32(); if (runCount < 0) { return nullptr; @@ -290,7 +290,7 @@ const SkTextBlob* SkTextBlob::CreateFromBuffer(SkReadBuffer& reader) { } } - return blobBuilder.build(); + return blobBuilder.make(); } unsigned SkTextBlob::ScalarsPerGlyph(GlyphPositioning pos) { @@ -613,7 +613,7 @@ const SkTextBlobBuilder::RunBuffer& SkTextBlobBuilder::allocRunPos(const SkPaint return fCurrentRunBuffer; } -const SkTextBlob* SkTextBlobBuilder::build() { +sk_sp<SkTextBlob> SkTextBlobBuilder::make() { SkASSERT((fRunCount > 0) == (nullptr != fStorage.get())); this->updateDeferredBounds(); @@ -624,7 +624,7 @@ const SkTextBlob* SkTextBlobBuilder::build() { fStorage.realloc(fStorageUsed); } - const SkTextBlob* blob = new (fStorage.release()) SkTextBlob(fRunCount, fBounds); + SkTextBlob* blob = new (fStorage.release()) SkTextBlob(fRunCount, fBounds); SkDEBUGCODE(const_cast<SkTextBlob*>(blob)->fStorageSize = fStorageSize;) SkDEBUGCODE( @@ -644,5 +644,5 @@ const SkTextBlob* SkTextBlobBuilder::build() { fLastRun = 0; fBounds.setEmpty(); - return blob; + return sk_sp<SkTextBlob>(blob); } |