From 2867e7648069272ad1827ebafe49bd0d22a619b3 Mon Sep 17 00:00:00 2001 From: reed Date: Mon, 29 Aug 2016 06:57:28 -0700 Subject: [PATCH] change readTypeface to return sk_sp BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2290653002 TBR=mtklein Review-Url: https://codereview.chromium.org/2290653002 --- src/core/SkPaint.cpp | 2 +- src/core/SkReadBuffer.cpp | 5 ++--- src/core/SkReadBuffer.h | 7 +------ src/core/SkValidatingReadBuffer.cpp | 6 ------ src/core/SkValidatingReadBuffer.h | 3 --- 5 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 44b2928..58d6a0f 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1958,7 +1958,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { this->setTextEncoding(static_cast((tmp >> 0) & 0xFF)); if (flatFlags & kHasTypeface_FlatFlag) { - this->setTypeface(sk_ref_sp(buffer.readTypeface())); + this->setTypeface(buffer.readTypeface()); } else { this->setTypeface(nullptr); } diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp index 5356d4a..43eaf20 100644 --- a/src/core/SkReadBuffer.cpp +++ b/src/core/SkReadBuffer.cpp @@ -297,14 +297,13 @@ sk_sp SkReadBuffer::readImage() { return image ? image : MakeEmptyImage(width, height); } -SkTypeface* SkReadBuffer::readTypeface() { - +sk_sp SkReadBuffer::readTypeface() { uint32_t index = fReader.readU32(); if (0 == index || index > (unsigned)fTFCount) { return nullptr; } else { SkASSERT(fTFArray); - return fTFArray[index - 1]; + return sk_ref_sp(fTFArray[index - 1]); } } diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index a8bed7b..7c4ecc6 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -166,14 +166,9 @@ public: // helpers to get info about arrays and binary data virtual uint32_t getArrayCount(); - /** - * Returns false if the image could not be completely read. In that case, it will be set - * to have width/height, but no pixels. - */ sk_sp readBitmapAsImage(); sk_sp readImage(); - - virtual SkTypeface* readTypeface(); + virtual sk_sp readTypeface(); void setTypefaceArray(SkTypeface* array[], int count) { fTFArray = array; diff --git a/src/core/SkValidatingReadBuffer.cpp b/src/core/SkValidatingReadBuffer.cpp index 2dd7070..326d0cf 100644 --- a/src/core/SkValidatingReadBuffer.cpp +++ b/src/core/SkValidatingReadBuffer.cpp @@ -210,12 +210,6 @@ uint32_t SkValidatingReadBuffer::getArrayCount() { return fError ? 0 : *(uint32_t*)fReader.peek(); } -SkTypeface* SkValidatingReadBuffer::readTypeface() { - SkASSERT(false); - // TODO: Implement this (securely) when needed - return nullptr; -} - bool SkValidatingReadBuffer::validateAvailable(size_t size) { return this->validate((size <= SK_MaxU32) && fReader.isAvailable(static_cast(size))); } diff --git a/src/core/SkValidatingReadBuffer.h b/src/core/SkValidatingReadBuffer.h index d8575bd..bad5f2f 100644 --- a/src/core/SkValidatingReadBuffer.h +++ b/src/core/SkValidatingReadBuffer.h @@ -62,9 +62,6 @@ public: // helpers to get info about arrays and binary data uint32_t getArrayCount() override; - // TODO: Implement this (securely) when needed - SkTypeface* readTypeface() override; - bool validate(bool isValid) override; bool isValid() const override; -- 2.7.4